From 4e61842fe235f9e47e8cd5a3ff535b66446ca64c Mon Sep 17 00:00:00 2001 From: Ruben Bimberg <ruben.bimberg@mni.thm.de> Date: Tue, 8 Jun 2021 19:38:27 +0200 Subject: [PATCH] Finishes merge with staging --- .../cloud-configuration.component.ts | 2 +- .../topic-cloud-administration.component.html | 6 +- .../comment-list/comment-list.component.ts | 1 - .../shared/header/header.component.ts | 2 +- .../tag-cloud-pop-up.component.ts | 2 +- .../shared/tag-cloud/tag-cloud.component.ts | 15 ++--- .../util/tag-cloud-data.service.spec.ts | 16 +++++ .../util/tag-cloud-data.service.ts} | 62 +++++++++++-------- .../util/topic-cloud-admin.service.ts | 4 +- 9 files changed, 67 insertions(+), 43 deletions(-) create mode 100644 src/app/services/util/tag-cloud-data.service.spec.ts rename src/app/{components/shared/tag-cloud/tag-cloud.data-manager.ts => services/util/tag-cloud-data.service.ts} (86%) 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 94f2117a5..1115225d8 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 06aa818ba..f621877ae 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 2518fad0f..8bf801d63 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 65d387666..c3842163a 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 e2d3719ce..de8d45233 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 b85ca8eee..451e5bb90 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 000000000..ee5ff3e99 --- /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 00ca8975c..48e81f951 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 fdecfe2f8..683739b34 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); }); -- GitLab