From c3eecc44f12e3901366f7951ce958015cf3b1246 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lukas=20Mau=C3=9F?= <lukas.mauss@mni.thm.de>
Date: Wed, 16 Oct 2019 18:30:56 +0200
Subject: [PATCH] Resolve "Bonus questions should not be able to be deleted"

---
 .../comment-settings.component.ts                |  1 +
 .../delete-comments.component.html               | 12 +++++++++---
 .../delete-comments/delete-comments.component.ts | 16 +++++++++++++---
 .../shared/comment/comment.component.html        |  2 +-
 src/assets/i18n/creator/de.json                  |  4 +++-
 src/assets/i18n/creator/en.json                  |  4 +++-
 6 files changed, 30 insertions(+), 9 deletions(-)

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 fa16a53ce..27920ced0 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
@@ -78,6 +78,7 @@ export class CommentSettingsComponent implements OnInit {
     const dialogRef = this.dialog.open(DeleteCommentsComponent, {
       width: '400px'
     });
+    dialogRef.componentInstance.roomId = this.roomId;
     dialogRef.afterClosed()
       .subscribe(result => {
         if (result === 'delete') {
diff --git a/src/app/components/creator/_dialogs/delete-comments/delete-comments.component.html b/src/app/components/creator/_dialogs/delete-comments/delete-comments.component.html
index a1dd80b05..2241fd6db 100644
--- a/src/app/components/creator/_dialogs/delete-comments/delete-comments.component.html
+++ b/src/app/components/creator/_dialogs/delete-comments/delete-comments.component.html
@@ -1,10 +1,16 @@
-<h1>{{ 'room-page.sure' | translate }}</h1>
+<h1 *ngIf="!bonusQuestions">{{ 'room-page.sure' | translate }}</h1>
+<h1 *ngIf="bonusQuestions">{{ 'room-page.delete-comments-alt-header' | translate }}</h1>
 <mat-divider></mat-divider>
-<p>{{ 'room-page.really-delete-comments' | translate }}</p>
-<app-dialog-action-buttons
+<p *ngIf="!bonusQuestions">{{ 'room-page.really-delete-comments' | translate }}</p>
+<p *ngIf="bonusQuestions"><i>{{ 'room-page.really-delete-comments-hint' | translate }}</i></p>
+<app-dialog-action-buttons *ngIf="!bonusQuestions"
   buttonsLabelSection="content"
   confirmButtonLabel="delete"
   [confirmButtonType]=confirmButtonType
   [cancelButtonClickAction]="buildCloseDialogActionCallback()"
   [confirmButtonClickAction]="buildCommentsDeleteActionCallback()"
 ></app-dialog-action-buttons>
+<app-dialog-action-buttons *ngIf="bonusQuestions"
+  buttonsLabelSection="content"
+  [cancelButtonClickAction]="buildCloseDialogActionCallback()"
+></app-dialog-action-buttons>
diff --git a/src/app/components/creator/_dialogs/delete-comments/delete-comments.component.ts b/src/app/components/creator/_dialogs/delete-comments/delete-comments.component.ts
index c8e750473..b9af90600 100644
--- a/src/app/components/creator/_dialogs/delete-comments/delete-comments.component.ts
+++ b/src/app/components/creator/_dialogs/delete-comments/delete-comments.component.ts
@@ -1,9 +1,10 @@
 import { Component, Inject, OnInit } from '@angular/core';
 import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
-import { RoomEditComponent } from '../room-edit/room-edit.component';
 import { LiveAnnouncer } from '@angular/cdk/a11y';
 import { DialogConfirmActionButtonType } from '../../../shared/dialog/dialog-action-buttons/dialog-action-buttons.component';
 import { TranslateService } from '@ngx-translate/core';
+import { BonusTokenService } from '../../../../services/http/bonus-token.service';
+import { CommentSettingsComponent } from '../comment-settings/comment-settings.component';
 
 @Component({
   selector: 'app-delete-comment',
@@ -16,17 +17,26 @@ export class DeleteCommentsComponent implements OnInit {
    * The confirm button type of the dialog.
    */
   confirmButtonType: DialogConfirmActionButtonType = DialogConfirmActionButtonType.Alert;
+  roomId: string;
+  bonusQuestions = false;
 
-  constructor(public dialogRef: MatDialogRef<RoomEditComponent>,
+  constructor(public dialogRef: MatDialogRef<CommentSettingsComponent>,
               @Inject(MAT_DIALOG_DATA) public data: any,
               private liveAnnouncer: LiveAnnouncer,
-              private translationService: TranslateService )  { }
+              private translationService: TranslateService,
+              private tokenService: BonusTokenService)  { }
 
 
   ngOnInit() {
     this.translationService.get('room-page.really-delete-comments').subscribe(msg => {
       this.liveAnnouncer.announce(msg);
     });
+    this.tokenService.getTokensByRoomId(this.roomId).subscribe(tokens => {
+      if (tokens.length > 0) {
+        console.log('LEL EHY HEREWÄ');
+        this.bonusQuestions = true;
+      }
+    });
   }
 
   /**
diff --git a/src/app/components/shared/comment/comment.component.html b/src/app/components/shared/comment/comment.component.html
index 0a7049940..c1834f3f1 100644
--- a/src/app/components/shared/comment/comment.component.html
+++ b/src/app/components/shared/comment/comment.component.html
@@ -40,7 +40,7 @@
                                                  : ('comment-page.mark-not-favorite' | translate)">grade
         </mat-icon>
       </button>
-      <button mat-icon-button *ngIf="isCreator" (click)="openDeleteCommentDialog()"
+      <button mat-icon-button *ngIf="isCreator && !comment.favorite" (click)="openDeleteCommentDialog()"
               tabindex="0" attr.aria-labelledby="comment_delete{{ comment.id }}">
         <mat-icon class="not-marked" matTooltip="{{ 'comment-page.delete' | translate }}">delete
         </mat-icon>
diff --git a/src/assets/i18n/creator/de.json b/src/assets/i18n/creator/de.json
index 1e8dcb4e3..13e3968cf 100644
--- a/src/assets/i18n/creator/de.json
+++ b/src/assets/i18n/creator/de.json
@@ -193,7 +193,9 @@
     "no-moderators": "",
     "present": "Präsentieren",
     "public-stream": "Fragen",
-    "really-delete-comments": "Willst du wirklich alle Fragen dieser Sitzung löschen? Die Aktion kann nicht rückgängig gemacht werden. Falls du Boni (gelbe Sterne) vergeben hast, exportiere alle Fragen, damit du eingereichte Bonus-Tokens überprüfen kannst.",
+    "really-delete-comments": "Willst du wirklich alle Fragen dieser Sitzung löschen? Die Aktion kann nicht rückgängig gemacht werden.",
+    "really-delete-comments-hint": "Es gibt noch Fragen welche mit einem Bonus versehen sind. Bitte entfernen Sie die markierungen um alle Fragen zu löschen.",
+    "delete-comments-alt-header": "Achtung",
     "really-remove-moderator": "Willst du folgenden Moderator wirklich entfernen?",
     "really2": " wirklich löschen? Die Aktion kann nicht rückgängig gemacht werden. Falls du Boni (gelbe Sterne) vergeben hast, exportiere alle Fragen, damit du eingereichte Bonus-Tokens überprüfen kannst.",
     "reallyContent": "Willst du die Frage ",
diff --git a/src/assets/i18n/creator/en.json b/src/assets/i18n/creator/en.json
index 3774c12ff..e65dbcbe8 100644
--- a/src/assets/i18n/creator/en.json
+++ b/src/assets/i18n/creator/en.json
@@ -194,7 +194,9 @@
     "no-moderators": "No moderators yet",
     "present": "Present",
     "public-stream": "Questions",
-    "really-delete-comments": "Do you really want to delete all questions of this session? This action cannot be undone. If you have given bonuses (yellow stars), export all questions so that you can check submitted bonus tokens.",
+    "really-delete-comments": "Do you really want to delete all questions of this session? This action cannot be undone.",
+    "really-delete-comments-hint": "There are still questions which are provided with a bonus. Please remove the markers to delete all questions.",
+    "delete-comments-alt-header": "Attention",
     "really-remove-moderator": "Do you really want to remove the following moderator?",
     "really2": "? This action cannot be undone. If you have given bonuses (yellow stars), export all questions so that you can check submitted bonus tokens.",
     "reallyContent": "Do you really want to delete content ",
-- 
GitLab