Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {MatProgressBarModule} from '@angular/material/progress-bar';
import { KeycloakAngularModule, KeycloakService } from 'keycloak-angular';
import { environment } from 'src/environments/environment';
import { HttpRequestInterceptor } from './shared/http-request-interceptor/http-request-interceptor';
import { AuthenticationService } from './shared/authentication/authentication.service';

function initializeKeycloak(keycloak: KeycloakService): () => Promise<boolean> {
return () =>
Expand Down Expand Up @@ -56,14 +57,15 @@ function initializeKeycloak(keycloak: KeycloakService): () => Promise<boolean> {
SpaceModule,
GraphViewModule,
RouterModule.forRoot([
{ path: 'welcome', component: WelcomePageComponent },
{ path: 'login', component: LoginPageComponent },
{ path: 'afterlogin', component: AfterLoginComponent },
{ path: 'myspaces', component: SubscribedSpacesOverviewComponent, canActivate: [AuthGuardService] },
{ path: 'spaces/create', component: CreateSpaceComponent, canActivate: [AuthGuardService] },
{ path: 'spaces/:spaceId', component: GraphViewPageComponent, canActivate: [AuthGuardService] },
{ path: '**', redirectTo: 'welcome' }
], { relativeLinkResolution: 'legacy' }),
{ path: 'welcome', component: WelcomePageComponent },
{ path: 'login', component: LoginPageComponent },
{ path: 'afterlogin', component: AfterLoginComponent },
{ path: 'myspaces', component: SubscribedSpacesOverviewComponent, canActivate: [AuthGuardService] },
{ path: 'spaces/create', component: CreateSpaceComponent, canActivate: [AuthGuardService] },
{ path: 'spaces/:spaceId', component: GraphViewPageComponent, canActivate: [AuthGuardService] },
{ path: '**', redirectTo: 'welcome' }
],
{ relativeLinkResolution: 'legacy' }),
HttpClientModule,
KeycloakAngularModule,
MatSidenavModule,
Expand All @@ -79,7 +81,8 @@ function initializeKeycloak(keycloak: KeycloakService): () => Promise<boolean> {
{ provide: HTTP_INTERCEPTORS,
useClass: HttpRequestInterceptor,
multi: true
}
},
AuthenticationService
],
bootstrap: [AppComponent]
})
Expand Down
36 changes: 36 additions & 0 deletions src/app/graph-view/graph-view-page/graph-view-page.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
top: 80px;
right: 10px;
direction: rtl;
max-width: 290px;
}

