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 d0a2061b1db17c71f59ef3b3334a3e4312e8785d..3de4f5410946ee82d7427033ba448b672bee041c 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 19fdfedc4324c6a8b3e84d90f03fc9cf7cd5d2f3..1f0ad47d43fb68360cbef49a3b5c397816befdf4 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 fd1bff65d0aa8deae0a7e29f9499ff45213598b6..8c74132d9bd19ee96eb2d1fdabbe2c9dda974489 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 575c9812863d66f4b4d30373ccd91e6655a739dc..683c987cff4d208506f9ca8d094903cbfa560afb 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"