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 35aa8901f04be6156c98381cd8159952725e4f0b..05dfc80e7217fa17db2cd5a8617d282216ecb521 100644 --- a/projects/common/models/elements/compound-elements/likert/likert-row.ts +++ b/projects/common/models/elements/compound-elements/likert/likert-row.ts @@ -39,29 +39,32 @@ export class LikertRowElement extends InputElement implements LikertRowPropertie } } + // eslint-disable-next-line class-methods-use-this hasAnswerScheme(): boolean { - return Boolean(this.getAnswerScheme); + // disable from direct call of getAnswerScheme + // this is done by its parent container + return false; } - getAnswerScheme(): AnswerScheme { + getAnswerScheme(options: TextImageLabel[]): AnswerScheme { return { id: this.id, type: 'integer', format: '', multiple: false, - nullable: !this.value && this.value !== 0, - values: this.getAnswerSchemeValues(), + nullable: false, + values: this.getAnswerSchemeValues(options), valuesComplete: true }; } - private getAnswerSchemeValues(): AnswerSchemeValue[] { - return [ - { - value: !this.value && this.value !== 0 ? 'null' : (this.value as number + 1).toString(), - label: InputElement.stripHTML(this.rowLabel.text) - } // TODO Image - ]; + // eslint-disable-next-line class-methods-use-this + private getAnswerSchemeValues(options: TextImageLabel[]): AnswerSchemeValue[] { + return options + .map((option, index) => ({ + value: (index + 1).toString(), + label: InputElement.stripHTML(option.text) + })); } getElementComponent(): Type<ElementComponent> { diff --git a/projects/common/models/elements/compound-elements/likert/likert.ts b/projects/common/models/elements/compound-elements/likert/likert.ts index 49f1eb0fd745f5b25bad031faad947842effe9d2..1a891fa4985d3838fad4df1739da4525567b494e 100644 --- a/projects/common/models/elements/compound-elements/likert/likert.ts +++ b/projects/common/models/elements/compound-elements/likert/likert.ts @@ -12,6 +12,7 @@ import { import { TextImageLabel } from 'common/models/elements/label-interfaces'; import { environment } from 'common/environment'; import { InstantiationEror } from 'common/util/errors'; +import { AnswerScheme } from 'common/models/elements/answer-scheme-interfaces'; export class LikertElement extends CompoundElement implements PositionedUIElement, OptionElement, LikertProperties { type: UIElementType = 'likert'; @@ -115,6 +116,10 @@ export class LikertElement extends CompoundElement implements PositionedUIElemen getDuplicate(): LikertElement { return new LikertElement(this); } + + getAnswerScheme(): AnswerScheme[] { + return this.rows.map(row => row.getAnswerScheme(this.options)); + } } export interface LikertProperties extends UIElementProperties { diff --git a/projects/common/models/elements/element.ts b/projects/common/models/elements/element.ts index 108dff17b70f4dc93e1bc1548b1da83b4e1145a9..285ea933ddfe5df54b25f0537d94e5b9ca48e005 100644 --- a/projects/common/models/elements/element.ts +++ b/projects/common/models/elements/element.ts @@ -123,7 +123,7 @@ export abstract class UIElement implements UIElementProperties { } hasAnswerScheme(): boolean { - return Boolean(this.getAnswerSchemeValues); + return Boolean(this.getAnswerScheme); } abstract getElementComponent(): Type<ElementComponent>; diff --git a/projects/common/models/elements/input-elements/math-table.ts b/projects/common/models/elements/input-elements/math-table.ts index 9f4cc1bc44650428e014bd211ad443f869e729b7..b4df2632f907fed0366097f9465a2cd02e125350 100644 --- a/projects/common/models/elements/input-elements/math-table.ts +++ b/projects/common/models/elements/input-elements/math-table.ts @@ -1,4 +1,4 @@ -import { UIElement, UIElementProperties, UIElementType, UIElementValue } from 'common/models/elements/element'; +import { UIElement, UIElementProperties, UIElementType } from 'common/models/elements/element'; import { AnswerScheme } from 'common/models/elements/answer-scheme-interfaces'; import { Type } from '@angular/core'; import { ElementComponent } from 'common/directives/element-component.directive'; @@ -64,10 +64,6 @@ export class MathTableElement extends UIElement implements MathTableProperties { } } - hasAnswerScheme(): boolean { - return Boolean(this.getAnswerScheme); - } - getAnswerScheme(): AnswerScheme { return { id: this.id,