.memberList ul {
Expand Down Expand Up @@ -40,4 +41,39 @@ mat-icon {
.graph-view {
width: 100%;
height: 100%;
}

.mat-icon.share-icon {
height:32px !important;
width:32px !important;
font-size:32px !important;
}

.recommendation-card {
position: fixed;
max-width: 300px;
margin: 24px;
}

.example-header-image {
background-image: url('../../../assets/default-avatar.png');
background-size: cover;
}

.recommendation-link {
padding: 8px;
display: flex;
cursor: pointer;
}

.recommendation-link:hover {
background-color: #F8F8FF;
}

.img-avatar {
border-radius: 50%;
height: 32px;
width: 32px;
display: block;
object-fit: cover;
}
104 changes: 39 additions & 65 deletions src/app/graph-view/graph-view-page/graph-view-page.component.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
<mat-progress-bar
<mat-progress-bar
color="accent"
style="width: 100%; position: fixed;"
mode="indeterminate"
*ngIf="this.loading">
</mat-progress-bar>
<div class="graph-view">
<mat-card fxHide.xs class="recommendation-card">
<mat-card-header>
<mat-card-title>Recommended For You</mat-card-title>
</mat-card-header>
<mat-card-content>
<mat-spinner *ngIf="!this.recommendationsLoaded" style="margin: auto;"></mat-spinner>
<ng-container *ngIf="this.recommendationsLoaded">
<a class="recommendation-link "*ngFor="let r of recommenderQuestions" (click)="recClicked(r)">
<span style="padding-right: 4px; position: relative;">
<img class="img-avatar" src="../../../assets/default-avatar.png">
</span>
<span fxLayout="column">
<span fxLayout>
<span>{{r.authorName}}</span>
<span> · </span>
<span style="color: #7C7C7C;">{{GetPastTime(r)}}</span>
</span>
<span style="color: #7C7C7C;">{{r.question.text}}</span>
</span>
</a>
</ng-container>
</mat-card-content>
</mat-card>
<div class="graph-view" fxLayout="row" fxLayoutAlign="center">
<div *ngIf="subscriptionInProgress">
<p>Subscribing to space&hellip;</p>
<mat-spinner></mat-spinner>
Expand All @@ -28,7 +51,7 @@
</mat-radio-group>
</mat-card>
<div fxHide.xs class="memberList" *ngIf="!subscriptionInProgress">
<mat-accordion displayMode="flat" multi="true">
<mat-accordion displayMode="flat" multi="true" style="margin-bottom: 20px;">
<mat-expansion-panel expanded="true" hideToggle>
<mat-expansion-panel-header expandedHeight="30px" collapsedHeight="30px">
<span class="bw">Participants</span>
Expand All @@ -43,69 +66,20 @@
<span class="bw">Help</span>
</mat-expansion-panel-header>
<ul>
<li><span class="bw"><mat-icon style="font-weight: bold">chat_bubble_outline</mat-icon> selected / <mat-icon>chat_bubble_outline</mat-icon> deselected</span>
</li>
<li><span class="bw"><mat-icon style="color: green">chat_bubble_outline</mat-icon> rated positively / <mat-icon
style="color: rgb(255, 0, 0)">chat_bubble_outline</mat-icon> rated negatively</span></li>
<li><span class="bw"><span style="font-weight: bold">>>></span> follow-up question</span></li>
<li><span class="bw"><span style="font-weight: bold">――</span> related question</span></li>
<li><span class="bw">―――――――――――――――――――――</span></li>
<li><span class="bw">More questions? <a
href="mailto:[email protected]">[email protected]</a></span></li>
<li><span class="bw"><mat-icon style="font-weight: bold">chat_bubble_outline</mat-icon>selected</span></li>
<li><span class="bw"><mat-icon>chat_bubble_outline</mat-icon>deselected</span></li>
<li><span class="bw"><mat-icon style="color: green">chat_bubble_outline</mat-icon>rated positively</span></li>
<li><span class="bw"><mat-icon style="color: rgb(255, 0, 0)">chat_bubble_outline</mat-icon>rated negatively</span></li>
<li><span class="bw"><span style="font-weight: bold">>>></span>follow-up question</span></li>
<li><span class="bw"><span style="font-weight: bold">――</span>related question</span></li>
<li><span class="bw">―――――――――――――――――――――</span></li>
<li><span class="bw">More questions?</span></li>
<li><span class="bw"><a href="mailto:[email protected]">[email protected]</a></span></li>
</ul>
</mat-expansion-panel>
</mat-accordion>
<button mat-button (click)="copyInviteUrl()" color="primary" style="margin: 8px 24px; padding: 0 !important;">
<b>SHARE</b>
<mat-icon class="share-icon" inline="true">share</mat-icon>
</button>
</div>
<!--<div class="container" fxLayout="row">-->
<!-- <div class="spaceContent" fxLayout="column" fxLayoutAlign="space-around center"> -->
<!-- <div *ngIf="subscriptionInProgress">
<p>Subscribing to space&hellip;</p>
<mat-spinner></mat-spinner>
</div>
<dnor-graph-view *ngIf="!subscriptionInProgress"
[spaceId]="spaceId"
[width]="width"
[height]="height"
[selectedQuestions]="selectedQuestions"
[interactionMode]="interactionMode"></dnor-graph-view>
<mat-card style="display: inline-block">
<mat-radio-group *ngIf="!subscriptionInProgress"
fxLayout="row" fxLayoutGap="20px" fxLayoutWrap [(ngModel)]="interactionMode">
<mat-radio-button color="primary" *ngFor="let m of getInteractionModes()" [value]="m">
{{getInteractionModeLabel(m)}}
</mat-radio-button>
</mat-radio-group>
</mat-card> -->
<!-- </div> -->
<!-- <div class="spaceInfo"> -->
<!-- <div class="memberList" *ngIf="!subscriptionInProgress">
<mat-accordion displayMode="flat" multi="true">
<mat-expansion-panel expanded="true">
<mat-expansion-panel-header expandedHeight="30px" collapsedHeight="30px">
<span class="bw">Participants</span>
</mat-expansion-panel-header>
<ul>
<li *ngFor="let m of this.spaceMembers"><span class="bw">{{m}}</span></li>
</ul>
</mat-expansion-panel>

<mat-expansion-panel>
<mat-expansion-panel-header expandedHeight="30px" collapsedHeight="30px">
<span class="bw">Help</span>
</mat-expansion-panel-header>
<ul>
<li><span class="bw"><mat-icon style="font-weight: bold">chat_bubble_outline</mat-icon> selected / <mat-icon>chat_bubble_outline</mat-icon> deselected</span>
</li>
<li><span class="bw"><mat-icon style="color: green">chat_bubble_outline</mat-icon> rated positively / <mat-icon
style="color: rgb(255, 0, 0)">chat_bubble_outline</mat-icon> rated negatively</span></li>
<li><span class="bw"><span style="font-weight: bold">>>></span> follow-up question</span></li>
<li><span class="bw"><span style="font-weight: bold">――</span> related question</span></li>
<li><span class="bw">―――――――――――――――――――――</span></li>
<li><span class="bw">More questions? <a
href="mailto:[email protected]">[email protected]</a></span></li>
</ul>
</mat-expansion-panel>
</mat-accordion>
</div> -->
<!-- </div> -->
<!-- </div> -->
123 changes: 112 additions & 11 deletions src/app/graph-view/graph-view-page/graph-view-page.component.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,85 @@
import {ChangeDetectorRef, Component, OnDestroy, OnInit} from '@angular/core';
import {ChangeDetectorRef, Component, OnChanges, OnDestroy, OnInit, SimpleChanges} from '@angular/core';
import {GraphInteractionMode} from '../graph-view/graph-data-model/graph-interaction-mode.enum';
import {ActivatedRoute, Router} from '@angular/router';
import {Subscription} from 'rxjs';
import {ActivatedRoute, NavigationExtras, Router} from '@angular/router';
import {BehaviorSubject, Subscription} from 'rxjs';
import {MyspacesService} from '../../shared/myspaces/myspaces.service';
import { GraphViewService } from '../graph-view/graph-view.service';
import { MatSnackBar } from '@angular/material/snack-bar';
import { Clipboard } from '@angular/cdk/clipboard';
import { SpaceService } from 'src/app/shared/space/space.service';
import { Space } from 'src/app/shared/rest-data-model/space';
import { RecommendationService } from 'src/app/shared/recommendation/recommendation.service';
import { RecommenderQuestion } from 'src/app/shared/rest-data-model/recommender-question';
import { Question } from 'src/app/shared/rest-data-model/question';
import { AgentService } from 'src/app/shared/agent/agent.service';

@Component({
selector: 'dnor-graph-view-page',
templateUrl: './graph-view-page.component.html',
styleUrls: ['./graph-view-page.component.css']
})
export class GraphViewPageComponent implements OnInit, OnDestroy {
export class GraphViewPageComponent implements OnInit, OnDestroy, OnChanges {
public subscriptionInProgress = false;
public interactionMode = GraphInteractionMode.SelectAndNavigate;
public height = 800;
public width = 1100;
public spaceId = '1';
public space: Space;
public selectedQuestions;
public spaceMembers = [];
public loading = false;
public recommenderQuestions: RecommenderQuestion[];
public selectedRecommenderQuestion: [];
public recommendationsLoaded = false;

private subscription: Subscription = new Subscription();

constructor(private activatedRoute: ActivatedRoute, private router: Router, private ref: ChangeDetectorRef,
private myspacesService: MyspacesService, private graphViewService: GraphViewService) {}
constructor(
private activatedRoute: ActivatedRoute,
private router: Router,
private ref: ChangeDetectorRef,
private myspacesService: MyspacesService,
private graphViewService: GraphViewService,
private snackBar: MatSnackBar,
private clipboard: Clipboard,
private spaceService: SpaceService,
private recommendationService: RecommendationService,
private agentService: AgentService) {}

ngOnChanges(changes: SimpleChanges): void {}

copyInviteUrl() {
let url = window.location.href;
url = url.substring(0, url.indexOf('/spaces')) + `/spaces/${this.space.spaceId}?pw=${this.space.spaceSecret}`;
this.clipboard.copy(url);
this.snackBar.open('Copied invitation link to clipboard. Paste to share with friends!', 'Ok');
}

ngOnInit() {
this.subscription.add(this.activatedRoute.params.subscribe((params) => {
this.spaceId = params['spaceId'];
this.myspacesService.getSubscribersObservable(this.spaceId).subscribe(subs => {
this.spaceMembers = subs.map(sub => sub.name);
});
this.myspacesService.getMySpaces().then(res => {
if (res.find(s => s.space.spaceId === this.spaceId)) {
this.spaceService.getSpace(this.spaceId).then((space: Space) => {
this.space = space;
});
}
});
}));
this.subscription.add(this.activatedRoute.queryParams.subscribe((queryParams) => {
const pw = queryParams['pw'];
if (pw !== undefined) {
this.subscriptionInProgress = true;
this.myspacesService.subscribeToSpace(this.spaceId, pw).then(() => {
const qp = queryParams['sq'] !== undefined ? {sq: queryParams['sq']} : {};
this.router.navigate([], {queryParams: qp, replaceUrl: true}).then(() =>
this.router.navigate([], {queryParams: qp, replaceUrl: true}).then(() => {
this.ngOnInit(); // reload component
this.subscriptionInProgress = false
);
});
});

}
const q = queryParams['sq'];
if (q === undefined) {
Expand All @@ -51,12 +88,76 @@ export class GraphViewPageComponent implements OnInit, OnDestroy {
this.selectedQuestions = JSON.parse(q);
}
}));
this.width = window.innerWidth * 0.99;
this.height = window.innerHeight * 0.92;

this.subscription.add(this.graphViewService.loading.subscribe((loading) => {
this.loading = loading;
this.ref.detectChanges();
}));
this.width = window.innerWidth * 0.99;
this.height = window.innerHeight * 0.91;

this.loadRecommendations();
}

loadRecommendations(): void {
this.recommendationsLoaded = false;
this.agentService.getAgent().then((agent) => {
this.recommendationService.getRecommendedQuestionsForSpace(agent.agentid, this.spaceId)
.then((res: RecommenderQuestion[]) => {
this.recommenderQuestions = res;
}).catch(() => {
console.error("error while getting recommendations...");
}).finally(() => {
this.recommendationsLoaded = true;
})
});
}

recClicked(rq: RecommenderQuestion): void {
//let questionIds = r.questionNeighbourIds;
let questionIds = [];
questionIds.push(rq.question.questionId);
let navigationExtras: NavigationExtras = {
queryParams: {
sq: JSON.stringify(questionIds)
}
}
this.graphViewService.recommenderSubject.next(questionIds);
this.router.navigate(['/spaces', rq.question.spaceId], navigationExtras);
}

GetPastTime(rq: RecommenderQuestion): string {
// TODO: This is way to complicated!
let date = new Date(rq.question.timestampCreated);
let dateNow = new Date();

if (date.getFullYear() === dateNow.getFullYear()) {
if (date.getMonth() === dateNow.getMonth()) {
if (date.getDay() === dateNow.getDay()) {
if (date.getHours() === dateNow.getHours()) {
if (date.getMinutes() === dateNow.getMinutes()) {
// show seconds
return (dateNow.getSeconds() - date.getSeconds()) + ' second(s) ago';
} else {
// show minutes
return (dateNow.getMinutes() - date.getMinutes()) + ' minute(s) ago';
}
} else {
// show hours
return (dateNow.getHours() - date.getHours()) + ' hour(s) ago';
}
} else {
// show days
return (dateNow.getDay() - date.getDay()) + ' day(s) ago';
}
} else {
// show month
return (dateNow.getMonth() - date.getMonth()) + ' month(s) ago';
}
} else {
// show years
return (dateNow.getFullYear() - date.getFullYear()) + 'year(s) ago';
}
}

ngOnDestroy() {
Expand Down
Loading