From 8b4a2622b472840cb4a31742396ef9fcd9c499ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Mau=C3=9F?= <lukas.mauss@mni.thm.de> Date: Thu, 10 Oct 2019 18:38:46 +0200 Subject: [PATCH] Cleanup bonus functions and export --- .../bonus-token/bonus-token.component.html | 17 +++++-- .../bonus-token/bonus-token.component.ts | 14 +++-- .../comment-settings.component.ts | 51 +++++++++---------- .../user-bonus-token.component.html | 19 +++++-- .../user-bonus-token.component.ts | 14 +++-- src/app/components/shared/shared.module.ts | 3 +- src/assets/i18n/creator/de.json | 4 +- src/assets/i18n/creator/en.json | 4 +- src/assets/i18n/home/de.json | 4 +- src/assets/i18n/home/en.json | 5 +- src/assets/i18n/participant/de.json | 4 +- src/assets/i18n/participant/en.json | 4 +- 12 files changed, 92 insertions(+), 51 deletions(-) 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 0bf87b73c..93941b81e 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 @@ -1,9 +1,18 @@ <div mat-dialog-content> <h1>{{'room-page.bonus-token-header' | translate }}</h1> <mat-divider></mat-divider> - <div fxLayout="row" *ngFor="let bonusToken of bonusTokens"> - <h2> - {{bonusToken.token}} - </h2> + <div *ngIf="bonusTokens.length >= 1"> + <div fxLayout="row" *ngFor="let bonusToken of bonusTokens"> + <h2> + {{bonusToken.token}} + </h2> + </div> </div> + <div *ngIf="bonusTokens.length === 0"> + <h3>{{'room-page.no-bonus' | translate }}</h3> + </div> + <app-dialog-action-buttons + buttonsLabelSection="content" + [cancelButtonClickAction]="buildDeclineActionCallback()"> + </app-dialog-action-buttons> </div> 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 f270f68dc..1b2f03e2d 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,6 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { BonusTokenService } from '../../../../services/http/bonus-token.service'; import { BonusToken } from '../../../../models/bonus-token'; +import { MatDialogRef } from '@angular/material'; @Component({ selector: 'app-bonus-token', @@ -11,10 +12,8 @@ export class BonusTokenComponent implements OnInit { roomId: string; bonusTokens: BonusToken[] = []; - constructor( - private bonusTokenService: BonusTokenService - ) { - + constructor(private bonusTokenService: BonusTokenService, + private dialogRef: MatDialogRef<BonusTokenComponent>) { } ngOnInit() { @@ -22,4 +21,11 @@ export class BonusTokenComponent implements OnInit { this.bonusTokens = list; }); } + + /** + * Returns a lambda which closes the dialog on call. + */ + buildDeclineActionCallback(): () => void { + return () => this.dialogRef.close(); + } } diff --git a/src/app/components/creator/_dialogs/comment-settings/comment-settings.component.ts b/src/app/components/creator/_dialogs/comment-settings/comment-settings.component.ts index 34539d348..9aa54b109 100644 --- a/src/app/components/creator/_dialogs/comment-settings/comment-settings.component.ts +++ b/src/app/components/creator/_dialogs/comment-settings/comment-settings.component.ts @@ -100,7 +100,7 @@ export class CommentSettingsComponent implements OnInit { this.comments = comments.map(comment => { const commentWithToken: CommentBonusTokenMixin = <CommentBonusTokenMixin>comment; for (const bt of list) { - if (commentWithToken.creatorId === bt.userId) { + if (commentWithToken.creatorId === bt.userId && comment.favorite) { commentWithToken.bonusToken = bt.token; } } @@ -109,32 +109,31 @@ export class CommentSettingsComponent implements OnInit { const exportComments = JSON.parse(JSON.stringify(this.comments)); let csv: string; let valueFields = ''; - const keyFields = [ - 'Frage', - 'Zeitstempel', - 'Präsentiert', - 'Favorit', - 'Richtig/Falsch', - 'Zugestellt', - 'Score', - 'Bonus Token', - '\r\n' - ]; - exportComments.forEach(element => { - element.body = '"' + element.body.replace(/[\r\n]/g, ' ').replace(/ +/g, ' ').replace(/"/g, '""') + '"'; - valueFields += Object.values(element).slice(3, 4) + delimiter; - let time; - time = Object.values(element).slice(4, 5); - valueFields += time[0].slice(0, 10) + '-' + time[0].slice(11, 16) + delimiter; - valueFields += Object.values(element).slice(5, 10).join(delimiter) + '\r\n'; + const fieldNames = ['room-page.question', 'room-page.timestamp', 'room-page.presented', + 'room-page.favorite', 'room-page.correct/wrong', 'room-page.score', 'room-page.token']; + let keyFields; + this.translationService.get(fieldNames).subscribe(msgs => { + keyFields = [msgs[fieldNames[0]], msgs[fieldNames[1]], msgs[fieldNames[2]], msgs[fieldNames[3]], + msgs[fieldNames[4]], msgs[fieldNames[5]], msgs[fieldNames[6]], '\r\n']; + + exportComments.forEach(element => { + console.log(Object.values(element)); + element.body = '"' + element.body.replace(/[\r\n]/g, ' ').replace(/ +/g, ' ').replace(/"/g, '""') + '"'; + valueFields += Object.values(element).slice(3, 4) + delimiter; + let time; + time = Object.values(element).slice(4, 5); + valueFields += time[0].slice(0, 10) + '-' + time[0].slice(11, 16) + delimiter; + valueFields += Object.values(element).slice(5, 8) + delimiter; + valueFields += Object.values(element).slice(9, 11).join(delimiter) + '\r\n'; + }); + csv = keyFields + valueFields; + const myBlob = new Blob([csv], { type: 'text/csv' }); + const link = document.createElement('a'); + const fileName = 'comments_' + date + '.csv'; + link.setAttribute('download', fileName); + link.href = window.URL.createObjectURL(myBlob); + link.click(); }); - csv = keyFields + valueFields; - const myBlob = new Blob([csv], { type: 'text/csv' }); - const link = document.createElement('a'); - const fileName = 'comments_' + date + '.csv'; - link.setAttribute('download', fileName); - link.href = window.URL.createObjectURL(myBlob); - link.click(); }); }); } diff --git a/src/app/components/shared/_dialogs/user-bonus-token/user-bonus-token.component.html b/src/app/components/shared/_dialogs/user-bonus-token/user-bonus-token.component.html index 6584f5b1d..8a2f81a7a 100644 --- a/src/app/components/shared/_dialogs/user-bonus-token/user-bonus-token.component.html +++ b/src/app/components/shared/_dialogs/user-bonus-token/user-bonus-token.component.html @@ -1,9 +1,18 @@ <div mat-dialog-content> - <h1>{{'user-bonus-token-dialog.header' | translate }}</h1> + <h1>{{'header.bonus-token' | translate }}</h1> <mat-divider></mat-divider> - <div fxLayout="row" *ngFor="let bonusToken of bonusTokens"> - <h2> - {{bonusToken.token}} - </h2> + <div *ngIf="bonusTokens.length >= 1"> + <div fxLayout="row" *ngFor="let bonusToken of bonusTokens"> + <h2> + {{bonusToken.token}} + </h2> + </div> </div> + <div *ngIf="bonusTokens.length === 0"> + <h3>{{'header.no-bonus' | translate }}</h3> + </div> + <app-dialog-action-buttons + buttonsLabelSection="introduction" + [cancelButtonClickAction]="buildDeclineActionCallback()"> + </app-dialog-action-buttons> </div> diff --git a/src/app/components/shared/_dialogs/user-bonus-token/user-bonus-token.component.ts b/src/app/components/shared/_dialogs/user-bonus-token/user-bonus-token.component.ts index e9cab7ee7..42c2274c5 100644 --- a/src/app/components/shared/_dialogs/user-bonus-token/user-bonus-token.component.ts +++ b/src/app/components/shared/_dialogs/user-bonus-token/user-bonus-token.component.ts @@ -1,6 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { BonusTokenService } from '../../../../services/http/bonus-token.service'; import { BonusToken } from '../../../../models/bonus-token'; +import { MatDialogRef } from '@angular/material'; @Component({ selector: 'app-user-bonus-token', @@ -11,10 +12,8 @@ export class UserBonusTokenComponent implements OnInit { userId: string; bonusTokens: BonusToken[] = []; - constructor( - private bonusTokenService: BonusTokenService - ) { - + constructor(private bonusTokenService: BonusTokenService, + private dialogRef: MatDialogRef<UserBonusTokenComponent>) { } ngOnInit() { @@ -22,4 +21,11 @@ export class UserBonusTokenComponent implements OnInit { this.bonusTokens = list; }); } + + /** + * Returns a lambda which closes the dialog on call. + */ + buildDeclineActionCallback(): () => void { + return () => this.dialogRef.close(); + } } diff --git a/src/app/components/shared/shared.module.ts b/src/app/components/shared/shared.module.ts index b35a47dba..63a03ad8d 100644 --- a/src/app/components/shared/shared.module.ts +++ b/src/app/components/shared/shared.module.ts @@ -82,7 +82,8 @@ import { MatRippleModule } from '@angular/material'; CreateCommentComponent, PresentCommentComponent, CommentComponent, - DialogActionButtonsComponent + DialogActionButtonsComponent, + UserBonusTokenComponent ], entryComponents: [ RoomCreateComponent, diff --git a/src/assets/i18n/creator/de.json b/src/assets/i18n/creator/de.json index c166a823f..20ad4e57b 100644 --- a/src/assets/i18n/creator/de.json +++ b/src/assets/i18n/creator/de.json @@ -163,6 +163,7 @@ "answer-statistics": "Statistiken", "bonus-token": "Tokens für Bonuspunkte", "bonus-token-header": "Tokens für Bonuspunkte", + "no-bonus": "Es wurden noch keine Bonuspunkte vergeben.", "cancel": "Abbrechen", "cancel-description": "Abbrechen", "changes-successful": "Änderungen gespeichert.", @@ -210,7 +211,8 @@ "presented": "Präsentiert", "correct/wrong": "Richtig/Falsch", "score": "Score", - "timestamp": "Zeitstempel" + "timestamp": "Zeitstempel", + "token": "Bonus-Token" }, "session": { "a11y-description": "Gib eine Beschreibung für die Sitzung ein.", diff --git a/src/assets/i18n/creator/en.json b/src/assets/i18n/creator/en.json index 19cc925a3..224fa8184 100644 --- a/src/assets/i18n/creator/en.json +++ b/src/assets/i18n/creator/en.json @@ -164,6 +164,7 @@ "answer-statistics": "Statistics", "bonus-token": "Tokens for bonus points", "bonus-token-header": "Tokens for bonus points", + "no-bonus": "No bonus points have been given yet.", "cancel": "Cancel", "cancel-description": "Cancel", "changes-successful": "Successfully updated.", @@ -211,7 +212,8 @@ "presented": "Presented", "correct/wrong": "Correct/Wrong", "score": "Score", - "timestamp": "Timestamp" + "timestamp": "Timestamp", + "token": "Bonus token" }, "session": { "a11y-description": "Enter a description for the session", diff --git a/src/assets/i18n/home/de.json b/src/assets/i18n/home/de.json index 4fe7a1d4b..d31f78611 100644 --- a/src/assets/i18n/home/de.json +++ b/src/assets/i18n/home/de.json @@ -60,7 +60,9 @@ "really-delete-account": "Willst du dein Konto mit allen Sitzungen unwiderruflich löschen?", "sure": "Bist du sicher?", "user-bonus-token": "Zu deinen Bonus Tokens", - "visited-sessions": "Besuchte Sitzungen" + "visited-sessions": "Besuchte Sitzungen", + "bonus-token": "Tokens für Bonuspunkte", + "no-bonus": "Noch keine Bonuspunkte erhalten." }, "help": { "cancel": "Schließen", diff --git a/src/assets/i18n/home/en.json b/src/assets/i18n/home/en.json index 7c38513ef..db38548be 100644 --- a/src/assets/i18n/home/en.json +++ b/src/assets/i18n/home/en.json @@ -61,7 +61,9 @@ "really-delete-account": "Do you really want to irrevocably delete your account with the associated sessions?", "sure": "Are you sure?", "user-bonus-token": "See your bonus tokens", - "visited-sessions": "Visited sessions" + "visited-sessions": "Visited sessions", + "bonus-token": "Tokens for bonus points", + "no-bonus": "No bonus points earned yet." }, "help": { "cancel": "Close", @@ -71,7 +73,6 @@ "home-page": { "accessibility-create": "Create a new session", "accessibility-join-button": "Enter the session with the specified session key.", - "accessibility-join-input": "Here you can enter the session key of the session you want to join.", "create-session": "New session", "created-1": "Session '", "created-2": "' successfully created", diff --git a/src/assets/i18n/participant/de.json b/src/assets/i18n/participant/de.json index b94578f76..0846e41c1 100644 --- a/src/assets/i18n/participant/de.json +++ b/src/assets/i18n/participant/de.json @@ -107,7 +107,9 @@ "learn": "Lernen", "live-announcer": "Du befindest dich jetzt in der Sitzung. Um Informationen zu Tastenkombinationen zu erhalten drücke jetzt die Enter-Taste oder rufe die Ansage zu einem späteren Zeitpunkt mit der Escape-Taste auf.", "live-feedback": "Live Feedback", - "session-id": "Code" + "session-id": "Code", + "bonus-token": "Tokens für Bonuspunkte", + "bonus-token-header": "Tokens für Bonuspunkte" }, "statistic": { "abstentions": "Enthaltungen", diff --git a/src/assets/i18n/participant/en.json b/src/assets/i18n/participant/en.json index cd14fcfe3..7a82927e8 100644 --- a/src/assets/i18n/participant/en.json +++ b/src/assets/i18n/participant/en.json @@ -106,7 +106,9 @@ "learn": "Learn", "live-announcer": "You're in the session now. To get information about key combinations press the Enter key or call the announcement later with the Escape key.", "live-feedback": "Live feedback", - "session-id": "Key" + "session-id": "Key", + "bonus-token": "Tokens for bonus points", + "bonus-token-header": "Tokens for bonus points" }, "statistic": { "abstentions": "Abstentions", -- GitLab