From fe149fd58afd618cbf9136e92323cfd16217cea8 Mon Sep 17 00:00:00 2001
From: Thomas Lenz <Thomas.Lenz@mni.thm.de>
Date: Fri, 6 Apr 2018 15:36:05 +0200
Subject: [PATCH] Modify choice-content model to accept the different formats

---
 .../content-choice-creator.component.ts       |  6 +++-
 .../content-choice-participant.component.ts   |  3 +-
 .../content-likert-creator.component.ts       |  6 ++--
 .../content-yes-no-creator.component.ts       |  5 +++-
 .../content-carousel-page.component.ts        | 28 +++++++++++++++----
 src/app/models/content-choice.ts              |  5 ++--
 6 files changed, 40 insertions(+), 13 deletions(-)

diff --git a/src/app/components/fragments/content-choice-creator/content-choice-creator.component.ts b/src/app/components/fragments/content-choice-creator/content-choice-creator.component.ts
index 54b09194e..45e5b3469 100644
--- a/src/app/components/fragments/content-choice-creator/content-choice-creator.component.ts
+++ b/src/app/components/fragments/content-choice-creator/content-choice-creator.component.ts
@@ -5,6 +5,7 @@ import { ContentService } from '../../../services/http/content.service';
 import { NotificationService } from '../../../services/util/notification.service';
 import { MatDialog } from '@angular/material';
 import { AnswerEditComponent } from '../../dialogs/answer-edit/answer-edit.component';
+import { ContentType } from '../../../models/content-type.enum';
 
 export class DisplayAnswer {
   answerOption: AnswerOption;
@@ -32,7 +33,8 @@ export class ContentChoiceCreatorComponent implements OnInit {
     1,
     [],
     [],
-    true);
+    true,
+    ContentType.CHOICE);
 
   displayedColumns = ['label', 'points', 'actions'];
 
