From e616600c1485d54d546017dee9927bca28731071 Mon Sep 17 00:00:00 2001
From: jojohoch <joachim.hoch@iqb.hu-berlin.de>
Date: Mon, 29 Aug 2022 10:27:11 +0200
Subject: [PATCH] [editor] Refactor some methods after merge

---
 .../cloze/cloze-child-elements/drop-list-simple.ts  |  6 +++---
 .../cloze/cloze-child-elements/text-field-simple.ts |  2 +-
 .../cloze/cloze-child-elements/toggle-button.ts     |  6 ++++--
 .../elements/compound-elements/likert/likert-row.ts | 13 ++++++++-----
 projects/common/models/elements/element.ts          |  6 ++----
 .../models/elements/input-elements/checkbox.ts      |  6 ++++--
 .../models/elements/input-elements/drop-list.ts     |  8 ++++----
 .../models/elements/input-elements/dropdown.ts      |  5 +++--
 .../input-elements/radio-button-group-complex.ts    |  8 ++++----
 .../elements/input-elements/radio-button-group.ts   |  6 +++---
 .../common/models/elements/input-elements/slider.ts |  2 +-
 .../models/elements/input-elements/spell-correct.ts |  2 +-
 .../models/elements/input-elements/text-area.ts     |  2 +-
 .../models/elements/input-elements/text-field.ts    |  2 +-
 projects/common/models/section.ts                   |  9 ++++-----
 15 files changed, 44 insertions(+), 39 deletions(-)

diff --git a/projects/common/models/elements/compound-elements/cloze/cloze-child-elements/drop-list-simple.ts b/projects/common/models/elements/compound-elements/cloze/cloze-child-elements/drop-list-simple.ts
index dc42abf27..18f4cc92d 100644
--- a/projects/common/models/elements/compound-elements/cloze/cloze-child-elements/drop-list-simple.ts
+++ b/projects/common/models/elements/compound-elements/cloze/cloze-child-elements/drop-list-simple.ts
@@ -1,6 +1,6 @@
 import { ElementFactory } from 'common/util/element.factory';
 import {
-  BasicStyles, DragNDropValueObject, InputElement, UIElementValue,  AnswerScheme,
+  BasicStyles, DragNDropValueObject, InputElement, UIElementValue, AnswerScheme,
   AnswerSchemeValue
 } from 'common/models/elements/element';
 import { Type } from '@angular/core';
