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 852463ad44bb458578838661a8995d7f66d28a60..c31b1c07b82be48a13f1ee09433c0431094c82eb 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 @@ -349,6 +349,11 @@ export class ModeratorCommentListComponent implements OnInit, OnDestroy { }); this.hideCommentsList = true; this.sortComments(this.currentSort); + + // set current filters to local storage for later use + localStorage.setItem('currentFilters', JSON.stringify(this.currentFilter)); + localStorage.setItem('currentPeriod', JSON.stringify(this.period)); + localStorage.setItem('currentFromNowTimestamp', JSON.stringify(this.fromNow)); // can be null } clickedUserNumber(usrNumber: number): void { 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 1003213062bbcff5f49cccbda6a0a12a845c63f8..fdf95e7f172a29c2b8cefd8726b737e60b8d8500 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 @@ -2,33 +2,20 @@ <p>{{'content.topic-cloud-content' | translate}}</p> </div> -<form> - - - <div class="block"> - <input type="radio" id="ma" name="wiederherstellung" value="mitallenFragen"> - <label for="ma" ><div mat-dialog-content>{{'Mit Allen Fragen weiter' | translate}}</div> </label> - </div> - <br> - <div class="block"> - <input type="radio" id="fj" name="wiederherstellung" value="Fragenabjetzt "> - <label for="fj"> <div mat-dialog-content> {{'Fragen ab jetzt' | translate}} </div></label> - </div> - <br> - <div class="block"> - <input type="radio" id="mwe" name="wiederherstellung" value="Reset"> - <label for="mwe"> <div mat-dialog-content>{{'weiter mit Momentanen Einstellungen' | translate}} </div></label> - </div> -</form> +<mat-divider></mat-divider> + <mat-radio-group [(ngModel)]="continueFilter" aria-label="Select an option"> + <mat-radio-button value="continueWithAll">{{'content.continue-with-all-questions' | translate}}</mat-radio-button> + <mat-radio-button checked="true" value="continueWithCurr">{{'content.continue-with-current-questions' | translate}}</mat-radio-button> + <mat-radio-button value="continueWithAllFromNow">{{'content.continue-with-all-questions-from-now' | translate}}</mat-radio-button> + </mat-radio-group> <app-dialog-action-buttons buttonsLabelSection="content" confirmButtonLabel="continue" - + buttonIcon="cloud" [cancelButtonClickAction]="cancelButtonActionCallback()" - [confirmButtonClickAction]="confirmButtonActionCallback()" - [resetButtonClickAction]="resetBuildCloseDialogActionCallback()"> + [confirmButtonClickAction]="confirmButtonActionCallback()"> </app-dialog-action-buttons> diff --git a/src/app/components/shared/_dialogs/topic-cloud-filter/topic-cloud-filter.component.scss b/src/app/components/shared/_dialogs/topic-cloud-filter/topic-cloud-filter.component.scss index 3586315021742758f7ddeed6d9fa13b3705223fc..d0f639b53f2a3aaebcca5c9dd5c1ae7f22d83027 100644 --- a/src/app/components/shared/_dialogs/topic-cloud-filter/topic-cloud-filter.component.scss +++ b/src/app/components/shared/_dialogs/topic-cloud-filter/topic-cloud-filter.component.scss @@ -1,6 +1,12 @@ -.block { - label { - display: inline-block; - } - +mat-radio-button{ + margin: 5px; + +} + + + +mat-radio-group { + display: flex; + flex-direction: column; + margin: 15px 0; } \ No newline at end of file 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 f4b06417de2ee49721ba7880e97449b30a7bda29..dd263fc8630908e5c4e29a702b4b5c3f16a16f1e 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 @@ -16,6 +16,10 @@ export class TopicCloudFilterComponent implements OnInit{ @Input()filteredComments: any; @Input()commentsFilteredByTime: any; + continueFilter: string = 'continueWithCurr'; + tmpCurFilters: string; + tmpPeriod : string; + constructor(public dialogRef: MatDialogRef<RoomCreatorPageComponent>, public dialog: MatDialog, public notificationService: NotificationService, @@ -29,33 +33,41 @@ export class TopicCloudFilterComponent implements OnInit{ ngOnInit() { this.translationService.use(localStorage.getItem('currentLang')); + this.tmpPeriod = localStorage.getItem('currentPeriod'); + this.tmpCurFilters = localStorage.getItem('currentFilters'); } closeDialog(): void { } - /** - * Returns a lambda which closes the dialog on call. - */ - cancelButtonActionCallback(): () => void { + + cancelButtonActionCallback(): () => void { return () => this.dialogRef.close('abort'); } + confirmButtonActionCallback(): () => void { + localStorage.setItem('currentFilters', this.tmpCurFilters); + localStorage.setItem('currentPeriod', this.tmpPeriod); - /** - * Returns a lambda which executes the dialog dedicated action on call. - */ - buildSaveActionCallback(): () => void { - return () => this.closeDialog(); - } + switch (this.continueFilter) { + case 'continueWithAll': + localStorage.setItem('currentFilters', ""); + break; - confirmButtonActionCallback(): () => void { - // - return () => this.dialogRef.close(this.router.navigateByUrl('/participant/room/' +localStorage.getItem('roomId')+ '/comments/tagcloud')); - } - resetBuildCloseDialogActionCallback():() => void { - this.commentsFilteredByTime = []; - this.filteredComments = []; - return () => this.dialogRef.close('reset'); + case 'continueWithCurr': + // filter set already + break; + + case 'continueWithAllFromNow': + localStorage.setItem('currentFilters', ""); + localStorage.setItem('currentPeriod', JSON.stringify('from-now')); + localStorage.setItem('currentFromNowTimestamp', JSON.stringify(new Date().getTime())); + break; + + default: + break; + } + + return () => this.dialogRef.close(this.router.navigateByUrl('/participant/room/' + localStorage.getItem('roomId') + '/comments/tagcloud')); } } 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 787b7359ac6b5353871bbcfdfa68b2cc967be490..cb7475de63cb0897dcda81936cbe582fac3160ae 100644 --- a/src/app/components/shared/comment-list/comment-list.component.ts +++ b/src/app/components/shared/comment-list/comment-list.component.ts @@ -505,6 +505,11 @@ export class CommentListComponent implements OnInit, OnDestroy { }); this.hideCommentsList = true; this.sortComments(this.currentSort); + + // set current filters to local storage for later use + localStorage.setItem('currentFilters', JSON.stringify(this.currentFilter)); + localStorage.setItem('currentPeriod', JSON.stringify(this.period)); + localStorage.setItem('currentFromNowTimestamp', JSON.stringify(this.fromNow)); // can be null } sort(array: any[], type: string): any[] { @@ -637,6 +642,7 @@ export class CommentListComponent implements OnInit, OnDestroy { } else { this.commentsFilteredByTime = this.comments; } + this.filterComments(this.currentFilter); this.titleService.attachTitle('(' + this.commentsFilteredByTime.length + ')'); } 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 fb8e5e78065ab4196baa9b8ce34ed2b71635855d..932d37b486240c9d7bebf67dd3a81f0b0a842def 100644 --- a/src/app/components/shared/tag-cloud/tag-cloud.component.ts +++ b/src/app/components/shared/tag-cloud/tag-cloud.component.ts @@ -13,6 +13,7 @@ import {Comment} from '../../../models/comment'; import {LanguageService} from "../../../services/util/language.service"; import {TranslateService} from "@ngx-translate/core"; import {QuestionWallComment} from "../questionwall/QuestionWallComment"; +import { SELECT_PANEL_INDENT_PADDING_X } from '@angular/material/select'; class TagComment implements CloudData { @@ -79,7 +80,7 @@ export class TagCloudComponent implements OnInit { ngOnInit(): void { this.translateService.use(localStorage.getItem('currentLang')); - this.commentService.getAckComments(this.roomId).subscribe((comments: Comment[]) => { + this.commentService.getFilteredComments(this.roomId).subscribe((comments: Comment[]) => { this.analyse(comments); }); } diff --git a/src/app/services/http/comment.service.ts b/src/app/services/http/comment.service.ts index cb19d5f274c60bcfaa8be2a16e5598e50c8d5e59..a6828e2a01255442f49a89b7699acc7c8cc1eff6 100644 --- a/src/app/services/http/comment.service.ts +++ b/src/app/services/http/comment.service.ts @@ -97,7 +97,105 @@ export class CommentService extends BaseHttpService { ); } - getAckComments(roomId: string): Observable<Comment[]> { + + filter(com : Comment) : boolean { + /* Get Filter Options */ + const currentFilters = localStorage.getItem('currentFilters'); + const period = localStorage.getItem('currentPeriod'); + const timestamp = localStorage.getItem('currentFromNowTimestamp'); + + /* Filter by Period */ + /* + const currentTime = new Date(); + const hourInSeconds = 3600000; + let periodInSeconds; + + enum Period { + FROMNOW = 'from-now', + ONEHOUR = 'time-1h', + THREEHOURS = 'time-3h', + ONEDAY = 'time-1d', + ONEWEEK = 'time-1w', + TWOWEEKS = 'time-2w', + ALL = 'time-all' + } + + if (period !== Period.ALL) { + switch (period) { + case Period.FROMNOW: + break; + case Period.ONEHOUR: + periodInSeconds = hourInSeconds; + break; + case Period.THREEHOURS: + periodInSeconds = hourInSeconds * 2; + break; + case Period.ONEDAY: + periodInSeconds = hourInSeconds * 24; + break; + case Period.ONEWEEK: + periodInSeconds = hourInSeconds * 168; + break; + case Period.TWOWEEKS: + periodInSeconds = hourInSeconds * 336; + break; + } + } + + const commentTime = new Date(com.timestamp).getTime(); + const refTime = (period === Period.FROMNOW ? timestamp : (currentTime.getTime() - periodInSeconds)); + + if (commentTime < refTime) { + return false; + } + + */ + + /* Other Filters */ + const read = 'read'; + const unread = 'unread'; + const favorite = 'favorite'; + const correct = 'correct'; + const wrong = 'wrong'; + const bookmark = 'bookmark'; + const answer = 'answer'; + const unanswered = 'unanswered'; + + enum CorrectWrong { + NULL, + CORRECT, + WRONG + } + + if (currentFilters != '') { // no filters => return true + switch (currentFilters) { + case correct: + return com.correct === CorrectWrong.CORRECT ? true : false; + case wrong: + return com.correct === CorrectWrong.WRONG ? true : false; + case favorite: + return com.favorite; + case bookmark: + return com.bookmark; + case read: + return com.read; + case unread: + return !com.read; + case answer: + return com.answer != ""; + case unanswered: + return !com.answer; + } + } + + return true; + } + + getFilteredComments(roomId: string) : Observable<Comment[]> { + return this.getAckComments(roomId).pipe(map(commentList => commentList.filter(comment => this.filter(comment)))); + } + + getAckComments(roomId: string, filterQuestion : boolean = false): Observable<Comment[]> { const connectionUrl = this.apiUrl.base + this.apiUrl.comment + this.apiUrl.find; return this.http.post<Comment[]>(connectionUrl, { properties: { roomId: roomId, ack: true },