From d5fade4920d435a91988237a74fed29f5ab0b3f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Mau=C3=9F?= <lukas.mauss@mni.thm.de> Date: Mon, 24 Feb 2020 21:31:43 +0100 Subject: [PATCH] Check if auto option is empty and remove duplicated rooms from list --- .../user-bonus-token.component.html | 5 +- .../user-bonus-token.component.ts | 55 +++++++++++++------ src/assets/i18n/home/de.json | 3 +- src/assets/i18n/home/en.json | 3 +- 4 files changed, 46 insertions(+), 20 deletions(-) diff --git a/src/app/components/participant/_dialogs/user-bonus-token/user-bonus-token.component.html b/src/app/components/participant/_dialogs/user-bonus-token/user-bonus-token.component.html index d0a2061b1..3de4f5410 100644 --- a/src/app/components/participant/_dialogs/user-bonus-token/user-bonus-token.component.html +++ b/src/app/components/participant/_dialogs/user-bonus-token/user-bonus-token.component.html @@ -14,8 +14,9 @@ <mat-label>{{ 'user-bonus-token.choose-session' | translate }}</mat-label> <input type="text" matInput [matAutocomplete]="auto"> <mat-autocomplete #auto="matAutocomplete"> - <mat-option *ngFor="let bt of bonusTokensMixin" [value]="bt.roomName" (onSelectionChange)="setCurrentRoom(bt)"> - {{bt.roomName}} + <mat-option *ngFor="let room of rooms" [value]="room.name" + (onSelectionChange)="setCurrentRoom($event, room)"> + {{room.name}} </mat-option> </mat-autocomplete> </mat-form-field> diff --git a/src/app/components/participant/_dialogs/user-bonus-token/user-bonus-token.component.ts b/src/app/components/participant/_dialogs/user-bonus-token/user-bonus-token.component.ts index 19fdfedc4..1f0ad47d4 100644 --- a/src/app/components/participant/_dialogs/user-bonus-token/user-bonus-token.component.ts +++ b/src/app/components/participant/_dialogs/user-bonus-token/user-bonus-token.component.ts @@ -3,9 +3,20 @@ import { BonusTokenService } from '../../../../services/http/bonus-token.service import { RoomService } from '../../../../services/http/room.service'; import { BonusToken } from '../../../../models/bonus-token'; import { BonusTokenRoomMixin } from '../../../../models/bonus-token-room-mixin'; -import { MatDialogRef } from '@angular/material'; +import { MatDialogRef, MatOptionSelectionChange } from '@angular/material'; import { Router } from '@angular/router'; import { TranslateService } from '@ngx-translate/core'; +import { NotificationService } from '../../../../services/util/notification.service'; + +export class MinRoom { + name: string; + id: string; + + constructor(name: string, id: string) { + this.name = name; + this.id = id; + } +} @Component({ selector: 'app-user-bonus-token', @@ -16,14 +27,16 @@ export class UserBonusTokenComponent implements OnInit { userId: string; bonusTokens: BonusToken[] = []; bonusTokensMixin: BonusTokenRoomMixin[] = []; - currentBT: BonusTokenRoomMixin; + currentRoom: MinRoom; + rooms: MinRoom[] = []; constructor( private bonusTokenService: BonusTokenService, private roomService: RoomService, private dialogRef: MatDialogRef<UserBonusTokenComponent>, protected router: Router, - public translationService: TranslateService + private translationService: TranslateService, + private notificationService: NotificationService ) { } @@ -38,6 +51,9 @@ export class UserBonusTokenComponent implements OnInit { btm.roomShortId = room.shortId; btm.roomName = room.name; this.bonusTokensMixin.push(btm); + if (!this.rooms.some(r => r.id === room.shortId)) { + this.rooms.push(new MinRoom(room.name, room.shortId)); + } }); } }); @@ -59,22 +75,29 @@ export class UserBonusTokenComponent implements OnInit { return tokens; } - setCurrentRoom(bt: BonusTokenRoomMixin) { - this.currentBT = bt; + setCurrentRoom(event: MatOptionSelectionChange, room: MinRoom) { + if (event.source.selected) { + this.currentRoom = room; + } } openMail() { - const sessionName = this.currentBT.roomName; - const sessionId = this.currentBT.roomShortId; - const translationList = ['user-bonus-token.mail-subject', 'user-bonus-token.mail-body-1', 'user-bonus-token.mail-body-2', - 'user-bonus-token.mail-body-3', 'user-bonus-token.mail-body-4']; - let mailText: string; - this.translationService.get(translationList).subscribe(msgs => { - console.log(msgs); - mailText = 'mailto:?subject=' + msgs[translationList[0]] + sessionName + '%C2%AB&body=' + msgs[translationList[1]] + sessionName - + msgs[translationList[2]] + sessionId + msgs[translationList[3]] + this.getTokensByRoom(sessionId) + msgs[translationList[4]]; - window.location.href = mailText; - }); + if (this.currentRoom) { + const sessionName = this.currentRoom.name; + const sessionId = this.currentRoom.id; + const translationList = ['user-bonus-token.mail-subject', 'user-bonus-token.mail-body-1', 'user-bonus-token.mail-body-2', + 'user-bonus-token.mail-body-3', 'user-bonus-token.mail-body-4']; + let mailText: string; + this.translationService.get(translationList).subscribe(msgs => { + mailText = 'mailto:?subject=' + msgs[translationList[0]] + sessionName + '%C2%AB&body=' + msgs[translationList[1]] + sessionName + + msgs[translationList[2]] + sessionId + msgs[translationList[3]] + this.getTokensByRoom(sessionId) + msgs[translationList[4]]; + window.location.href = mailText; + }); + } else { + this.translationService.get('user-bonus-token.please-choose').subscribe(msg => { + this.notificationService.show(msg); + }); + } } /** diff --git a/src/assets/i18n/home/de.json b/src/assets/i18n/home/de.json index fd1bff65d..8c74132d9 100644 --- a/src/assets/i18n/home/de.json +++ b/src/assets/i18n/home/de.json @@ -247,7 +247,8 @@ "mail-body-2": "%C2%AB%20mit%20dem%20Sitzungs-Code%20%C2%BB", "mail-body-3": "%C2%AB%20die%20folgenden%20Tokens%20erhalten%3A%0D%0A%0D%0A", "mail-body-4": "%0D%0A%0D%0AIch%20bitte%20um%20die%20Einl%C3%B6sung%20in%20Bonuspunkte.%0D%0A%0D%0ADanke%20f%C3%BCr%20%C2%BBfrag.jetzt%C2%AB!%0D%0A%0D%0A---", - "choose-session": "Wähle eine Sitzung aus" + "choose-session": "Wähle eine Sitzung aus", + "please-choose": "Bitte wähle zuerst eine Sitzung aus!" }, "qr-dialog": { "session": "Sitzung" diff --git a/src/assets/i18n/home/en.json b/src/assets/i18n/home/en.json index 575c98128..683c987cf 100644 --- a/src/assets/i18n/home/en.json +++ b/src/assets/i18n/home/en.json @@ -248,7 +248,8 @@ "mail-body-2": "%C2%AB%20with%20the%20session%20code%20%C2%BB", "mail-body-3": "%C2%AB%3A%0D%0A%0D%0A", "mail-body-4": "%0D%0A%0D%0AI%20ask%20for%20the%20redemption%20in%20bonus%20points.%0D%0A%0D%0AThanks%20for%20%C2%BBfrag.jetzt%C2%AB!%0D%0A%0D%0A---", - "choose-session": "Choose a session" + "choose-session": "Choose a session", + "please-choose": "Please select a session first!" }, "qr-dialog": { "session": "Session" -- GitLab