@@ -233,9 +235,11 @@ export class ContentChoiceCreatorComponent implements OnInit {
     }
     if (this.singleChoice) {
       this.content.multiple = false;
+      this.content.format = ContentType.BINARY;
     }
     if (this.multipleChoice) {
       this.content.multiple = true;
+      this.content.format = ContentType.CHOICE;
     }
     this.notificationService.show('Content submitted.');
     /*   if (this.content.contentId === '0') {
diff --git a/src/app/components/fragments/content-choice-participant/content-choice-participant.component.ts b/src/app/components/fragments/content-choice-participant/content-choice-participant.component.ts
index 434368216..d4472e753 100644
--- a/src/app/components/fragments/content-choice-participant/content-choice-participant.component.ts
+++ b/src/app/components/fragments/content-choice-participant/content-choice-participant.component.ts
@@ -41,7 +41,8 @@ export class ContentChoiceParticipantComponent implements OnInit {
       new AnswerOption('Option 4', '30')
     ],
     [2, 3, 4],
-    false);
+    false,
+    ContentType.BINARY);
   checkedAnswers: CheckedAnswer[] = [];
   isAnswerSent = false;
 
diff --git a/src/app/components/fragments/content-likert-creator/content-likert-creator.component.ts b/src/app/components/fragments/content-likert-creator/content-likert-creator.component.ts
index e87b1ed56..02ce99c33 100644
--- a/src/app/components/fragments/content-likert-creator/content-likert-creator.component.ts
+++ b/src/app/components/fragments/content-likert-creator/content-likert-creator.component.ts
@@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
 import { DisplayAnswer } from '../content-choice-creator/content-choice-creator.component';
 import { ContentChoice } from '../../../models/content-choice';
 import { AnswerOption } from '../../../models/answer-option';
+import { ContentType } from '../../../models/content-type.enum';
 
 @Component({
   selector: 'app-content-likert-creator',
@@ -25,12 +26,13 @@ export class ContentLikertCreatorComponent implements OnInit {
     1,
     [],
     [],
-    false);
+    false,
+    ContentType.SCALE);
 
   displayedColumns = ['label'];
 
   displayAnswers: DisplayAnswer[] = [];
-  newAnswerOptionPoints = '';
+  newAnswerOptionPoints = '0';
 
   constructor() {
   }
diff --git a/src/app/components/fragments/content-yes-no-creator/content-yes-no-creator.component.ts b/src/app/components/fragments/content-yes-no-creator/content-yes-no-creator.component.ts
index 351a5263a..3e3839047 100644
--- a/src/app/components/fragments/content-yes-no-creator/content-yes-no-creator.component.ts
+++ b/src/app/components/fragments/content-yes-no-creator/content-yes-no-creator.component.ts
@@ -3,6 +3,7 @@ import { ContentChoice } from '../../../models/content-choice';
 import { DisplayAnswer } from '../content-choice-creator/content-choice-creator.component';
 import { AnswerOption } from '../../../models/answer-option';
 import { NotificationService } from '../../../services/util/notification.service';
+import { ContentType } from '../../../models/content-type.enum';
 
 @Component({
   selector: 'app-content-yes-no-creator',
@@ -22,7 +23,9 @@ export class ContentYesNoCreatorComponent implements OnInit {
     1,
     [],
     [],
-    false);
+    false,
+    ContentType.BINARY
+    );
 
   displayedColumns = ['label'];
 
diff --git a/src/app/components/pages/content-carousel-page/content-carousel-page.component.ts b/src/app/components/pages/content-carousel-page/content-carousel-page.component.ts
index 982bda99f..f61e25577 100644
--- a/src/app/components/pages/content-carousel-page/content-carousel-page.component.ts
+++ b/src/app/components/pages/content-carousel-page/content-carousel-page.component.ts
@@ -1,5 +1,4 @@
 import { Component, OnInit } from '@angular/core';
-import { Content } from '../../../models/content';
 import { ContentType } from '../../../models/content-type.enum';
 import { AnswerOption } from '../../../models/answer-option';
 import { ContentChoice } from '../../../models/content-choice';
@@ -26,22 +25,39 @@ export class ContentCarouselPageComponent implements OnInit {
       1,
       [new AnswerOption('yes', ''), new AnswerOption('no', '')],
       [],
-      true),
+      true,
+      ContentType.CHOICE),
     new ContentChoice('0',
       '1',
       'roomId2',
       'SingleChoice Subject',
-      'SingleChoide Body',
+      'SingleChoice Body',
       1,
       [new AnswerOption('may', ''), new AnswerOption('not', '')],
       [],
-      false),
+      false,
+      ContentType.BINARY),
     new ContentText('1',
       '1',
-      '0',
+      'roomId3',
       'TextContent Subject',
       'TextContent Body',
-      1)
+      1),
+    new ContentChoice('0',
+      '1',
+      'roomId4',
+      'LikertContent Subjekt',
+      'LikertContent Body',
+      1,
+      [
+        new AnswerOption('Strongly agree', '0'),
+        new AnswerOption('Agree', '0'),
+        new AnswerOption('Neither agree nor disagree', '0'),
+        new AnswerOption('Disagree', '0' ),
+      new AnswerOption('Strongly disagree', '0') ],
+      [],
+      false,
+      ContentType.SCALE)
   ];
 
   constructor(private contentService: ContentService,
diff --git a/src/app/models/content-choice.ts b/src/app/models/content-choice.ts
index 25cb9927d..6bca40dbb 100644
--- a/src/app/models/content-choice.ts
+++ b/src/app/models/content-choice.ts
@@ -15,14 +15,15 @@ export class ContentChoice extends Content {
               round: number,
               options: AnswerOption[],
               correctOptionIndexes: number[],
-              multiple: boolean) {
+              multiple: boolean,
+              format: ContentType) {
     super(contentId,
       revision,
       roomId,
       subject,
       body,
       round,
-      ContentType.CHOICE,
+      format,
       new Map());
       this.options = options;
       this.correctOptionIndexes = correctOptionIndexes;
-- 
GitLab