From d0e9dc3aa332228c1b1885f5fd2e8b30e08a306f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lukas=20Mau=C3=9F?= <lukas.mauss@mni.thm.de>
Date: Fri, 8 Feb 2019 17:45:24 +0100
Subject: [PATCH] Fix content backup

---
 .../content-list/content-list.component.html  |  4 +-
 .../content-list/content-list.component.ts    | 38 ++++++-------------
 2 files changed, 14 insertions(+), 28 deletions(-)

diff --git a/src/app/components/creator/content-list/content-list.component.html b/src/app/components/creator/content-list/content-list.component.html
index 24503bb4f..8c2daf2b7 100644
--- a/src/app/components/creator/content-list/content-list.component.html
+++ b/src/app/components/creator/content-list/content-list.component.html
@@ -37,10 +37,10 @@
     <mat-card-content>
       <mat-expansion-panel *ngFor="let content of contents">
         <mat-expansion-panel-header>
-          <button mat-icon-button color="accent" (click)="$event.stopPropagation();">
+          <button mat-icon-button color="accent" (click)="editContent(content);$event.stopPropagation();">
             <mat-icon>create</mat-icon>
           </button>
-          <button mat-icon-button color="warn" (click)="deleteContentDialog(content);$event.stopPropagation();"
+          <button mat-icon-button color="warn" (click)="deleteContent(content);$event.stopPropagation();"
                   class="deleteButton">
             <mat-icon>delete_forever</mat-icon>
           </button>
diff --git a/src/app/components/creator/content-list/content-list.component.ts b/src/app/components/creator/content-list/content-list.component.ts
index 4886c77aa..acf7290a8 100644
--- a/src/app/components/creator/content-list/content-list.component.ts
+++ b/src/app/components/creator/content-list/content-list.component.ts
@@ -18,6 +18,7 @@ import { RoomService } from '../../../services/http/room.service';
 import { TranslateService } from '@ngx-translate/core';
 import { LanguageService } from '../../../services/util/language.service';
 import { ContentDeleteComponent } from '../_dialogs/content-delete/content-delete.component';
+import { ContentCreatorComponent } from '../content-creator/content-creator.component';
 
 
 @Component({
@@ -86,17 +87,6 @@ export class ContentListComponent implements OnInit {
   }
 
   createChoiceContentBackup(content: ContentChoice) {
-    const answerOptions: Array<AnswerOption> = new Array<AnswerOption> ();
-    const correctAnswers: number[] = [];
-
-    for (let i = 0; i < content.options.length; i++) {
-      answerOptions.push(content.options[i]);
-    }
-
-    for (let i = 0; i < content.correctOptionIndexes.length; i++) {
-      correctAnswers.push(content.correctOptionIndexes[i]);
-    }
-
     this.contentBackup = new ContentChoice(
       content.id,
       content.revision,
@@ -104,9 +94,9 @@ export class ContentListComponent implements OnInit {
       content.subject,
       content.body,
       content.round,
-      [],
-      answerOptions,
-      correctAnswers,
+      content.groups,
+      content.options,
+      content.correctOptionIndexes,
       content.multiple,
       content.format
     );
@@ -124,8 +114,8 @@ export class ContentListComponent implements OnInit {
     );
   }
 
-  editContent(subject: string) {
-    const index = this.findIndexOfSubject(subject);
+  editContent(content: Content) {
+    const index = this.findIndexOfSubject(content.subject);
     const format = this.contents[index].format;
 
     if (format === this.ContentType.TEXT) {
@@ -136,7 +126,7 @@ export class ContentListComponent implements OnInit {
 
     switch (format) {
       case this.ContentType.CHOICE:
-        this.editChoiceContentDialog(index, this.contents[index] as ContentChoice);
+        this.editChoiceContentDialog(content);
         break;
       case this.ContentType.BINARY:
         this.editBinaryContentDialog(index, this.contents[index] as ContentChoice);
@@ -152,7 +142,7 @@ export class ContentListComponent implements OnInit {
     }
   }
 
-  deleteContentDialog(delContent: Content) {
+  deleteContent(delContent: Content) {
     const index = this.findIndexOfSubject(delContent.subject);
     this.contentBackup = delContent;
     const dialogRef = this.dialog.open(ContentDeleteComponent, {
@@ -165,17 +155,13 @@ export class ContentListComponent implements OnInit {
       });
   }
 
-  editChoiceContentDialog(index: number, content: ContentChoice) {
-    const dialogRef = this.dialog.open(ContentChoiceCreatorComponent, {
+  editChoiceContentDialog(delContent: Content) {
+    const index = this.findIndexOfSubject(delContent.subject);
+    const dialogRef = this.dialog.open(ContentCreatorComponent, {
       width: '800px'
     });
-    if (content.multiple) {
-      dialogRef.componentInstance.singleChoice = false;
-    } else {
-      dialogRef.componentInstance.singleChoice = true;
-    }
     dialogRef.componentInstance.editDialogMode = true;
-    dialogRef.componentInstance.content = content;
+    dialogRef.componentInstance.content = delContent;
     dialogRef.afterClosed()
       .subscribe(result => {
         this.updateContentChanges(index, result);
-- 
GitLab