From 9adb3e7a8742b99ec04d2f84cd7a278d09d23058 Mon Sep 17 00:00:00 2001 From: Ruben Bimberg <ruben.bimberg@mni.thm.de> Date: Wed, 3 Nov 2021 15:32:07 +0100 Subject: [PATCH] Partial commit --- .../moderator-comment-list.component.ts | 2 +- .../topic-cloud-filter.component.html | 23 ++++++++++++--- .../topic-cloud-filter.component.ts | 27 +++++++++++++---- .../comment-list/comment-list.component.ts | 2 +- .../comment-list/comment-list.filter.ts | 8 ++--- .../shared/tag-cloud/tag-cloud.component.ts | 29 ++++++++++++++++++- .../services/util/tag-cloud-data.service.ts | 2 +- 7 files changed, 75 insertions(+), 18 deletions(-) diff --git a/src/app/components/moderator/moderator-comment-list/moderator-comment-list.component.ts b/src/app/components/moderator/moderator-comment-list/moderator-comment-list.component.ts index 5a77176e3..09d0c46e3 100644 --- a/src/app/components/moderator/moderator-comment-list/moderator-comment-list.component.ts +++ b/src/app/components/moderator/moderator-comment-list/moderator-comment-list.component.ts @@ -91,7 +91,7 @@ export class ModeratorCommentListComponent implements OnInit, OnDestroy { private moderationService: ModeratorService ) { langService.langEmitter.subscribe(lang => translateService.use(lang)); - this.filter = CommentListFilter.loadCurrentFilter(); + this.filter = CommentListFilter.loadFilter(); } handlePageEvent(e: PageEvent) { diff --git a/src/app/components/shared/_dialogs/topic-cloud-filter/topic-cloud-filter.component.html b/src/app/components/shared/_dialogs/topic-cloud-filter/topic-cloud-filter.component.html index d9bb41a3c..fca3f52e7 100644 --- a/src/app/components/shared/_dialogs/topic-cloud-filter/topic-cloud-filter.component.html +++ b/src/app/components/shared/_dialogs/topic-cloud-filter/topic-cloud-filter.component.html @@ -84,6 +84,8 @@ autocomplete="off" type="number" appAccessibilityEscapedInput + [min]="maxWordCountMin" + [max]="maxWordCountMax" [formControl]="maxWordCount"> <mat-hint> {{'content.field-hint-number' | translate: { min: maxWordCountMin, max: maxWordCountMax } }} @@ -100,13 +102,25 @@ </mat-form-field> <mat-form-field appearance="fill"> <mat-label>Maximale Wortlänge</mat-label> - <input matInput6 + <input matInput autocomplete="off" type="number" appAccessibilityEscapedInput - min="3" - max="30" - value="15"> + [min]="maxWordLengthMin" + [max]="maxWordLengthMax" + [formControl]="maxWordLength"> + <mat-hint> + {{'content.field-hint-number' | translate: { min: maxWordLengthMin, max: maxWordLengthMax } }} + </mat-hint> + <mat-error *ngIf="maxWordLength.hasError('required')"> + {{'content.field-required' | translate}} + </mat-error> + <mat-error *ngIf="maxWordLength.hasError('min')"> + {{'content.field-too-low' | translate: { min: maxWordLengthMin } }} + </mat-error> + <mat-error *ngIf="maxWordLength.hasError('max')"> + {{'content.field-too-high' | translate: { max: maxWordLengthMax } }} + </mat-error> </mat-form-field> </mat-card> </mat-radio-group> @@ -132,6 +146,7 @@ (click)="openHelp()"> <mat-icon>help</mat-icon> {{ 'explanation.label' | translate}} + </button> </ars-col> <ars-col> diff --git a/src/app/components/shared/_dialogs/topic-cloud-filter/topic-cloud-filter.component.ts b/src/app/components/shared/_dialogs/topic-cloud-filter/topic-cloud-filter.component.ts index 183a77a4b..379fd5ebf 100644 --- a/src/app/components/shared/_dialogs/topic-cloud-filter/topic-cloud-filter.component.ts +++ b/src/app/components/shared/_dialogs/topic-cloud-filter/topic-cloud-filter.component.ts @@ -95,7 +95,6 @@ export class TopicCloudFilterComponent implements OnInit, OnDestroy { this.translationService.use(localStorage.getItem('currentLang')); const subscriptionEventService = this.eventService.on<CommentListData>('currentRoomData').subscribe(data => { subscriptionEventService.unsubscribe(); - console.log(data.currentFilter); this.tmpFilter = data.currentFilter; this._room = data.room; this.roomDataService.getRoomData(data.room.id).subscribe(roomData => { @@ -106,7 +105,7 @@ export class TopicCloudFilterComponent implements OnInit, OnDestroy { }); }); this._subscriptionCommentUpdates = this.roomDataService.receiveUpdates([{ finished: true }]) - .subscribe(_ => this.commentsLoadedCallback()); + .subscribe(_ => this.commentsLoadedCallback()); }); this.eventService.broadcast('pushCurrentRoomData'); } @@ -173,6 +172,9 @@ export class TopicCloudFilterComponent implements OnInit, OnDestroy { return () => { let filter: CommentListFilter; + let brainstorming: any = { + brainstormingActive: false + }; switch (this.continueFilter) { case 'continueWithAll': // all questions allowed @@ -181,10 +183,19 @@ export class TopicCloudFilterComponent implements OnInit, OnDestroy { break; case 'continueWithAllFromNow': + if (!this.maxWordCount.valid || !this.maxWordLength.valid) { + return; + } filter = new CommentListFilter(this.tmpFilter); filter.resetToDefault(); filter.period = Period.fromNow; filter.fromNow = new Date().getTime(); + brainstorming = { + brainstormingActive: true, + question: this.question, + maxWordCount: this.maxWordCount.value, + maxWordLength: this.maxWordLength.value + }; break; case 'continueWithCurr': @@ -195,11 +206,15 @@ export class TopicCloudFilterComponent implements OnInit, OnDestroy { return; } - localStorage.setItem('tag-cloud-question', this.question); - this.dialogRef.close(); - this.router.navigateByUrl(this.target).then(() => { - filter.save(); + const subscription = this.eventService.on('tagCloudInit').subscribe(() => { + this.eventService.broadcast('tagCloudPassFilterData', { + brainstorming, + filter + }); + subscription.unsubscribe(); }); + this.dialogRef.close(); + this.router.navigateByUrl(this.target); }; } 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 750faa9b3..5c5002a71 100644 --- a/src/app/components/shared/comment-list/comment-list.component.ts +++ b/src/app/components/shared/comment-list/comment-list.component.ts @@ -115,7 +115,7 @@ export class CommentListComponent implements OnInit, OnDestroy { this.searchPlaceholder = msg; }); }); - this.filter = CommentListFilter.loadCurrentFilter(); + this.filter = CommentListFilter.loadFilter(); } handlePageEvent(e: PageEvent) { diff --git a/src/app/components/shared/comment-list/comment-list.filter.ts b/src/app/components/shared/comment-list/comment-list.filter.ts index 32ce9d479..7db173bda 100644 --- a/src/app/components/shared/comment-list/comment-list.filter.ts +++ b/src/app/components/shared/comment-list/comment-list.filter.ts @@ -77,8 +77,8 @@ export class CommentListFilter { this.lastRoomId = obj.lastRoomId; } - static loadCurrentFilter(): CommentListFilter { - return new CommentListFilter(JSON.parse(localStorage.getItem('currentFilter'))); + static loadFilter(name = 'currentFilter'): CommentListFilter { + return new CommentListFilter(JSON.parse(localStorage.getItem(name))); } resetToDefault() { @@ -108,13 +108,13 @@ export class CommentListFilter { this.moderatorIds = new Set<string>([...moderators]); } - save() { + save(name = 'currentFilter') { const ownerId = this.ownerId; const threshold = this.threshold; const userId = this.userId; const moderatorIds = this.moderatorIds; this.ownerId = this.threshold = this.userId = this.moderatorIds = undefined; - localStorage.setItem('currentFilter', JSON.stringify(this)); + localStorage.setItem(name, JSON.stringify(this)); this.ownerId = ownerId; this.threshold = threshold; this.userId = userId; 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 a8d3120eb..09bec4288 100644 --- a/src/app/components/shared/tag-cloud/tag-cloud.component.ts +++ b/src/app/components/shared/tag-cloud/tag-cloud.component.ts @@ -33,6 +33,8 @@ import { Theme } from '../../../../theme/Theme'; import { MatDrawer } from '@angular/material/sidenav'; import { DeviceInfoService } from '../../../services/util/device-info.service'; import { SyncFence } from '../../../utils/SyncFence'; +import { Subscription } from 'rxjs'; +import { CommentListFilter } from '../comment-list/comment-list.filter'; class CustomPosition implements Position { left: number; @@ -107,6 +109,9 @@ export class TagCloudComponent implements OnInit, OnDestroy, AfterContentInit { themeSubscription = null; createCommentWrapper: CreateCommentWrapper = null; question = ''; + maxWordCount: number; + maxWordLength: number; + brainstormingActive: boolean; private _currentSettings: CloudParameters; private _subscriptionCommentlist = null; private _subscriptionRoom = null; @@ -116,6 +121,7 @@ export class TagCloudComponent implements OnInit, OnDestroy, AfterContentInit { private readonly _smartDebounce = new SmartDebounce(50, 1_000); private _currentTheme: Theme; private _syncFenceBuildCloud: SyncFence; + private _eventFilterSubscription: Subscription; constructor(private commentService: CommentService, private langService: LanguageService, @@ -138,11 +144,24 @@ export class TagCloudComponent implements OnInit, OnDestroy, AfterContentInit { this.translateService.use(lang); }); this._currentSettings = TagCloudComponent.getCurrentCloudParameters(); - this.question = localStorage.getItem('tag-cloud-question'); this._calcCanvas = document.createElement('canvas'); this._calcRenderContext = this._calcCanvas.getContext('2d'); this._syncFenceBuildCloud = new SyncFence(2, () => this.dataManager.bindToRoom(this.room, this.userRole, this.user.id)); + this._eventFilterSubscription = eventService.on('tagCloudPassFilterData').subscribe((data: any) => { + if (data.brainstorming) { + this.brainstormingActive = true; + this.question = data.brainstorming.question as string; + this.maxWordCount = data.brainstorming.maxWordCount as number; + this.maxWordLength = data.brainstorming.maxWordLength as number; + } else { + this.brainstormingActive = false; + } + localStorage.setItem('brainstormingActive', this.brainstormingActive ? 'true' : 'false'); + (data.filter as CommentListFilter).save('cloudFilter'); + this._eventFilterSubscription.unsubscribe(); + }); + eventService.broadcast('tagCloudInit'); } private static getCurrentCloudParameters(): CloudParameters { @@ -157,6 +176,10 @@ export class TagCloudComponent implements OnInit, OnDestroy, AfterContentInit { } ngOnInit(): void { + if (!this._eventFilterSubscription.closed) { + this._eventFilterSubscription.unsubscribe(); + this.brainstormingActive = localStorage.getItem('brainstormingActive') === 'true'; + } this.userRole = this.route.snapshot.data.roles[0]; this.updateGlobalStyles(); this.headerInterface = this.eventService.on<string>('navigate').subscribe(e => { @@ -392,6 +415,10 @@ export class TagCloudComponent implements OnInit, OnDestroy, AfterContentInit { admin.endDate = data.admin.endDate; admin.scorings = data.admin.scorings; data.admin = undefined; + this.question = data.brainstorming?.question; + this.maxWordLength = data.brainstorming?.maxWordLength; + this.maxWordCount = data.brainstorming?.maxWordCount; + data.brainstorming = undefined; this.topicCloudAdmin.setAdminData(admin, false, this.userRole); if (this.deviceInfo.isCurrentlyMobile) { const defaultParams = new CloudParameters(); diff --git a/src/app/services/util/tag-cloud-data.service.ts b/src/app/services/util/tag-cloud-data.service.ts index f79b7cb66..1078ba1b5 100644 --- a/src/app/services/util/tag-cloud-data.service.ts +++ b/src/app/services/util/tag-cloud-data.service.ts @@ -177,7 +177,7 @@ export class TagCloudDataService { throw new Error('Room already bound.'); } this._currentModerators = null; - this._currentFilter = CommentListFilter.loadCurrentFilter(); + this._currentFilter = CommentListFilter.loadFilter(); this._currentFilter.updateRoom(room); this._roomId = room.id; this._currentOwner = room.ownerId; -- GitLab