diff --git a/src/app/components/shared/_dialogs/spacy-dialog/spacy-dialog.component.ts b/src/app/components/shared/_dialogs/spacy-dialog/spacy-dialog.component.ts index cfcad0b481eaf935b4b2aa7ceb4fa586119e6c3c..de9d06bf9d05db565bec65df1e546974972f28e6 100644 --- a/src/app/components/shared/_dialogs/spacy-dialog/spacy-dialog.component.ts +++ b/src/app/components/shared/_dialogs/spacy-dialog/spacy-dialog.component.ts @@ -46,7 +46,7 @@ export class SpacyDialogComponent implements OnInit, AfterContentInit { /** * Returns a lambda which closes the dialog on call. */ - buildCloseDialogActionCallback(): () => void { + buildCloseDialogActionCallback(): () => void { return () => this.dialogRef.close(); } @@ -61,34 +61,31 @@ export class SpacyDialogComponent implements OnInit, AfterContentInit { evalInput(model: Model) { const words: Keyword[] = []; // N at first pos = all Nouns(NN de/en) including singular(NN, NNP en), plural (NNPS, NNS en), proper Noun(NNE, NE de) - this.spacyService.analyse(this.commentBodyChecked, model) - .subscribe(res => { - this.spacyKeywords.length = 0; - for (const word of res.words) { - if (word.tag.charAt(0) === 'N') { - this.spacyKeywords.push(word.text); - words.push({ - word: word.text, - completed: false, - editing: false, - selected: false - }); - } - } - this.keywords = words; - }, () => { - this.spacyKeywords = []; - this.keywords = []; - }); + this.spacyService.getKeywords(this.commentBodyChecked, model).subscribe(res => { + this.spacyKeywords = res; + const wordsArr = []; + for (const tag of res) { + wordsArr.push({ + word: tag, + completed: false, + editing: false, + selected: false + }); + } + this.keywords = wordsArr; + }, () => { + this.spacyKeywords = []; + this.keywords = []; + }); } - onEdit(keyword){ + onEdit(keyword) { keyword.editing = true; keyword.completed = false; keyword.selected = false; } - onEndEditing(keyword){ + onEndEditing(keyword) { keyword.editing = false; keyword.completed = true; keyword.selected = true; diff --git a/src/app/components/shared/comment-list/comment-list.component.ts b/src/app/components/shared/comment-list/comment-list.component.ts index df09d1a86e928654615bb716e6e5762770180744..386936244011bfe1a199be8b6900397ec4b3e783 100644 --- a/src/app/components/shared/comment-list/comment-list.component.ts +++ b/src/app/components/shared/comment-list/comment-list.component.ts @@ -32,6 +32,7 @@ import { ModeratorService } from '../../../services/http/moderator.service'; import { TopicCloudFilterComponent } from '../_dialogs/topic-cloud-filter/topic-cloud-filter.component'; import { CommentFilterOptions } from '../../../utils/filter-options'; import { isObjectBindingPattern } from 'typescript'; +import { CreateCommentWrapper } from '../../../utils/CreateCommentWrapper'; export enum Period { FROMNOW = 'from-now', @@ -101,6 +102,7 @@ export class CommentListComponent implements OnInit, OnDestroy { fromNow: number; moderatorIds: string[]; commentsEnabled: boolean; + private _createCommentWrapper: CreateCommentWrapper = null; constructor( private commentService: CommentService, @@ -127,7 +129,7 @@ export class CommentListComponent implements OnInit, OnDestroy { initNavigation() { const navigation = {}; const nav = (b, c) => navigation[b] = c; - nav('createQuestion', () => this.openCreateDialog()); + nav('createQuestion', () => this._createCommentWrapper.openCreateDialog(this.user)); nav('moderator', () => { const dialogRef = this.dialog.open(ModeratorsComponent, { width: '400px', @@ -221,6 +223,8 @@ export class CommentListComponent implements OnInit, OnDestroy { this.moderationEnabled = this.room.moderated; this.directSend = this.room.directSend; this.commentsEnabled = (this.userRole > 0) || !this.room.closed; + this._createCommentWrapper = new CreateCommentWrapper(this.translateService, + this.notificationService, this.commentService, this.dialog, this.room); localStorage.setItem('moderationEnabled', JSON.stringify(this.moderationEnabled)); if (!this.authenticationService.hasAccess(this.shortId, UserRole.PARTICIPANT)) { this.roomService.addToHistory(this.room.id); @@ -253,8 +257,8 @@ export class CommentListComponent implements OnInit, OnDestroy { this.getCurrentFilter().writeFilter(); } - private getCurrentFilter() : CommentFilterOptions { - let filter = new CommentFilterOptions(); + private getCurrentFilter(): CommentFilterOptions { + const filter = new CommentFilterOptions(); filter.filterSelected = this.currentFilter; filter.paused = this.freeze; filter.periodSet = this.period; @@ -395,7 +399,7 @@ export class CommentListComponent implements OnInit, OnDestroy { case this.ack: const isNowAck = <boolean>value; if (!isNowAck) { - this.comments = this.comments.filter(function (el) { + this.comments = this.comments.filter((el) => { return el.id !== payload.id; }); this.setTimePeriod(); @@ -422,7 +426,7 @@ export class CommentListComponent implements OnInit, OnDestroy { break; case 'CommentDeleted': for (let i = 0; i < this.comments.length; i++) { - this.comments = this.comments.filter(function (el) { + this.comments = this.comments.filter((el) => { return el.id !== payload.id; }); } @@ -436,55 +440,6 @@ export class CommentListComponent implements OnInit, OnDestroy { closeDialog() { this.dialog.closeAll(); } - openCreateDialog(): void { - const dialogRef = this.dialog.open(CreateCommentComponent, { - width: '900px', - maxWidth: 'calc( 100% - 50px )', - maxHeight: 'calc( 100vh - 50px )', - autoFocus: false, - }); - dialogRef.componentInstance.user = this.user; - dialogRef.componentInstance.roomId = this.roomId; - let tags; - tags = []; - if (this.room.tags) { - tags = this.room.tags; - } - dialogRef.componentInstance.tags = tags; - dialogRef.afterClosed() - .subscribe(result => { - if (result) { - this.send(result); - } else { - return; - } - }); - } - - - send(comment: Comment): void { - let message; - if (this.directSend) { - this.translateService.get('comment-list.comment-sent').subscribe(msg => { - message = msg; - }); - comment.ack = true; - } else { - if (this.userRole === 1 || this.userRole === 2 || this.userRole === 3) { - this.translateService.get('comment-list.comment-sent').subscribe(msg => { - message = msg; - }); - comment.ack = true; - } - if (this.userRole === 0) { - this.translateService.get('comment-list.comment-sent-to-moderator').subscribe(msg => { - message = msg; - }); - } - } - this.commentService.addComment(comment).subscribe(); - this.notificationService.show(message); - } filterComments(type: string, compare?: any): void { this.currentFilter = type; @@ -538,13 +493,12 @@ export class CommentListComponent implements OnInit, OnDestroy { } else if (type === this.votedesc) { return (b.score > a.score) ? 1 : (a.score > b.score) ? -1 : 0; } else if (type === this.time) { - const dateA = new Date(a.timestamp), dateB = new Date(b.timestamp); + const dateA = new Date(a.timestamp); + const dateB = new Date(b.timestamp); return (+dateB > +dateA) ? 1 : (+dateA > +dateB) ? -1 : 0; } }); - return sortedArray.sort((a, b) => { - return this.isCreatedByModeratorOrCreator(a) ? -1 : this.isCreatedByModeratorOrCreator(b) ? 1 : 0; - }); + return sortedArray.sort((a, b) => this.isCreatedByModeratorOrCreator(a) ? -1 : this.isCreatedByModeratorOrCreator(b) ? 1 : 0); } isCreatedByModeratorOrCreator(comment: Comment): boolean { @@ -575,7 +529,7 @@ export class CommentListComponent implements OnInit, OnDestroy { this.notificationService.show(msg); }); - let filter = CommentFilterOptions.generateFilterUntil(this.currentFilter, this.period, new Date().getTime()); + const filter = CommentFilterOptions.generateFilterUntil(this.currentFilter, this.period, new Date().getTime()); filter.writeFilter(); } @@ -591,8 +545,8 @@ export class CommentListComponent implements OnInit, OnDestroy { this.translateService.get('comment-list.comment-stream-started').subscribe(msg => { this.notificationService.show(msg); }); - - let filter = this.getCurrentFilter(); + + const filter = this.getCurrentFilter(); filter.writeFilter(); } @@ -669,7 +623,7 @@ export class CommentListComponent implements OnInit, OnDestroy { } this.getCurrentFilter().writeFilter(); - + this.filterComments(this.currentFilter); this.titleService.attachTitle('(' + this.commentsFilteredByTime.length + ')'); } diff --git a/src/app/components/shared/tag-cloud/demoData.ts b/src/app/components/shared/tag-cloud/demoData.ts deleted file mode 100644 index 9992f77908eaadf4767829ea50274ecafef2a0c5..0000000000000000000000000000000000000000 --- a/src/app/components/shared/tag-cloud/demoData.ts +++ /dev/null @@ -1,57 +0,0 @@ -export { demoMap }; -const demoMap = new Map<string, number>(); - demoMap.set("Topic 1",1); - demoMap.set("Topic 2 of 1",1); - demoMap.set("Topic 3 of 1",1); - demoMap.set("Topic 4 of 1",1); - demoMap.set("Topic 5 of 1",1); - demoMap.set("Topic 6 of 1",1); - demoMap.set("Topic 7 of 1",1); - demoMap.set("Topic 8 of 1",1); - demoMap.set("Topic 9 of 1",1); - demoMap.set("Topic 10 of 1",1); - demoMap.set("Topic 2",2); - demoMap.set("Topic 2 of 2",2); - demoMap.set("Topic 3 of 2",2); - demoMap.set("Topic 4 of 2",2); - demoMap.set("Topic 5 of 2",2); - demoMap.set("Topic 6 of 2",2); - demoMap.set("Topic 7 of 2",2); - demoMap.set("Topic 8 of 2",2); - demoMap.set("Topic 9 of 2",2); - demoMap.set("Topic 3",3); - demoMap.set("Topic 2 of 3",3); - demoMap.set("Topic 3 of 3",3); - demoMap.set("Topic 4 of 3",3); - demoMap.set("Topic 5 of 3",3); - demoMap.set("Topic 6 of 3",3); - demoMap.set("Topic 7 of 3",3); - demoMap.set("Topic 8 of 3",3); - demoMap.set("Topic 4",4); - demoMap.set("Topic 2 of 4",4); - demoMap.set("Topic 3 of 4",4); - demoMap.set("Topic 4 of 4",4); - demoMap.set("Topic 5 of 4",4); - demoMap.set("Topic 6 of 4",4); - demoMap.set("Topic 7 of 4",4); - demoMap.set("Topic 5",5); - demoMap.set("Topic 2 of 5",5); - demoMap.set("Topic 3 of 5",5); - demoMap.set("Topic 4 of 5",5); - demoMap.set("Topic 5 of 5",5); - demoMap.set("Topic 6 of 5",5); - demoMap.set("Topic 6",6); - demoMap.set("Topic 2 of 6",6); - demoMap.set("Topic 3 of 6",6); - demoMap.set("Topic 4 of 6",6); - demoMap.set("Topic 5 of 6",6); - demoMap.set("Topic 7",7); - demoMap.set("Topic 2 of 7",7); - demoMap.set("Topic 3 of 7",7); - demoMap.set("Topic 4 of 7",7); - demoMap.set("Topic 8",8); - demoMap.set("Topic 2 of 8",8); - demoMap.set("Topic 3 of 8",8); - demoMap.set("Topic 9",9); - demoMap.set("Topic 2 of 9",9); - demoMap.set("Topic 10",10); \ No newline at end of file diff --git a/src/app/components/shared/tag-cloud/tag-cloud.component.ts b/src/app/components/shared/tag-cloud/tag-cloud.component.ts index ff269ec685041f95edeee6a387d6ff23aedad489..67ab3ef60e8d379549712a82b9c2ed9f7061de2b 100644 --- a/src/app/components/shared/tag-cloud/tag-cloud.component.ts +++ b/src/app/components/shared/tag-cloud/tag-cloud.component.ts @@ -8,11 +8,8 @@ import { ZoomOnHoverOptions } from 'angular-tag-cloud-module'; import { CommentService } from '../../../services/http/comment.service'; -import { SpacyService } from '../../../services/http/spacy.service'; -import { Comment } from '../../../models/comment'; import { LanguageService } from '../../../services/util/language.service'; import { TranslateService } from '@ngx-translate/core'; -import { CreateCommentComponent } from '../_dialogs/create-comment/create-comment.component'; import { MatDialog } from '@angular/material/dialog'; import { User } from '../../../models/user'; import { Room } from '../../../models/room'; @@ -27,6 +24,7 @@ import { cloneParameters, CloudParameters, CloudTextStyle, CloudWeightSettings } import { TopicCloudAdministrationComponent } from '../_dialogs/topic-cloud-administration/topic-cloud-administration.component'; import { WsCommentServiceService } from '../../../services/websockets/ws-comment-service.service'; import { TagCloudDataManager } from './tag-cloud.data-manager'; +import { CreateCommentWrapper } from '../../../utils/CreateCommentWrapper'; class CustomPosition implements Position { left: number; @@ -161,9 +159,9 @@ export class TagCloudComponent implements OnInit, AfterViewInit, OnDestroy { themeSubscription = null; readonly dataManager: TagCloudDataManager; private _currentSettings: CloudParameters; + private _createCommentWrapper: CreateCommentWrapper = null; constructor(private commentService: CommentService, - private spacyService: SpacyService, private langService: LanguageService, private translateService: TranslateService, public dialog: MatDialog, @@ -200,7 +198,7 @@ export class TagCloudComponent implements OnInit, AfterViewInit, OnDestroy { this.updateGlobalStyles(); this.headerInterface = this.eventService.on<string>('navigate').subscribe(e => { if (e === 'createQuestion') { - this.openCreateDialog(); + this._createCommentWrapper.openCreateDialog(this.user); } else if (e === 'topicCloudConfig') { this.configurationOpen = !this.configurationOpen; this.dataManager.demoActive = !this.dataManager.demoActive; @@ -229,6 +227,8 @@ export class TagCloudComponent implements OnInit, AfterViewInit, OnDestroy { this.room = room; this.roomId = room.id; this.directSend = this.room.directSend; + this._createCommentWrapper = new CreateCommentWrapper(this.translateService, + this.notificationService, this.commentService, this.dialog, this.room); if (!this.authenticationService.hasAccess(this.shortId, UserRole.PARTICIPANT)) { this.roomService.addToHistory(this.room.id); this.authenticationService.setAccess(this.shortId, UserRole.PARTICIPANT); @@ -318,7 +318,7 @@ export class TagCloudComponent implements OnInit, AfterViewInit, OnDestroy { if (remaining > 0) { --countFiler[tagData.adjustedWeight]; } - let rotation = this._currentSettings.cloudWeightSettings[tagData.adjustedWeight].rotation; + let rotation = Math.random() < 0.5 ? this._currentSettings.cloudWeightSettings[tagData.adjustedWeight].rotation : 0; if (rotation === null || this._currentSettings.randomAngles) { rotation = Math.floor(Math.random() * 30 - 15); } @@ -369,53 +369,6 @@ export class TagCloudComponent implements OnInit, AfterViewInit, OnDestroy { } } - openCreateDialog(): void { - const dialogRef = this.dialog.open(CreateCommentComponent, { - width: '900px', - maxWidth: 'calc( 100% - 50px )', - maxHeight: 'calc( 100vh - 50px )', - autoFocus: false, - }); - dialogRef.componentInstance.user = this.user; - dialogRef.componentInstance.roomId = this.roomId; - let tags; - tags = []; - if (this.room.tags) { - tags = this.room.tags; - } - dialogRef.componentInstance.tags = tags; - dialogRef.afterClosed() - .subscribe(result => { - if (result) { - this.send(result); - } else { - return; - } - }); - } - - send(comment: Comment): void { - if (this.directSend) { - this.translateService.get('comment-list.comment-sent').subscribe(msg => { - this.notificationService.show(msg); - }); - comment.ack = true; - } else { - if (this.userRole === 1 || this.userRole === 2 || this.userRole === 3) { - this.translateService.get('comment-list.comment-sent').subscribe(msg => { - this.notificationService.show(msg); - }); - comment.ack = true; - } - if (this.userRole === 0) { - this.translateService.get('comment-list.comment-sent-to-moderator').subscribe(msg => { - this.notificationService.show(msg); - }); - } - } - this.commentService.addComment(comment).subscribe(); - } - private redraw(): void { if (this.child === undefined) { return; diff --git a/src/app/components/shared/tag-cloud/tag-cloud.data-manager.ts b/src/app/components/shared/tag-cloud/tag-cloud.data-manager.ts index 90ac54d32b5655c4623a8b92be4b8cdad29ad988..2c870737338f2f0263899efac73ffdd491369db3 100644 --- a/src/app/components/shared/tag-cloud/tag-cloud.data-manager.ts +++ b/src/app/components/shared/tag-cloud/tag-cloud.data-manager.ts @@ -95,6 +95,7 @@ export class TagCloudDataManager { } this._roomId = roomId; this.onUpdateData(); + //TODO Optimize for special events => better performance this._wsCommentSubscription = this._wsCommentService .getCommentStream(this._roomId).subscribe(e => this.onUpdateData()); } diff --git a/src/app/services/http/spacy.service.ts b/src/app/services/http/spacy.service.ts index 7c39e05509362f0f1d577506e6810223332ec248..92825bb8dc2bb79c17bd494feaedab11be444a4a 100644 --- a/src/app/services/http/spacy.service.ts +++ b/src/app/services/http/spacy.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable } from 'rxjs'; import { BaseHttpService } from './base-http.service'; -import { catchError } from 'rxjs/operators'; +import { catchError, map } from 'rxjs/operators'; export type Model = 'de' | 'en' | 'fr'; @@ -73,6 +73,12 @@ export class SpacyService extends BaseHttpService { super(); } + getKeywords(text: string, model: string): Observable<string[]> { + return this.analyse(text, model).pipe( + map(result => result.words.filter(v => v.tag.charAt(0) === 'N').map(v => v.text)) + ); + } + analyse(text: string, model: string): Observable<Result> { const url = '/spacy'; return this.http.post<Result>(url, {text, model}, httpOptions) diff --git a/src/app/utils/CreateCommentWrapper.ts b/src/app/utils/CreateCommentWrapper.ts new file mode 100644 index 0000000000000000000000000000000000000000..db05b6f9774847eab36484b4dfdf40a0f9b97ad5 --- /dev/null +++ b/src/app/utils/CreateCommentWrapper.ts @@ -0,0 +1,65 @@ +import { MatDialog } from '@angular/material/dialog'; +import { TranslateService } from '@ngx-translate/core'; + +import { CreateCommentComponent } from '../components/shared/_dialogs/create-comment/create-comment.component'; +import { User } from '../models/user'; +import { Room } from '../models/room'; +import { Comment } from '../models/comment'; +import { NotificationService } from '../services/util/notification.service'; +import { UserRole } from '../models/user-roles.enum'; +import { CommentService } from '../services/http/comment.service'; + +export class CreateCommentWrapper { + constructor(private translateService: TranslateService, + private notificationService: NotificationService, + private commentService: CommentService, + private dialog: MatDialog, + private room: Room) { + } + + openCreateDialog(user: User): void { + const dialogRef = this.dialog.open(CreateCommentComponent, { + width: '900px', + maxWidth: 'calc( 100% - 50px )', + maxHeight: 'calc( 100vh - 50px )', + autoFocus: false, + }); + dialogRef.componentInstance.user = user; + dialogRef.componentInstance.roomId = this.room.id; + dialogRef.componentInstance.tags = this.room.tags || []; + dialogRef.afterClosed() + .subscribe(result => { + if (result) { + this.send(result, user.role); + } else { + return; + } + }); + } + + send(comment: Comment, userRole: UserRole): void { + if (this.room.directSend) { + this.translateService.get('comment-list.comment-sent').subscribe(msg => { + this.notificationService.show(msg); + }); + comment.ack = true; + } else { + switch (userRole) { + case UserRole.EDITING_MODERATOR: + case UserRole.EXECUTIVE_MODERATOR: + case UserRole.CREATOR: + this.translateService.get('comment-list.comment-sent').subscribe(msg => { + this.notificationService.show(msg); + }); + comment.ack = true; + break; + case UserRole.PARTICIPANT: + this.translateService.get('comment-list.comment-sent-to-moderator').subscribe(msg => { + this.notificationService.show(msg); + }); + break; + } + } + this.commentService.addComment(comment).subscribe(); + } +}