From c8d494d988f88b5f691f1e839dcd02ecc2f88b9b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lukas=20Mau=C3=9F?= <lukas.mauss@mni.thm.de>
Date: Wed, 7 Nov 2018 15:14:36 +0100
Subject: [PATCH] Refactor yes-no-content-creation

---
 .../content-creator.component.html            |  3 ++
 .../content-yes-no-creator.component.html     | 33 +++++--------------
 .../content-yes-no-creator.component.ts       | 16 +++++----
 3 files changed, 22 insertions(+), 30 deletions(-)

diff --git a/src/app/components/creator/content-creator/content-creator.component.html b/src/app/components/creator/content-creator/content-creator.component.html
index fffd4ad81..be3ab8716 100644
--- a/src/app/components/creator/content-creator/content-creator.component.html
+++ b/src/app/components/creator/content-creator/content-creator.component.html
@@ -26,4 +26,7 @@
   <app-content-likert-creator *ngIf="format === 'likert'"
        [contentSub] = "subject.value" [contentBod]="body.value" [contentCol]="group.value">
   </app-content-likert-creator>
+  <app-content-yes-no-creator *ngIf="format === 'yesno'"
+                              [contentSub] = "subject.value" [contentBod]="body.value" [contentCol]="group.value">
+  </app-content-yes-no-creator>
 </form>
diff --git a/src/app/components/creator/content-yes-no-creator/content-yes-no-creator.component.html b/src/app/components/creator/content-yes-no-creator/content-yes-no-creator.component.html
index 2a6489270..adcc6f37f 100644
--- a/src/app/components/creator/content-yes-no-creator/content-yes-no-creator.component.html
+++ b/src/app/components/creator/content-yes-no-creator/content-yes-no-creator.component.html
@@ -1,27 +1,12 @@
-<form (ngSubmit)="submitContent(subject.value, body.value, group.value)">
-  <mat-form-field class="input-block">
-    <input matInput #subject [(ngModel)]="content.subject" placeholder="{{ 'content.subject' | translate }}" name="subject">
-  </mat-form-field>
-  <mat-form-field class="input-block">
-    <textarea matInput #body [(ngModel)]="content.body" placeholder="{{ 'content.body' | translate }}" name="body"></textarea>
-  </mat-form-field>
-        <mat-radio-group [(ngModel)]="yesno" [ngModelOptions]="{standalone: true}" fxLayout="row" fxLayoutAlign="center" fxLayoutGap="20px">
-          <mat-radio-button [value]=true [checked]=true>
-            {{ 'content.yes' | translate }}
-          </mat-radio-button>
-          <mat-radio-button [value]=false [checked]=false>
-            {{ 'content.no' | translate }}
-          </mat-radio-button>
-        </mat-radio-group>
-  <mat-form-field>
-    <input matInput #group matInput [formControl]="myControl" [matAutocomplete]="auto"
-           value={{lastCollection}} placeholder="{{'content.collection' | translate}}"/>
-    <mat-autocomplete #auto="matAutocomplete">
-      <mat-option *ngFor="let collection of filteredOptions | async" [value]="collection">
-        {{collection}}
-      </mat-option>
-    </mat-autocomplete>
-  </mat-form-field>
+<form (ngSubmit)="submitContent()">
+  <mat-radio-group [(ngModel)]="yesno" [ngModelOptions]="{standalone: true}" fxLayout="row" fxLayoutAlign="center" fxLayoutGap="20px">
+    <mat-radio-button [value]=true [checked]=true>
+      {{ 'content.yes' | translate }}
+    </mat-radio-button>
+    <mat-radio-button [value]=false [checked]=false>
+      {{ 'content.no' | translate }}
+    </mat-radio-button>
+  </mat-radio-group>
   <div *ngIf="!editDialogMode">
     <button mat-raised-button type="submit" color="accent">{{ 'content.create' | translate }}</button>
   </div>
diff --git a/src/app/components/creator/content-yes-no-creator/content-yes-no-creator.component.ts b/src/app/components/creator/content-yes-no-creator/content-yes-no-creator.component.ts
index f36749c32..97bc13c47 100644
--- a/src/app/components/creator/content-yes-no-creator/content-yes-no-creator.component.ts
+++ b/src/app/components/creator/content-yes-no-creator/content-yes-no-creator.component.ts
@@ -1,4 +1,4 @@
-import { Component, Inject, OnInit } from '@angular/core';
+import { Component, Inject, Input, OnInit } from '@angular/core';
 import { ContentChoice } from '../../../models/content-choice';
 import { DisplayAnswer } from '../content-choice-creator/content-choice-creator.component';
 import { AnswerOption } from '../../../models/answer-option';
@@ -19,6 +19,10 @@ import { TranslateService } from '@ngx-translate/core';
   styleUrls: ['./content-yes-no-creator.component.scss']
 })
 export class ContentYesNoCreatorComponent implements OnInit {
+  @Input() contentSub;
+  @Input() contentBod;
+  @Input() contentCol;
+
   yesno = true;
   answerLabels = [
     'yes',
@@ -93,8 +97,8 @@ export class ContentYesNoCreatorComponent implements OnInit {
     });
   }
 
-  submitContent(subject: string, body: string, group: string): void {
-    if (subject.valueOf() === '' || body.valueOf() === '') {
+  submitContent(): void {
+    if (this.contentSub === '' || this.contentBod === '') {
       this.translationService.get('content.no-empty').subscribe(message => {
         this.notificationService.show(message);
       });
@@ -109,10 +113,10 @@ export class ContentYesNoCreatorComponent implements OnInit {
       '',
       '',
       this.roomId,
-      subject,
-      body,
+      this.contentSub,
+      this.contentBod,
       1,
-      [group],
+      [this.contentCol],
       this.content.options,
       this.content.correctOptionIndexes,
       this.content.multiple,
-- 
GitLab