@@ -42,7 +42,7 @@ export class DropListSimpleElement extends InputElement {
   }
 
   hasAnswerScheme(): boolean {
-    return true;
+    return Boolean(this.getAnswerScheme);
   }
 
   getAnswerScheme(dropLists: Array<DropListElement | DropListSimpleElement>): AnswerScheme {
@@ -62,7 +62,7 @@ export class DropListSimpleElement extends InputElement {
     return [this, ...valueDropLists]
       .map(dropList => dropList.value as DragNDropValueObject[])
       .flat()
-      .map(option => ({ value: option.id, label: option.stringValue as string })); // TODO: imageValueSrc
+      .map(option => ({ value: option.id, label: option.text as string }));
   }
 
   setProperty(property: string, value: UIElementValue) {
diff --git a/projects/common/models/elements/compound-elements/cloze/cloze-child-elements/text-field-simple.ts b/projects/common/models/elements/compound-elements/cloze/cloze-child-elements/text-field-simple.ts
index cdce6dd3a..f2ee44ef9 100644
--- a/projects/common/models/elements/compound-elements/cloze/cloze-child-elements/text-field-simple.ts
+++ b/projects/common/models/elements/compound-elements/cloze/cloze-child-elements/text-field-simple.ts
@@ -47,7 +47,7 @@ export class TextFieldSimpleElement extends InputElement {
   }
 
   hasAnswerScheme(): boolean {
-    return true;
+    return Boolean(this.getAnswerScheme);
   }
 
   getAnswerScheme(): AnswerScheme {
diff --git a/projects/common/models/elements/compound-elements/cloze/cloze-child-elements/toggle-button.ts b/projects/common/models/elements/compound-elements/cloze/cloze-child-elements/toggle-button.ts
index 185b4b2e2..b65e79842 100644
--- a/projects/common/models/elements/compound-elements/cloze/cloze-child-elements/toggle-button.ts
+++ b/projects/common/models/elements/compound-elements/cloze/cloze-child-elements/toggle-button.ts
@@ -1,5 +1,7 @@
 import { ElementFactory } from 'common/util/element.factory';
-import { BasicStyles, InputElement, AnswerScheme, AnswerSchemeValue } from 'common/models/elements/element';
+import {
+  BasicStyles, InputElement, AnswerScheme, AnswerSchemeValue
+} from 'common/models/elements/element';
 import { Type } from '@angular/core';
 import { ElementComponent } from 'common/directives/element-component.directive';
 import {
@@ -35,7 +37,7 @@ export class ToggleButtonElement extends InputElement {
   }
 
   hasAnswerScheme(): boolean {
-    return true;
+    return Boolean(this.getAnswerScheme);
   }
 
   getAnswerScheme(): AnswerScheme {
diff --git a/projects/common/models/elements/compound-elements/likert/likert-row.ts b/projects/common/models/elements/compound-elements/likert/likert-row.ts
index 32d132be7..3def2ba47 100644
--- a/projects/common/models/elements/compound-elements/likert/likert-row.ts
+++ b/projects/common/models/elements/compound-elements/likert/likert-row.ts
@@ -1,5 +1,7 @@
 import { Type } from '@angular/core';
-import { InputElement, AnswerScheme, AnswerSchemeValue, TextImageLabel } from 'common/models/elements/element';
+import {
+  InputElement, AnswerScheme, AnswerSchemeValue, TextImageLabel
+} from 'common/models/elements/element';
 import { ElementComponent } from 'common/directives/element-component.directive';
 import {
   LikertRadioButtonGroupComponent
@@ -20,7 +22,7 @@ export class LikertRowElement extends InputElement {
   }
 
   hasAnswerScheme(): boolean {
-    return true;
+    return Boolean(this.getAnswerScheme);
   }
 
   getAnswerScheme(): AnswerScheme {
@@ -36,10 +38,11 @@ export class LikertRowElement extends InputElement {
   }
 
   private getAnswerSchemeValues(): AnswerSchemeValue[] {
-    console.log(this.value);
     return [
-      { value: !this.value && this.value !== 0 ? 'null' : (this.value as number + 1).toString(),
-        label: this.rowLabel.text } // TODO Image
+      {
+        value: !this.value && this.value !== 0 ? 'null' : (this.value as number + 1).toString(),
+        label: this.rowLabel.text
+      } // TODO Image
     ];
   }
 
diff --git a/projects/common/models/elements/element.ts b/projects/common/models/elements/element.ts
index 509e778bf..55bf5b0cd 100644
--- a/projects/common/models/elements/element.ts
+++ b/projects/common/models/elements/element.ts
@@ -73,10 +73,9 @@ export abstract class UIElement {
   }
 
   hasAnswerScheme(): boolean {
-    return false;
+    return Boolean(this.getAnswerSchemeValues);
   }
 
-  abstract getComponentFactory(): Type<ElementComponent>;
   abstract getElementComponent(): Type<ElementComponent>;
 }
 
@@ -101,7 +100,6 @@ export abstract class InputElement extends UIElement {
   abstract getAnswerScheme(options?: unknown): AnswerScheme;
 }
 
-
 export abstract class CompoundElement extends UIElement {
   abstract getChildElements(): UIElement[];
 }
@@ -115,7 +113,7 @@ export abstract class PlayerElement extends UIElement {
   }
 
   hasAnswerScheme(): boolean {
-    return true;
+    return Boolean(this.getAnswerScheme);
   }
 
   getAnswerScheme(): AnswerScheme {
diff --git a/projects/common/models/elements/input-elements/checkbox.ts b/projects/common/models/elements/input-elements/checkbox.ts
index cd4136357..cd471ccf7 100644
--- a/projects/common/models/elements/input-elements/checkbox.ts
+++ b/projects/common/models/elements/input-elements/checkbox.ts
@@ -1,6 +1,8 @@
 import { Type } from '@angular/core';
 import { ElementFactory } from 'common/util/element.factory';
-import { BasicStyles, InputElement, PositionedUIElement, PositionProperties, AnswerScheme, AnswerSchemeValue } from 'common/models/elements/element';
+import {
+  BasicStyles, InputElement, PositionedUIElement, PositionProperties, AnswerScheme, AnswerSchemeValue
+} from 'common/models/elements/element';
 import { ElementComponent } from 'common/directives/element-component.directive';
 import { CheckboxComponent } from 'common/components/input-elements/checkbox.component';
 
@@ -15,7 +17,7 @@ export class CheckboxElement extends InputElement implements PositionedUIElement
   }
 
   hasAnswerScheme(): boolean {
-    return true;
+    return Boolean(this.getAnswerScheme);
   }
 
   getAnswerScheme(): AnswerScheme {
diff --git a/projects/common/models/elements/input-elements/drop-list.ts b/projects/common/models/elements/input-elements/drop-list.ts
index 43d63b332..2d80abd95 100644
--- a/projects/common/models/elements/input-elements/drop-list.ts
+++ b/projects/common/models/elements/input-elements/drop-list.ts
@@ -51,7 +51,7 @@ export class DropListElement extends InputElement implements PositionedUIElement
   }
 
   hasAnswerScheme(): boolean {
-    return true;
+    return Boolean(this.getAnswerScheme);
   }
 
   getAnswerScheme(options: Array<DropListElement | DropListSimpleElement>): AnswerScheme {
@@ -66,13 +66,13 @@ export class DropListElement extends InputElement implements PositionedUIElement
     };
   }
 
-  private getAnswerSchemeValues( dropLists: Array<DropListElement | DropListSimpleElement>): AnswerSchemeValue[] {
-    const valueDropLists = dropLists.filter(dropList => dropList.connectedTo.includes(this.id) );
+  private getAnswerSchemeValues(dropLists: Array<DropListElement | DropListSimpleElement>): AnswerSchemeValue[] {
+    const valueDropLists = dropLists.filter(dropList => dropList.connectedTo.includes(this.id));
     if (valueDropLists.length || this.isSortingList()) {
       return [this, ...valueDropLists]
         .map(dropList => dropList.value as DragNDropValueObject[])
         .flat()
-        .map(option => ({ value: option.id, label: option.stringValue as string })); // TODO: imageValueSrc
+        .map(option => ({ value: option.id, label: option.text as string }));
     }
     return [];
   }
diff --git a/projects/common/models/elements/input-elements/dropdown.ts b/projects/common/models/elements/input-elements/dropdown.ts
index 234c1921f..e336c0aca 100644
--- a/projects/common/models/elements/input-elements/dropdown.ts
+++ b/projects/common/models/elements/input-elements/dropdown.ts
@@ -24,7 +24,7 @@ export class DropdownElement extends InputElement implements PositionedUIElement
   }
 
   hasAnswerScheme(): boolean {
-    return true;
+    return Boolean(this.getAnswerScheme);
   }
 
   getAnswerScheme(): AnswerScheme {
@@ -40,7 +40,8 @@ export class DropdownElement extends InputElement implements PositionedUIElement
   }
 
   private getAnswerSchemeValues(): AnswerSchemeValue[] {
-    return this.options.map((option, index) => ({ value: (index + 1).toString(), label: option }));
+    return this.options
+      .map((option, index) => ({ value: (index + 1).toString(), label: option.text }));
   }
 
   getElementComponent(): Type<ElementComponent> {
diff --git a/projects/common/models/elements/input-elements/radio-button-group-complex.ts b/projects/common/models/elements/input-elements/radio-button-group-complex.ts
index d31bbc7c7..c73953048 100644
--- a/projects/common/models/elements/input-elements/radio-button-group-complex.ts
+++ b/projects/common/models/elements/input-elements/radio-button-group-complex.ts
@@ -3,7 +3,7 @@ import { ElementFactory } from 'common/util/element.factory';
 import {
   BasicStyles, InputElement, OptionElement,
   PositionedUIElement, PositionProperties, TextImageLabel,
-  AnswerScheme, AnswerSchemeValue,
+  AnswerScheme, AnswerSchemeValue
 } from 'common/models/elements/element';
 import { ElementComponent } from 'common/directives/element-component.directive';
 import { RadioGroupImagesComponent } from 'common/components/input-elements/radio-group-images.component';
@@ -25,7 +25,7 @@ export class RadioButtonGroupComplexElement extends InputElement implements Posi
   }
 
   hasAnswerScheme(): boolean {
-    return true;
+    return Boolean(this.getAnswerScheme);
   }
 
   getAnswerScheme(): AnswerScheme {
@@ -41,8 +41,8 @@ export class RadioButtonGroupComplexElement extends InputElement implements Posi
   }
 
   private getAnswerSchemeValues(): AnswerSchemeValue[] {
-    return this.columns
-      .map((option, index) => ({ value: (index + 1).toString(), label: option.text })); //TODO iMAGE
+    return this.options
+      .map((option, index) => ({ value: (index + 1).toString(), label: option.text }));
   }
 
   getElementComponent(): Type<ElementComponent> {
diff --git a/projects/common/models/elements/input-elements/radio-button-group.ts b/projects/common/models/elements/input-elements/radio-button-group.ts
index 89e555c61..eb5746c79 100644
--- a/projects/common/models/elements/input-elements/radio-button-group.ts
+++ b/projects/common/models/elements/input-elements/radio-button-group.ts
@@ -35,7 +35,7 @@ export class RadioButtonGroupElement extends InputElement implements PositionedU
   }
 
   hasAnswerScheme(): boolean {
-    return true;
+    return Boolean(this.getAnswerScheme);
   }
 
   getAnswerScheme(): AnswerScheme {
@@ -51,8 +51,8 @@ export class RadioButtonGroupElement extends InputElement implements PositionedU
   }
 
   private getAnswerSchemeValues(): AnswerSchemeValue[] {
-    return this.richTextOptions
-      .map((option, index) => ({ value: (index + 1).toString(), label: option }));
+    return this.options
+      .map((option, index) => ({ value: (index + 1).toString(), label: option.text }));
   }
 
   getElementComponent(): Type<ElementComponent> {
diff --git a/projects/common/models/elements/input-elements/slider.ts b/projects/common/models/elements/input-elements/slider.ts
index 8cd2ceb5b..b65104a47 100644
--- a/projects/common/models/elements/input-elements/slider.ts
+++ b/projects/common/models/elements/input-elements/slider.ts
@@ -35,7 +35,7 @@ export class SliderElement extends InputElement implements PositionedUIElement {
   }
 
   hasAnswerScheme(): boolean {
-    return true;
+    return Boolean(this.getAnswerScheme);
   }
 
   getAnswerScheme(): AnswerScheme {
diff --git a/projects/common/models/elements/input-elements/spell-correct.ts b/projects/common/models/elements/input-elements/spell-correct.ts
index 7b18ae065..6a0cd1d09 100644
--- a/projects/common/models/elements/input-elements/spell-correct.ts
+++ b/projects/common/models/elements/input-elements/spell-correct.ts
@@ -35,7 +35,7 @@ export class SpellCorrectElement extends InputElement implements PositionedUIEle
   }
 
   hasAnswerScheme(): boolean {
-    return true;
+    return Boolean(this.getAnswerScheme);
   }
 
   getAnswerScheme(): AnswerScheme {
diff --git a/projects/common/models/elements/input-elements/text-area.ts b/projects/common/models/elements/input-elements/text-area.ts
index 9c9ba32e0..4e2211969 100644
--- a/projects/common/models/elements/input-elements/text-area.ts
+++ b/projects/common/models/elements/input-elements/text-area.ts
@@ -47,7 +47,7 @@ export class TextAreaElement extends InputElement implements PositionedUIElement
   }
 
   hasAnswerScheme(): boolean {
-    return true;
+    return Boolean(this.getAnswerScheme);
   }
 
   getAnswerScheme(): AnswerScheme {
diff --git a/projects/common/models/elements/input-elements/text-field.ts b/projects/common/models/elements/input-elements/text-field.ts
index 3ced6845e..64acc9138 100644
--- a/projects/common/models/elements/input-elements/text-field.ts
+++ b/projects/common/models/elements/input-elements/text-field.ts
@@ -54,7 +54,7 @@ export class TextFieldElement extends InputElement implements PositionedUIElemen
   }
 
   hasAnswerScheme(): boolean {
-    return true;
+    return Boolean(this.getAnswerScheme);
   }
 
   getAnswerScheme(): AnswerScheme {
diff --git a/projects/common/models/section.ts b/projects/common/models/section.ts
index 3eae3dba8..c72f14d47 100644
--- a/projects/common/models/section.ts
+++ b/projects/common/models/section.ts
@@ -1,7 +1,7 @@
 import { Type } from '@angular/core';
 import { IDManager } from 'common/util/id-manager';
 import {
-  CompoundElement, PositionedUIElement, UIElement, UIElementValue, AnswerScheme
+  CompoundElement, PositionedUIElement, UIElement, UIElementValue, AnswerScheme, PlayerElement, InputElement
 } from 'common/models/elements/element';
 import { ButtonElement } from 'common/models/elements/button/button';
 import { TextElement } from 'common/models/elements/text/text';
@@ -104,9 +104,8 @@ export class Section {
   getAnswerScheme(dropLists: UIElement[]): AnswerScheme[] {
     return this.getAllElements()
       .filter(element => element.hasAnswerScheme())
-      .map(element =>
-        (element.type === 'drop-list' || element.type === 'drop-list-simple') ?
-          (element as InputElement).getAnswerScheme(dropLists) :
-          (element as InputElement | PlayerElement | TextElement | ImageElement).getAnswerScheme());
+      .map(element => ((element.type === 'drop-list' || element.type === 'drop-list-simple') ?
+        (element as InputElement).getAnswerScheme(dropLists) :
+        (element as InputElement | PlayerElement | TextElement | ImageElement).getAnswerScheme()));
   }
 }
-- 
GitLab