diff --git a/src/app/components/creator/_dialogs/bonus-token/bonus-token.component.html b/src/app/components/creator/_dialogs/bonus-token/bonus-token.component.html index 6749a9d0b870240189bd757523f7959bcd1fdc8c..c2a0e4ddfb09780b81cddec0e1005495a6d66241 100644 --- a/src/app/components/creator/_dialogs/bonus-token/bonus-token.component.html +++ b/src/app/components/creator/_dialogs/bonus-token/bonus-token.component.html @@ -2,24 +2,30 @@ <h2 class="oldtypo-h2">{{'room-page.bonus-token-header' | translate }}</h2> <h3 class="oldtypo-h3">»{{room.name}}«</h3> <h3 class="oldtypo-h3">{{ 'room-page.session-id' | translate}}: {{ room.shortId }}</h3> - + <mat-divider></mat-divider> <div *ngIf="bonusTokens.length >= 1"> - <div fxLayout="row" *ngFor="let bonusToken of bonusTokens; index as i" class="tokens"> - <p tabindex="0"> - {{bonusToken.token}} - </p> - <span class="fill-remaining-space"></span> - <p> - {{bonusToken.timestamp | date: lang === 'de' ? 'dd.MM.yy' : ' M/d/yy'}} - </p> - <span class="fill-remaining-space"></span> - <button mat-icon-button (click)="navToComment(bonusToken.commentId)"> - <mat-icon matTooltip="{{ 'room-page.nav-to-comment' | translate }}">comment</mat-icon> - </button> - <button mat-icon-button (click)="openDeleteSingleBonusDialog(bonusToken.userId, bonusToken.commentId, i)"> - <mat-icon matTooltip="{{ 'room-page.delete-token' | translate }}" class="delete-icon">close</mat-icon> - </button> - </div> + <p> + <mat-form-field appearance="outline"> + <input matInput (keyup)="inputChanged($event)"> + <mat-hint>{{ 'room-page.hint' | translate}}</mat-hint> + </mat-form-field> + </p> + <mat-list> + <mat-list-item *ngFor="let bonusToken of bonusTokens; let index = index"> + <p tabindex="0"> + {{ bonusToken.token }} + </p> + <p> + {{ bonusToken.timestamp | date: lang === 'de' ? 'dd.MM.yy' : ' M/d/yy'}} + </p> + <button mat-icon-button (click)="navToComment(bonusToken.commentId)"> + <mat-icon matTooltip="{{ 'room-page.nav-to-comment' | translate }}">comment</mat-icon> + </button> + <button mat-icon-button (click)="openDeleteSingleBonusDialog(bonusToken.userId, bonusToken.commentId, index)"> + <mat-icon matTooltip="{{ 'room-page.delete-token' | translate }}" class="delete-icon">close</mat-icon> + </button> + </mat-list-item> + </mat-list> </div> <div *ngIf="bonusTokens.length === 0"> <p>{{'room-page.no-bonus' | translate }} @@ -33,7 +39,7 @@ </div> </div> - <app-dialog-action-buttons - buttonsLabelSection="content" - [cancelButtonClickAction]="buildDeclineActionCallback()"> - </app-dialog-action-buttons> +<app-dialog-action-buttons + buttonsLabelSection="content" + [cancelButtonClickAction]="buildDeclineActionCallback()"> +</app-dialog-action-buttons> diff --git a/src/app/components/creator/_dialogs/bonus-token/bonus-token.component.ts b/src/app/components/creator/_dialogs/bonus-token/bonus-token.component.ts index 7d92e32a37db8560b0d0fcb02678196f6ad6a3c3..10885592bbd733d41bf94ea12938efba87417401 100644 --- a/src/app/components/creator/_dialogs/bonus-token/bonus-token.component.ts +++ b/src/app/components/creator/_dialogs/bonus-token/bonus-token.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit } from '@angular/core'; +import {Component, OnDestroy, OnInit, QueryList, ViewChild, ViewChildren} from '@angular/core'; import { BonusTokenService } from '../../../../services/http/bonus-token.service'; import { BonusToken } from '../../../../models/bonus-token'; import { Room } from '../../../../models/room'; @@ -8,16 +8,22 @@ import { BonusDeleteComponent } from '../bonus-delete/bonus-delete.component'; import { NotificationService } from '../../../../services/util/notification.service'; import { TranslateService } from '@ngx-translate/core'; import { Router } from '@angular/router'; +import { Subject, Subscription } from 'rxjs'; +import { debounceTime } from 'rxjs/operators'; +import { isNumeric } from 'rxjs/internal-compatibility'; @Component({ selector: 'app-bonus-token', templateUrl: './bonus-token.component.html', styleUrls: ['./bonus-token.component.scss'] }) -export class BonusTokenComponent implements OnInit { +export class BonusTokenComponent implements OnInit, OnDestroy { room: Room; bonusTokens: BonusToken[] = []; lang: string; + private modelChanged: Subject<string> = new Subject<string>(); + private subscription: Subscription; + private debounceTime = 500; constructor(private bonusTokenService: BonusTokenService, public dialog: MatDialog, @@ -29,11 +35,16 @@ export class BonusTokenComponent implements OnInit { ngOnInit() { this.bonusTokenService.getTokensByRoomId(this.room.id).subscribe(list => { - this.bonusTokens = list.sort((a, b) => { - return (a.token > b.token) ? 1 : -1; - }); + this.bonusTokens = list.sort((a, b) => (a.token > b.token) ? 1 : -1); }); this.lang = localStorage.getItem('currentLang'); + this.subscription = this.modelChanged + .pipe( + debounceTime(this.debounceTime), + ) + .subscribe(value => { + this.inputToken(value); + }); } openDeleteSingleBonusDialog(userId: string, commentId: string, index: number): void { @@ -95,4 +106,38 @@ export class BonusTokenComponent implements OnInit { buildDeclineActionCallback(): () => void { return () => this.dialogRef.close(); } + + inputToken(input: any) { + const index = this.validateTokenInput(input); + if(index !== -1) { + this.translationService.get('token-validator.valid').subscribe(msg => { + this.notificationService.show(msg); + }); + } else { + this.translationService.get('token-validator.invalid').subscribe(msg => { + this.notificationService.show(msg); + }); + } + } + + validateTokenInput(input: any) { + let ind = -1; + if(input.length === 8 && isNumeric(input)) { + this.bonusTokens.map((c, index) => { + if (c.token === input) { + ind = index; + } + }); + } + return ind; + } + + inputChanged(event: any) { + event.cancelBubble = true; + this.modelChanged.next(event.target.value); + } + + ngOnDestroy(): void { + this.subscription.unsubscribe(); + } } diff --git a/src/assets/i18n/creator/de.json b/src/assets/i18n/creator/de.json index a7efe0a8f4cf58fa1b5b2ffcfe7b057a0f212f51..560de699476a993e72fdecac4e29dcb453204cf4 100644 --- a/src/assets/i18n/creator/de.json +++ b/src/assets/i18n/creator/de.json @@ -341,7 +341,8 @@ "only-specific-language-will-be-filtered": "Nur Vulgärausdrücke in der Sprache der Frage werden gefiltert", "partial-words-will-be-filtered": "Vulgäre Teilwörter werden auch gefiltert", "keyword-from-spacy": "Stichwort von spaCy", - "keyword-from-questioner": "Stichwort vom Fragensteller" + "keyword-from-questioner": "Stichwort vom Fragensteller", + "hint": "Nach Token filtern" }, "session": { "a11y-description": "Gib eine Beschreibung für die Sitzung ein.", @@ -509,5 +510,9 @@ "manual-weight-number": "Anzahl Themen beschränken", "manual-weight-number-tooltip": "Anzahl Themen der Häufigkeitsgruppe", "manual-weight-number-note": "Begrenzt die Anzahl Themen einer Häufigkeitsgruppe auf den eingestellten Wert" + }, + "token-validator": { + "valid": "VALID", + "invalid": "INVALID" } } diff --git a/src/assets/i18n/creator/en.json b/src/assets/i18n/creator/en.json index 059c021ef2c76597d0ceecc6f8542c0f1c0e632a..f329fd474a989749ac3e4a264b07a88611c17898 100644 --- a/src/assets/i18n/creator/en.json +++ b/src/assets/i18n/creator/en.json @@ -340,7 +340,8 @@ "partial-words-filter": "Filter partial words", "words-will-be-overwritten": "Profane words will be overwritten with '***'", "only-specific-language-will-be-filtered": "Only the language of the question will be filtered", - "partial-words-will-be-filtered": "Profane partial words will be also filtered" + "partial-words-will-be-filtered": "Profane partial words will be also filtered", + "hint": "Filter by token" }, "session": { "a11y-description": "Enter a description of the session", @@ -507,5 +508,9 @@ "manual-weight-number": "Set quantity", "manual-weight-number-tooltip": "Quantity Limitation of this weight class", "manual-weight-number-note": "Limits the respective weight class to a self-defined value" + }, + "token-validator": { + "valid": "VALID", + "invalid": "INVALID" } }