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 a43c004ddd59b02b636c793290dabb893e6181f0..89afc96ef053467ae2485be1cfc1279eea0690fb 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 @@ -15,7 +15,6 @@ import { CorrectWrong } from '../../../models/correct-wrong.enum'; import { EventService } from '../../../services/util/event.service'; import { Router } from '@angular/router'; import { AppComponent } from '../../../app.component'; -import { Period } from '../../shared/comment-list/comment-list.component'; import { ModeratorsComponent } from '../../creator/_dialogs/moderators/moderators.component'; import { TagsComponent } from '../../creator/_dialogs/tags/tags.component'; import { DeleteCommentsComponent } from '../../creator/_dialogs/delete-comments/delete-comments.component'; @@ -23,7 +22,7 @@ import { Export } from '../../../models/export'; import { CreateCommentComponent } from '../../shared/_dialogs/create-comment/create-comment.component'; import { NotificationService } from '../../../services/util/notification.service'; import { BonusTokenService } from '../../../services/http/bonus-token.service'; -import { CommentFilterOptions } from '../../../utils/filter-options'; +import { CommentFilter, Period } from '../../../utils/filter-options'; @Component({ @@ -189,12 +188,10 @@ export class ModeratorCommentListComponent implements OnInit, OnDestroy { this.translateService.get('comment-list.search').subscribe(msg => { this.searchPlaceholder = msg; }); - - this.getCurrentFilter().writeFilter(); } - private getCurrentFilter() : CommentFilterOptions { - let filter = new CommentFilterOptions(); + private getCurrentFilter() { + let filter = new CommentFilter(); filter.filterSelected = this.currentFilter; filter.periodSet = this.period; @@ -202,7 +199,7 @@ export class ModeratorCommentListComponent implements OnInit, OnDestroy { filter.timeStampNow = new Date().getTime(); } - return filter; + CommentFilter.currentFilter = filter; } checkScroll(): void { @@ -366,8 +363,6 @@ export class ModeratorCommentListComponent implements OnInit, OnDestroy { }); this.hideCommentsList = true; this.sortComments(this.currentSort); - - CommentFilterOptions.writeFilterStatic(this.getCurrentFilter()); } clickedUserNumber(usrNumber: number): void { @@ -444,8 +439,6 @@ export class ModeratorCommentListComponent implements OnInit, OnDestroy { this.commentsFilteredByTime = this.comments; } - this.getCurrentFilter().writeFilter(); - this.filterComments(this.currentFilter); } } diff --git a/src/app/components/shared/_dialogs/create-comment/create-comment.component.html b/src/app/components/shared/_dialogs/create-comment/create-comment.component.html index 2a7cb1d793eee5ac71d438944affdd5bb3f2a9de..b2a76fad7c816a9134ef5aa7675ec9627229b2d7 100644 --- a/src/app/components/shared/_dialogs/create-comment/create-comment.component.html +++ b/src/app/components/shared/_dialogs/create-comment/create-comment.component.html @@ -113,6 +113,7 @@ <app-dialog-action-buttons buttonsLabelSection="comment-page" confirmButtonLabel="send" + [showLoadingCycle] = "isSendingToSpacy" [showDivider]="false" [spacing]="false" [cancelButtonClickAction]="buildCloseDialogActionCallback()" diff --git a/src/app/components/shared/_dialogs/create-comment/create-comment.component.scss b/src/app/components/shared/_dialogs/create-comment/create-comment.component.scss index 09f756425cc41ece379423affb91493d8de00cec..d50c707cbf5aa205ece1b7e41a4c3fc28602d75f 100644 --- a/src/app/components/shared/_dialogs/create-comment/create-comment.component.scss +++ b/src/app/components/shared/_dialogs/create-comment/create-comment.component.scss @@ -135,8 +135,12 @@ mat-hint { } .lang-confidence { + color: var(--white); + border: solid var(--red); + border-width: thick; + border-radius: 5px; + background-color: var(--red); animation: shake 0.5s; - color: var(--red); font-size: 16px; } diff --git a/src/app/components/shared/_dialogs/create-comment/create-comment.component.ts b/src/app/components/shared/_dialogs/create-comment/create-comment.component.ts index 206b884ccc4916093b2d93e751efaeafbd43b068..d39c798de3c1a306f8b69596cff455f17c7b1a22 100644 --- a/src/app/components/shared/_dialogs/create-comment/create-comment.component.ts +++ b/src/app/components/shared/_dialogs/create-comment/create-comment.component.ts @@ -35,6 +35,7 @@ export class CreateCommentComponent implements OnInit, OnDestroy { bodyForm = new FormControl('', [Validators.required]); isSpellchecking = false; + isSendingToSpacy = false; hasSpellcheckConfidence = true; newLang = 'auto'; @@ -110,6 +111,7 @@ export class CreateCommentComponent implements OnInit, OnDestroy { comment.creatorId = this.user.id; comment.createdFromLecturer = this.user.role === 1; comment.tag = this.selectedTag; + this.isSendingToSpacy = true; this.openSpacyDialog(comment); } } @@ -140,6 +142,7 @@ export class CreateCommentComponent implements OnInit, OnDestroy { } else { this.dialogRef.close(comment); } + this.isSendingToSpacy = false; }); } 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 c77fddc5eaf9dcc62dbeeef9872f740eb5a6b057..cd133545067017ceca5b94000c546f0910ad29f0 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 @@ -45,6 +45,7 @@ export class SpacyDialogComponent implements OnInit, AfterContentInit { ngAfterContentInit(): void { if(this.langSupported) { + this.commentBodyChecked = this.commentBodyChecked.replace(/[#*_]+/g ,''); this.evalInput(this.commentLang); } } 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 99a9210b3852d7888d784d835406831659c901bf..26d3c422be906c8d9eb8a76f9053c0a5544863cf 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 @@ -6,7 +6,7 @@ import { RoomCreatorPageComponent } from '../../../creator/room-creator-page/roo import { LanguageService } from '../../../../services/util/language.service'; import { EventService } from '../../../../services/util/event.service'; import { Router } from '@angular/router'; -import { CommentFilterOptions } from '../../../../utils/filter-options'; +import { CommentFilter } from '../../../../utils/filter-options'; import { CommentService } from '../../../../services/http/comment.service'; import { RoomService } from '../../../../services/http/room.service'; import { Comment } from '../../../../models/comment'; @@ -30,7 +30,7 @@ export class TopicCloudFilterComponent implements OnInit { continueFilter = 'continueWithCurr'; - tmpFilter : CommentFilterOptions; + tmpFilter : CommentFilter; allCommentsCount : number; allCommentsUsers : number; allCommentsKeywords : number; @@ -57,7 +57,7 @@ export class TopicCloudFilterComponent implements OnInit { ngOnInit() { this.translationService.use(localStorage.getItem('currentLang')); - this.tmpFilter = CommentFilterOptions.readFilter(); + this.tmpFilter = CommentFilter.currentFilter; localStorage.setItem("filtertmp", JSON.stringify(this.tmpFilter)); this.roomService.getRoomByShortId(this.shortId).subscribe(room => { @@ -123,26 +123,26 @@ export class TopicCloudFilterComponent implements OnInit { confirmButtonActionCallback() { return () => { - let filter : CommentFilterOptions; + let filter : CommentFilter; switch (this.continueFilter) { case 'continueWithAll': - filter = new CommentFilterOptions(); // all questions allowed + filter = new CommentFilter(); // all questions allowed break; case 'continueWithAllFromNow': - filter = CommentFilterOptions.generateFilterNow(this.tmpFilter.filterSelected); + filter = CommentFilter.generateFilterNow(this.tmpFilter.filterSelected); break; case 'continueWithCurr': - filter = JSON.parse(localStorage.getItem("filtertmp")) as CommentFilterOptions; + filter = JSON.parse(localStorage.getItem("filtertmp")) as CommentFilter; break; default: return; } - CommentFilterOptions.writeFilterStatic(filter); + CommentFilter.currentFilter = filter; this.dialogRef.close(this.router.navigateByUrl('/participant/room/' + this.shortId + '/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 f32841e4217d3322a4c5bc8461dd7e756a810f43..969f0c49b712726a76213890aa01c86c14275ba8 100644 --- a/src/app/components/shared/comment-list/comment-list.component.ts +++ b/src/app/components/shared/comment-list/comment-list.component.ts @@ -27,19 +27,11 @@ import { DeleteCommentsComponent } from '../../creator/_dialogs/delete-comments/ import { Export } from '../../../models/export'; import { BonusTokenService } from '../../../services/http/bonus-token.service'; import { ModeratorService } from '../../../services/http/moderator.service'; -import { CommentFilterOptions } from '../../../utils/filter-options'; +import { TopicCloudFilterComponent } from '../_dialogs/topic-cloud-filter/topic-cloud-filter.component'; +import { CommentFilter, Period } from '../../../utils/filter-options'; +import { isObjectBindingPattern } from 'typescript'; import { CreateCommentWrapper } from '../../../utils/CreateCommentWrapper'; -export enum Period { - FROMNOW = 'from-now', - ONEHOUR = 'time-1h', - THREEHOURS = 'time-3h', - ONEDAY = 'time-1d', - ONEWEEK = 'time-1w', - TWOWEEKS = 'time-2w', - ALL = 'time-all' -} - @Component({ selector: 'app-comment-list', templateUrl: './comment-list.component.html', @@ -261,11 +253,11 @@ export class CommentListComponent implements OnInit, OnDestroy { this.searchPlaceholder = msg; }); - this.getCurrentFilter().writeFilter(); + CommentFilter.writeStdFilter(); } - private getCurrentFilter(): CommentFilterOptions { - const filter = new CommentFilterOptions(); + private setCurrentFilter() { + const filter = new CommentFilter(); filter.filterSelected = this.currentFilter; filter.paused = this.freeze; filter.periodSet = this.period; @@ -276,7 +268,7 @@ export class CommentListComponent implements OnInit, OnDestroy { filter.timeStampNow = new Date().getTime(); } - return filter; + CommentFilter.currentFilter = filter; } ngOnDestroy() { @@ -453,7 +445,6 @@ export class CommentListComponent implements OnInit, OnDestroy { this.selectedTag = ''; this.selectedKeyword = ''; this.sortComments(this.currentSort); - CommentFilterOptions.writeFilterStatic(this.getCurrentFilter()); return; } this.filteredComments = this.commentsFilteredByTime.filter(c => { @@ -492,8 +483,6 @@ export class CommentListComponent implements OnInit, OnDestroy { }); this.hideCommentsList = true; this.sortComments(this.currentSort); - - CommentFilterOptions.writeFilterStatic(this.getCurrentFilter()); } sort(array: any[], type: string): any[] { @@ -542,9 +531,6 @@ export class CommentListComponent implements OnInit, OnDestroy { this.translateService.get('comment-list.comment-stream-stopped').subscribe(msg => { this.notificationService.show(msg); }); - - let filter = CommentFilterOptions.generateFilterUntil(this.currentFilter, this.period, new Date().getTime(), this.selectedTag, this.selectedKeyword); - filter.writeFilter(); } playCommentStream() { @@ -559,9 +545,6 @@ export class CommentListComponent implements OnInit, OnDestroy { this.translateService.get('comment-list.comment-stream-started').subscribe(msg => { this.notificationService.show(msg); }); - - const filter = this.getCurrentFilter(); - filter.writeFilter(); } subscribeCommentStream() { @@ -636,8 +619,6 @@ export class CommentListComponent implements OnInit, OnDestroy { this.commentsFilteredByTime = this.comments; } - this.getCurrentFilter().writeFilter(); - this.filterComments(this.currentFilter); this.titleService.attachTitle('(' + this.commentsFilteredByTime.length + ')'); } diff --git a/src/app/components/shared/comment/comment.component.scss b/src/app/components/shared/comment/comment.component.scss index 2f933346af8f6a1b33e24a35866f0c273593fd33..b4f6c773b849c1b862afc4a41aba2f0dc61ad03b 100644 --- a/src/app/components/shared/comment/comment.component.scss +++ b/src/app/components/shared/comment/comment.component.scss @@ -194,11 +194,12 @@ mat-card-content > :first-child { } .keywords-even { background-color: var(--alt-surface); - cursor: pointer; } .keyword-span { color: var(--on-surface) !important; opacity: 1 !important; + cursor: pointer; + width: 100%; } .keyword-icon { diff --git a/src/app/components/shared/dialog/dialog-action-buttons/dialog-action-buttons.component.html b/src/app/components/shared/dialog/dialog-action-buttons/dialog-action-buttons.component.html index 06bf0d6f8f0ce4f2a5efc5b9c067d68cdb94e280..9ae1ae502f68b18599444df4143b78f61c33e031 100644 --- a/src/app/components/shared/dialog/dialog-action-buttons/dialog-action-buttons.component.html +++ b/src/app/components/shared/dialog/dialog-action-buttons/dialog-action-buttons.component.html @@ -12,7 +12,11 @@ class="mat-flat-button {{ confirmButtonType }}-confirm-button" attr.aria-labelledby="{{ ariaPrefix + 'confirm' | translate }}" (click)="performConfirmButtonClickAction()" - ><mat-icon *ngIf="buttonIcon" style="margin-right: 5px;">{{buttonIcon}}</mat-icon>{{ buttonsLabelSection + '.' + confirmButtonLabel | translate}}</button> + ><mat-icon *ngIf="buttonIcon" style="margin-right: 5px;">{{buttonIcon}}</mat-icon>{{ buttonsLabelSection + '.' + confirmButtonLabel | translate}} + <mat-icon *ngIf="showLoadingCycle"> + <mat-spinner diameter="20"></mat-spinner> + </mat-icon> + </button> <button *ngIf="cancelButtonClickAction !== undefined" type="button" diff --git a/src/app/components/shared/dialog/dialog-action-buttons/dialog-action-buttons.component.ts b/src/app/components/shared/dialog/dialog-action-buttons/dialog-action-buttons.component.ts index 7529dadb1c988f8fdbb4ca890e6de88e22facc15..6b4af6f658edb828d083568cfc3d33fc6786b48b 100644 --- a/src/app/components/shared/dialog/dialog-action-buttons/dialog-action-buttons.component.ts +++ b/src/app/components/shared/dialog/dialog-action-buttons/dialog-action-buttons.component.ts @@ -52,12 +52,14 @@ export class DialogActionButtonsComponent implements OnInit { */ @Input() cancelButtonClickAction: (Function | undefined); - + /** * TRUE if some spacing will be rendered above the action buttons. */ @Input() spacing = true; + @Input() showLoadingCycle = false; + /** * The ARIA identifier prefix. diff --git a/src/app/components/shared/header/header.component.html b/src/app/components/shared/header/header.component.html index c72627dae7d5d85aa9cb766bcb3d2dc65d28a9ac..36be0756f437e89e319a1eacff3072594a9e1a26 100644 --- a/src/app/components/shared/header/header.component.html +++ b/src/app/components/shared/header/header.component.html @@ -17,42 +17,42 @@ </h2> - <ng-container *ngIf="room && room.questionsBlocked && !router.url.includes('/room-list/')"> + <ng-container *ngIf="room && room.closed && !router.url.includes('/room-list/')"> <mat-icon>block</mat-icon><h1>{{'header.questions-blocked'|translate}}</h1> </ng-container> - <ars-style-btn-material + <!--Topic Cloud--> + <div class="topic-cloud-btns" [ngClass]="{'noOfQuestions': deviceType === 'desktop'}" *ngIf="router.url.includes('tagcloud')" ars-flex-box> - <ars-col ars-btn-wrp + <ars-col [xp]="16" [extra]="true"> - <button ars-btn + <button mat-icon-button class="pseudo-button" matRipple matTooltip="{{'header.overview-question-tooltip' | translate}}"> - <i>comment</i> - <p style="margin-left: 0.25em;">{{commentsCountQuestions}}</p> + <mat-icon class="oldtypo-h2 comment_tag-icon">comment</mat-icon> + <span style="margin-left: 0.25em;">{{commentsCountQuestions}}</span> </button> - <button ars-btn + <button mat-icon-button class="pseudo-button" matRipple matTooltip="{{'header.overview-questioners-tooltip' | translate}}"> - <i>person</i> - <p style="margin-left: 0.25em;">{{commentsCountUsers}}</p> + <mat-icon class="oldtypo-h2 comment_tag-icon">person</mat-icon> + <span style="margin-left: 0.25em;">{{commentsCountUsers}}</span> </button> - - <button ars-btn + <button mat-icon-button class="pseudo-button" matRipple matTooltip="{{'header.overview-keywords-tooltip' | translate}}"> <mat-icon svgIcon="hashtag" class="oldtypo-h2 comment_tag-icon"></mat-icon> - <p style="margin-left: 0.25em;">{{commentsCountKeywords}}</p> + <span style="margin-left: 0.25em;">{{commentsCountKeywords}}</span> </button> </ars-col> - </ars-style-btn-material> + </div> <!--Feedback im Hörsaal--> <h2 class="oldtypo-h2" @@ -125,7 +125,7 @@ <ng-container *ngIf="router.url.endsWith('/comments')"> <button mat-menu-item - *ngIf="user && !router.url.endsWith('moderator/comments') && ((user.role > 0) || ((user.role == 0) && room && !room.questionsBlocked))" + *ngIf="user && !router.url.endsWith('moderator/comments') && ((user.role > 0) || ((user.role == 0) && room && !room.closed))" tabindex="0" (click)="navigateCreateQuestion();"> <mat-icon> @@ -163,16 +163,6 @@ <span>{{'header.tag-cloud' | translate}}</span> </button> - - <button mat-menu-item - tabindex="0" - (click)="startWorkerDialog()"> - <mat-icon>update - </mat-icon> - <span>{{'header.update-spacy-keywords' | translate}}</span> - </button> - - </ng-container> <ng-container *ngIf="router.url.includes('/participant/room/')"> </ng-container> @@ -364,7 +354,7 @@ <ng-container *ngIf="router.url.includes('/creator') || router.url.includes('/moderator')"> <button mat-menu-item (click)="blockQuestions()" - [ngClass]="{'color-warn': room && room.questionsBlocked}" + [ngClass]="{'color-warn': room && room.closed}" tabindex="0"> <mat-icon class="color-warn">block</mat-icon> <span>{{'header.block' | translate}}</span> diff --git a/src/app/components/shared/header/header.component.scss b/src/app/components/shared/header/header.component.scss index be81643b313af5a7b224d859a62e5ed864334d49..616d47238794e9ec610e9b7c3ccd752ebbe45acd 100644 --- a/src/app/components/shared/header/header.component.scss +++ b/src/app/components/shared/header/header.component.scss @@ -36,12 +36,17 @@ mat-toolbar-row { margin: 0 !important; } -ars-style-btn-material button { - &:hover, &:focus { - border: none; +.topic-cloud-btns { + > ars-col button { + margin-right: 0.75em; + + &:hover, &:focus { + border: none; + } } > * { + overflow: hidden !important; color: var(--on-surface); } } @@ -73,7 +78,7 @@ button:focus { } svg { - -webkit-filter: invert(100%); + -webkit-filter: invert(100%); /* safari 6.0 - 9.0 */ filter: invert(100%); } @@ -117,26 +122,7 @@ svg { * { background-color: transparent !important; } - *:hover { - color: var(--dialog); - background-color: var(--on-dialog) !important; - - mat-icon{ - color: var(--dialog); - background-color: var(--on-dialog) !important; - } - } } h1{ color: red; } -::ng-deep .mat-menu-item:hover .qrcode svg > path { - fill: var(--dialog); - color: var(--dialog); - background-color: var(--on-dialog) !important; - } - - ::ng-deep #cdk-overlay-0 .mat-menu-content > button:hover mat-icon{ - color: var(--dialog); - background-color: var(--on-dialog) !important; - } \ No newline at end of file diff --git a/src/app/components/shared/questionwall/question-wall/question-wall.component.ts b/src/app/components/shared/questionwall/question-wall/question-wall.component.ts index a7f95f09f38f7b7d25c48d4f13023486b0801b80..d238dce2d3f2ef7eea696b4b36893c0875d2e4d3 100644 --- a/src/app/components/shared/questionwall/question-wall/question-wall.component.ts +++ b/src/app/components/shared/questionwall/question-wall/question-wall.component.ts @@ -14,7 +14,7 @@ import { Rescale } from '../../../../models/rescale'; import { QuestionWallKeyEventSupport } from '../QuestionWallKeyEventSupport'; import { CorrectWrong } from '../../../../models/correct-wrong.enum'; import { MatSliderChange } from '@angular/material/slider'; -import { Period } from '../../comment-list/comment-list.component'; +import { Period } from '../../../../utils/filter-options'; @Component({ selector: 'app-question-wall', diff --git a/src/app/models/comment.ts b/src/app/models/comment.ts index c857181c08a6730ac351acfd3c5ecbce31b83d52..31f2711c1bb7d74934ca8e55802fd4aee2fdca20 100644 --- a/src/app/models/comment.ts +++ b/src/app/models/comment.ts @@ -1,3 +1,4 @@ +import { dashCaseToCamelCase } from '@angular/compiler/src/util'; import { CorrectWrong } from './correct-wrong.enum'; export class Comment { diff --git a/src/app/services/util/tag-cloud-data.service.ts b/src/app/services/util/tag-cloud-data.service.ts index 8d9ec90e30d238b75c59974a951da943d12e11aa..42530b1b95fa295f4dd9193bc852ebef3894f9cc 100644 --- a/src/app/services/util/tag-cloud-data.service.ts +++ b/src/app/services/util/tag-cloud-data.service.ts @@ -4,7 +4,7 @@ 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 { CommentFilter } 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'; @@ -113,7 +113,7 @@ export class TagCloudDataService { }); this.fetchData(); - if (!CommentFilterOptions.readFilter().paused) { + if (!CommentFilter.currentFilter.paused) { this._wsCommentSubscription = this._wsCommentService .getCommentStream(this._roomId).subscribe(e => this.onMessage(e)); } diff --git a/src/app/utils/filter-comments.ts b/src/app/utils/filter-comments.ts index 6486f9b3537fbbcfa714b27214dfc7a3cc122114..83943523692972143366b764831dec1df7f5a1e2 100644 --- a/src/app/utils/filter-comments.ts +++ b/src/app/utils/filter-comments.ts @@ -1,11 +1,10 @@ -import { Period } from '../components/shared/comment-list/comment-list.component'; import { Comment } from '../models/comment'; import { CorrectWrong } from '../models/correct-wrong.enum'; -import { CommentFilterOptions, FilterNames } from './filter-options'; +import { CommentFilter, FilterNames, Period } from './filter-options'; export class CommentFilterUtils { - private static checkPeriod(com : Comment, filter : CommentFilterOptions) : boolean { + private static checkPeriod(com : Comment, filter : CommentFilter) : boolean { /* Filter by Period */ const currentTime = new Date(); const hourInSeconds = 3600000; @@ -48,7 +47,7 @@ export class CommentFilterUtils { return commentTime > (currentTime.getTime() - periodInSeconds); } - private static checkFilters(com : Comment, filter : CommentFilterOptions) : boolean { + private static checkFilters(com : Comment, filter : CommentFilter) : boolean { if (filter.filterSelected) { // no filters => return true switch (filter.filterSelected) { case FilterNames.correct: @@ -79,10 +78,8 @@ export class CommentFilterUtils { return true; } - - public static checkComment(com : Comment) : boolean { - let filter = CommentFilterOptions.readFilter(); - return (this.checkPeriod(com, filter) && this.checkFilters(com, filter)); + + public static checkComment(com : Comment, filter : CommentFilter = CommentFilter.currentFilter) : boolean { + return (this.checkPeriod(com, filter) && this.checkFilters(com, filter)); } - } \ No newline at end of file diff --git a/src/app/utils/filter-options.ts b/src/app/utils/filter-options.ts index e00ed0f05ea143ef9ab39fb65c74e4aafeec6f73..c0203f093a26d345fc8ed3e8dc334a86bb715652 100644 --- a/src/app/utils/filter-options.ts +++ b/src/app/utils/filter-options.ts @@ -1,6 +1,3 @@ -import { Period } from "../components/shared/comment-list/comment-list.component"; -import { CommentFilterUtils } from "./filter-comments"; - export const enum FilterNames { read = 'read', unread = 'unread', @@ -12,40 +9,53 @@ export const enum FilterNames { unanswered = 'unanswered' }; -export class CommentFilterOptions { - filterSelected : string; - keywordSelected : string; - tagSelected : string; - - paused: boolean; - timeStampUntil : number; - - periodSet : Period; - timeStampNow : number; - - constructor() { - this.filterSelected = ''; - this.keywordSelected = ''; - this.tagSelected = ''; - this.paused = false; - this.periodSet = Period.ALL; +export enum Period { + FROMNOW = 'from-now', + ONEHOUR = 'time-1h', + THREEHOURS = 'time-3h', + ONEDAY = 'time-1d', + ONEWEEK = 'time-1w', + TWOWEEKS = 'time-2w', + ALL = 'time-all' +} + +export class CommentFilter { + filterSelected : string = ''; + keywordSelected : string = ''; + tagSelected : string = ''; + + paused: boolean = false; + timeStampUntil : number = 0; + + periodSet : Period = Period.TWOWEEKS; + timeStampNow : number = 0; + + constructor(obj?: any) { + if (obj) { + this.filterSelected = obj.filterSelected; + this.keywordSelected = obj.keywordSelected; + this.tagSelected = obj.tagSelected; + this.paused = obj.paused; + this.timeStampUntil = obj.timeStampUntil; + this.periodSet = obj.periodSet; + this.timeStampNow = obj.timeStampNow; + } } - public writeFilter() { - localStorage.setItem("filter", JSON.stringify(this)); + public static set currentFilter(filter : CommentFilter) { + localStorage.setItem("filter", JSON.stringify(filter)); } - - public static writeFilterStatic(filter : CommentFilterOptions) { - localStorage.setItem("filter", JSON.stringify(filter)); + public static get currentFilter() : CommentFilter { + return new CommentFilter(JSON.parse(localStorage.getItem("filter"))); } - public static readFilter() : CommentFilterOptions { - return JSON.parse(localStorage.getItem("filter")); + public static writeStdFilter() { + this.currentFilter = new CommentFilter(); } - public static generateFilterNow(filterSelected : string) : CommentFilterOptions { - let filter = new CommentFilterOptions(); + public static generateFilterNow(filterSelected : string) : CommentFilter { + let filter = new CommentFilter(); filter.filterSelected = filterSelected; filter.paused = false; @@ -59,8 +69,8 @@ export class CommentFilterOptions { return filter; } - public static generateFilterUntil(filterSelected : string, periodSelected : Period, untilTime : number, tagSelected : string, keywordSelected : string) : CommentFilterOptions { - let filter = new CommentFilterOptions(); + public static generateFilterUntil(filterSelected : string, periodSelected : Period, untilTime : number, tagSelected : string, keywordSelected : string) : CommentFilter { + let filter = new CommentFilter(); filter.filterSelected = filterSelected; @@ -74,5 +84,4 @@ export class CommentFilterOptions { return filter; } - } \ No newline at end of file