Skip to content
Snippets Groups Projects
slider.ts 1.98 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { Type } from '@angular/core';
    
    rhenck's avatar
    rhenck committed
      BasicStyles, InputElement, PositionedUIElement, PositionProperties, AnswerScheme, AnswerSchemeValue, UIElement
    
    } from 'common/models/elements/element';
    
    import { ElementComponent } from 'common/directives/element-component.directive';
    import { SliderComponent } from 'common/components/input-elements/slider.component';
    
    export class SliderElement extends InputElement implements PositionedUIElement {
      minValue: number = 0;
      maxValue: number = 100;
      showValues: boolean = true;
      barStyle: boolean = false;
      thumbLabel: boolean = false;
      position: PositionProperties;
      styling: BasicStyles & {
        lineHeight: number;
      };
    
    
    rhenck's avatar
    rhenck committed
      constructor(element: Partial<SliderElement>) {
        super(element);
    
    rhenck's avatar
    rhenck committed
        if (element.minValue) this.minValue = element.minValue;
    
        if (element.maxValue !== undefined) this.maxValue = element.maxValue;
        if (element.showValues !== undefined) this.showValues = element.showValues;
    
    rhenck's avatar
    rhenck committed
        if (element.barStyle) this.barStyle = element.barStyle;
        if (element.thumbLabel) this.thumbLabel = element.thumbLabel;
    
    rhenck's avatar
    rhenck committed
        this.position = UIElement.initPositionProps(element.position);
    
        this.styling = {
    
    rhenck's avatar
    rhenck committed
          ...UIElement.initStylingProps({
    
            backgroundColor: 'transparent',
            lineHeight: 135,
            ...element.styling
          })
        };
      }
    
    
      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(),
    
      private getAnswerSchemeValues(): AnswerSchemeValue[] {
    
        return Array.from({ length: (this.maxValue + 1 - this.minValue) }, (_, index) => (
          { value: (index + this.minValue).toString(), label: (index + this.minValue).toString() }
    
        )) as AnswerSchemeValue[];
    
      getElementComponent(): Type<ElementComponent> {
    
        return SliderComponent;
      }
    }