Skip to content
Snippets Groups Projects
likert-row.ts 1.7 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { Type } from '@angular/core';
    
    import {
      InputElement, AnswerScheme, AnswerSchemeValue, TextImageLabel
    } from 'common/models/elements/element';
    
    import { ElementComponent } from 'common/directives/element-component.directive';
    import {
      LikertRadioButtonGroupComponent
    } from 'common/components/compound-elements/likert/likert-radio-button-group.component';
    
    export class LikertRowElement extends InputElement {
    
      rowLabel: TextImageLabel = { text: '', imgSrc: null, imgPosition: 'above' };
    
      columnCount: number = 0;
      firstColumnSizeRatio: number = 5;
      verticalButtonAlignment: 'auto' | 'center' = 'center';
    
    
    rhenck's avatar
    rhenck committed
      constructor(element: Partial<LikertRowElement>) {
        super(element);
    
        if (element.rowLabel) this.rowLabel = { ...element.rowLabel };
    
    rhenck's avatar
    rhenck committed
        if (element.columnCount) this.columnCount = element.columnCount;
        if (element.firstColumnSizeRatio) this.firstColumnSizeRatio = element.firstColumnSizeRatio;
        if (element.verticalButtonAlignment) this.verticalButtonAlignment = element.verticalButtonAlignment;
    
      hasAnswerScheme(): boolean {
    
        return Boolean(this.getAnswerScheme);
    
      getAnswerScheme(): AnswerScheme {
    
        return {
          id: this.id,
          type: 'integer',
          format: '',
          multiple: false,
    
          nullable: !this.value && this.value !== 0,
    
          values: this.getAnswerSchemeValues(),
    
          valuesComplete: true
        };
      }
    
    
      private getAnswerSchemeValues(): AnswerSchemeValue[] {
    
          {
            value: !this.value && this.value !== 0 ? 'null' : (this.value as number + 1).toString(),
    
            label: InputElement.stripHTML(this.rowLabel.text)
    
          } // TODO Image
    
      getElementComponent(): Type<ElementComponent> {
    
        return LikertRadioButtonGroupComponent;
      }
    }