diff --git a/src/app/components/shared/_dialogs/cloud-configuration/cloud-configuration.component.ts b/src/app/components/shared/_dialogs/cloud-configuration/cloud-configuration.component.ts index 94f2117a5e6498a1234e130d54c39cc4b0d2b192..1115225d8b676ee6c8b855373117f2d0d9e5fe3f 100644 --- a/src/app/components/shared/_dialogs/cloud-configuration/cloud-configuration.component.ts +++ b/src/app/components/shared/_dialogs/cloud-configuration/cloud-configuration.component.ts @@ -1,9 +1,9 @@ import { Component, Input, OnInit } from '@angular/core'; import { TranslateService } from '@ngx-translate/core'; import { TagCloudComponent } from '../../tag-cloud/tag-cloud.component'; -import { TagCloudMetaDataCount } from '../../tag-cloud/tag-cloud.data-manager'; import { CloudParameters, CloudTextStyle } from '../../tag-cloud/tag-cloud.interface'; import { WeightClass } from './weight-class.interface'; +import { TagCloudMetaDataCount } from '../../../../services/util/tag-cloud-data.service'; @Component({ selector: 'app-cloud-configuration', diff --git a/src/app/components/shared/_dialogs/topic-cloud-administration/topic-cloud-administration.component.html b/src/app/components/shared/_dialogs/topic-cloud-administration/topic-cloud-administration.component.html index 06aa818ba806b9e31e753813169f82e597594369..f621877ae21001e348de4ff1dc69bf4c9ead0312 100644 --- a/src/app/components/shared/_dialogs/topic-cloud-administration/topic-cloud-administration.component.html +++ b/src/app/components/shared/_dialogs/topic-cloud-administration/topic-cloud-administration.component.html @@ -108,10 +108,10 @@ Spacy labels </mat-panel-title> </mat-expansion-panel-header> - + <mat-tab-group animationDuration="0ms" mat-stretch-tabs mat-align-tabs="center"> <mat-tab label="{{'topic-cloud-dialog.german' | translate}}"> - <mat-selection-list [(ngModel)]="wantedLabels.de"> + <mat-selection-list *ngIf="wantedLabels" [(ngModel)]="wantedLabels.de"> <mat-option class="color-on-surface" (click)="selectAllDE(); allSelectedDE = !allSelectedDE"> <mat-label> @@ -126,7 +126,7 @@ </mat-selection-list> </mat-tab> <mat-tab label="{{'topic-cloud-dialog.english' | translate}}"> - <mat-selection-list [(ngModel)]="wantedLabels.en"> + <mat-selection-list *ngIf="wantedLabels" [(ngModel)]="wantedLabels.en"> <mat-option class="color-on-surface" (click)="selectAllEN(); allSelectedEN = !allSelectedEN"> <mat-label> 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 2518fad0f1c687ad5f9713a5d1751635f50b43bb..8bf801d639de9196d687dd999531981f0cc3cdf0 100644 --- a/src/app/components/shared/comment-list/comment-list.component.ts +++ b/src/app/components/shared/comment-list/comment-list.component.ts @@ -459,7 +459,6 @@ export class CommentListComponent implements OnInit, OnDestroy { this.sortComments(this.currentSort); return; } - console.log(compare); this.filteredComments = this.commentsFilteredByTime.filter(c => { switch (type) { case this.correct: diff --git a/src/app/components/shared/header/header.component.ts b/src/app/components/shared/header/header.component.ts index 65d387666d2b9ac11a2935dfbf73971d1b319a73..c3842163ab6ec31498753ccb4abf41f0ae106357 100644 --- a/src/app/components/shared/header/header.component.ts +++ b/src/app/components/shared/header/header.component.ts @@ -23,7 +23,7 @@ import { MotdService } from '../../../services/http/motd.service'; import { TopicCloudFilterComponent } from '../_dialogs/topic-cloud-filter/topic-cloud-filter.component'; import { RoomService } from '../../../services/http/room.service'; import { Room } from '../../../models/room'; -import { TagCloudMetaData } from '../tag-cloud/tag-cloud.data-manager'; +import { TagCloudMetaData } from '../../../services/util/tag-cloud-data.service'; @Component({ selector: 'app-header', diff --git a/src/app/components/shared/tag-cloud/tag-cloud-pop-up/tag-cloud-pop-up.component.ts b/src/app/components/shared/tag-cloud/tag-cloud-pop-up/tag-cloud-pop-up.component.ts index e2d3719cec4db64f2b36a8c1ac03b7beef0d37a8..de8d4523354b49e75560fa72208c99d5c2260e6b 100644 --- a/src/app/components/shared/tag-cloud/tag-cloud-pop-up/tag-cloud-pop-up.component.ts +++ b/src/app/components/shared/tag-cloud/tag-cloud-pop-up/tag-cloud-pop-up.component.ts @@ -1,10 +1,10 @@ import { AfterViewInit, Component, ElementRef, Input, OnInit, ViewChild } from '@angular/core'; -import { TagCloudDataTagEntry } from '../tag-cloud.data-manager'; import { TranslateService } from '@ngx-translate/core'; import { LanguageService } from '../../../../services/util/language.service'; import { TagCloudComponent } from '../tag-cloud.component'; import { AuthenticationService } from '../../../../services/http/authentication.service'; import { User } from '../../../../models/user'; +import { TagCloudDataTagEntry } from "../../../../services/util/tag-cloud-data.service"; const CLOSE_TIME = 1500; 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 b85ca8eeea1a37760e6e293262985a46ebd1497d..451e5bb905137f85500b9aa7824f08e4aef690dc 100644 --- a/src/app/components/shared/tag-cloud/tag-cloud.component.ts +++ b/src/app/components/shared/tag-cloud/tag-cloud.component.ts @@ -23,10 +23,10 @@ import { ThemeService } from '../../../../theme/theme.service'; import { cloneParameters, CloudParameters, CloudTextStyle, CloudWeightSettings } from './tag-cloud.interface'; import { TopicCloudAdministrationComponent } from '../_dialogs/topic-cloud-administration/topic-cloud-administration.component'; import { WsCommentServiceService } from '../../../services/websockets/ws-comment-service.service'; -import { TagCloudDataManager, TagCloudDataTagEntry } from './tag-cloud.data-manager'; import { CreateCommentWrapper } from '../../../utils/CreateCommentWrapper'; import { TopicCloudAdminService } from '../../../services/util/topic-cloud-admin.service'; import { TagCloudPopUpComponent } from './tag-cloud-pop-up/tag-cloud-pop-up.component'; +import { TagCloudDataService, TagCloudDataTagEntry } from '../../../services/util/tag-cloud-data.service'; class CustomPosition implements Position { left: number; @@ -163,7 +163,6 @@ export class TagCloudComponent implements OnInit, AfterViewInit, OnDestroy { //Subscriptions headerInterface = null; themeSubscription = null; - readonly dataManager: TagCloudDataManager; private _currentSettings: CloudParameters; private _createCommentWrapper: CreateCommentWrapper = null; private _subscriptionCommentlist = null; @@ -183,12 +182,12 @@ export class TagCloudComponent implements OnInit, AfterViewInit, OnDestroy { private themeService: ThemeService, private wsCommentService: WsCommentServiceService, private topicCloudAdmin: TopicCloudAdminService, - private router: Router) { + private router: Router, + public dataManager: TagCloudDataService) { this.roomId = localStorage.getItem('roomId'); this.langService.langEmitter.subscribe(lang => { this.translateService.use(lang); }); - this.dataManager = new TagCloudDataManager(wsCommentService, commentService, topicCloudAdmin); this._currentSettings = TagCloudComponent.getCurrentCloudParameters(); this._calcCanvas = document.createElement('canvas'); this._calcRenderContext = this._calcCanvas.getContext('2d'); @@ -223,8 +222,6 @@ export class TagCloudComponent implements OnInit, AfterViewInit, OnDestroy { data: { user: this.user } - }).afterClosed().subscribe(() => { - this.dataManager.updateAdminSettings(); }); } }); @@ -269,7 +266,7 @@ export class TagCloudComponent implements OnInit, AfterViewInit, OnDestroy { ngAfterViewInit() { document.getElementById('footer_rescale').style.display = 'none'; this._calcFont = window.getComputedStyle(document.getElementById('tagCloudComponent')).fontFamily; - this.dataManager.activate(this.roomId); + this.dataManager.bindToRoom(this.roomId); this.dataManager.updateDemoData(this.translateService); this.setCloudParameters(TagCloudComponent.getCurrentCloudParameters(), false); } @@ -278,10 +275,10 @@ export class TagCloudComponent implements OnInit, AfterViewInit, OnDestroy { document.getElementById('footer_rescale').style.display = 'block'; this.headerInterface.unsubscribe(); this.themeSubscription.unsubscribe(); - this.dataManager.deactivate(); + this.dataManager.unbindRoom(); } - get tagCloudDataManager(): TagCloudDataManager { + get tagCloudDataManager(): TagCloudDataService { return this.dataManager; } diff --git a/src/app/services/util/tag-cloud-data.service.spec.ts b/src/app/services/util/tag-cloud-data.service.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..ee5ff3e99990ea480d89a1d867eb3f7d1236aa89 --- /dev/null +++ b/src/app/services/util/tag-cloud-data.service.spec.ts @@ -0,0 +1,16 @@ +/*import { TestBed } from '@angular/core/testing'; + +import { TagCloudDataService } from './tag-cloud-data.service'; + +describe('TagCloudDataService', () => { + let service: TagCloudDataService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(TagCloudDataService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +});*/ diff --git a/src/app/components/shared/tag-cloud/tag-cloud.data-manager.ts b/src/app/services/util/tag-cloud-data.service.ts similarity index 86% rename from src/app/components/shared/tag-cloud/tag-cloud.data-manager.ts rename to src/app/services/util/tag-cloud-data.service.ts index 00ca8975c0d56a33d0c000dd968ad66ad3923b5e..48e81f9512fb43f10f050551c026c574dc538509 100644 --- a/src/app/components/shared/tag-cloud/tag-cloud.data-manager.ts +++ b/src/app/services/util/tag-cloud-data.service.ts @@ -1,13 +1,15 @@ -import { Comment } from '../../../models/comment'; -import { Observable, Subject } from 'rxjs'; -import { WsCommentServiceService } from '../../../services/websockets/ws-comment-service.service'; -import { CommentService } from '../../../services/http/comment.service'; -import { CloudParameters } from './tag-cloud.interface'; +import { Injectable } from '@angular/core'; +import { TopicCloudAdminData } from '../../components/shared/_dialogs/topic-cloud-administration/TopicCloudAdminData'; +import { Observable, Subject, Subscription } from 'rxjs'; +import { WsCommentServiceService } from '../websockets/ws-comment-service.service'; +import { CommentService } from '../http/comment.service'; +import { TopicCloudAdminService } from './topic-cloud-admin.service'; +import { CommentFilterOptions } from '../../utils/filter-options'; import { TranslateService } from '@ngx-translate/core'; +import { CloudParameters } from '../../components/shared/tag-cloud/tag-cloud.interface'; +import { Comment } from '../../models/comment'; +import { CommentFilterUtils } from '../../utils/filter-comments'; import { Message } from '@stomp/stompjs'; -import { CommentFilterUtils } from '../../../utils/filter-comments'; -import { TopicCloudAdminService } from '../../../services/util/topic-cloud-admin.service'; -import { CommentFilterOptions } from '../../../utils/filter-options'; export interface TagCloudDataTagEntry { weight: number; @@ -60,7 +62,10 @@ export enum TagCloudCalcWeightType { byLengthAndVotes } -export class TagCloudDataManager { +@Injectable({ + providedIn: 'root' +}) +export class TagCloudDataService { private _isDemoActive: boolean; private _isAlphabeticallySorted: boolean; private _dataBus: Subject<TagCloudData>; @@ -75,6 +80,10 @@ export class TagCloudDataManager { private _lastMetaData: TagCloudMetaData = null; private readonly _currentMetaData: TagCloudMetaData; private _demoData: TagCloudData = null; + private _adminData: TopicCloudAdminData = null; + private _currentBlacklist: string[] = []; + private _subscriptionAdminData: Subscription; + private _subscriptionBlacklist: Subscription; constructor(private _wsCommentService: WsCommentServiceService, private _commentService: CommentService, @@ -98,9 +107,18 @@ export class TagCloudDataManager { }); } - activate(roomId: string): void { + bindToRoom(roomId: string): void { this._roomId = roomId; - this.updateAdminSettings(false); + this._subscriptionAdminData = this._tagCloudAdmin.getAdminData.subscribe(adminData => { + this._adminData = adminData; + this._calcWeightType = this._adminData.considerVotes ? TagCloudCalcWeightType.byLengthAndVotes : TagCloudCalcWeightType.byLength; + this._supplyType = this._adminData.keywordORfulltext as unknown as TagCloudDataSupplyType; + this.rebuildTagData(); + }); + this._subscriptionBlacklist = this._tagCloudAdmin.getBlacklist().subscribe(blacklist => { + this._currentBlacklist = blacklist || []; + this.rebuildTagData(); + }); this.fetchData(); if (!CommentFilterOptions.readFilter().paused) { this._wsCommentSubscription = this._wsCommentService @@ -108,7 +126,9 @@ export class TagCloudDataManager { } } - deactivate(): void { + unbindRoom(): void { + this._subscriptionBlacklist.unsubscribe(); + this._subscriptionAdminData.unsubscribe(); if (this._wsCommentSubscription !== null) { this._wsCommentSubscription.unsubscribe(); this._wsCommentSubscription = null; @@ -194,19 +214,10 @@ export class TagCloudDataManager { } blockWord(tag: string): void { - this._tagCloudAdmin.addToBlacklistWordList(tag.toLowerCase()); + this._tagCloudAdmin.addWordToBlacklist(tag.toLowerCase()); this.rebuildTagData(); } - updateAdminSettings(refresh = true): void { - const data = this._tagCloudAdmin.getAdminData; - this._calcWeightType = data.considerVotes ? TagCloudCalcWeightType.byLengthAndVotes : TagCloudCalcWeightType.byLength; - this._supplyType = data.keywordORfulltext as unknown as TagCloudDataSupplyType; - if (refresh) { - this.rebuildTagData(); - } - } - updateConfig(parameters: CloudParameters): boolean { if (parameters.sortAlphabetically !== this._isAlphabeticallySorted) { this._isAlphabeticallySorted = parameters.sortAlphabetically; @@ -272,10 +283,12 @@ export class TagCloudDataManager { } private rebuildTagData() { + if (!this._lastFetchedComments) { + return; + } const currentMeta = this._isDemoActive ? this._lastMetaData : this._currentMetaData; const data: TagCloudData = new Map<string, TagCloudDataTagEntry>(); const users = new Set<number>(); - const blackList = this._tagCloudAdmin.getBlacklistWords(true, true); for (const comment of this._lastFetchedComments) { let keywords = comment.keywordsFromQuestioner; if (this._supplyType === TagCloudDataSupplyType.keywordsAndFullText) { @@ -291,7 +304,7 @@ export class TagCloudDataManager { for (const keyword of keywords) { const lowerCaseKeyWord = keyword.toLowerCase(); let profanity = false; - for (const word of blackList) { + for (const word of this._currentBlacklist) { if (lowerCaseKeyWord.includes(word)) { profanity = true; break; @@ -412,5 +425,4 @@ export class TagCloudDataManager { break; } } - } diff --git a/src/app/services/util/topic-cloud-admin.service.ts b/src/app/services/util/topic-cloud-admin.service.ts index fdecfe2f88e79ef25650ac1890c6028c3dfa424e..683739b340167b4360bdbfd2fb9e23fd0918cd67 100644 --- a/src/app/services/util/topic-cloud-admin.service.ts +++ b/src/app/services/util/topic-cloud-admin.service.ts @@ -162,7 +162,7 @@ export class TopicCloudAdminService { } getDefaultSpacyTagsDE(): string[] { - let tags: string[]; + const tags: string[] = []; spacyLabels.de.forEach(label => { tags.push(label.tag); }); @@ -170,7 +170,7 @@ export class TopicCloudAdminService { } getDefaultSpacyTagsEN(): string[] { - let tags: string[]; + const tags: string[] = []; spacyLabels.en.forEach(label => { tags.push(label.tag); });