Skip to content
Snippets Groups Projects
math-field.ts 1.52 KiB
Newer Older
  • Learn to ignore specific revisions
  • rhenck's avatar
    rhenck committed
    import {
    
      InputElement, InputElementProperties, UIElementType
    
    rhenck's avatar
    rhenck committed
    } from 'common/models/elements/element';
    import { Type } from '@angular/core';
    import { ElementComponent } from 'common/directives/element-component.directive';
    import { MathFieldComponent } from 'common/components/input-elements/math-field.component';
    
    import { AnswerScheme } from 'common/models/elements/answer-scheme-interfaces';
    import { BasicStyles, PositionProperties } from 'common/models/elements/property-group-interfaces';
    
    rhenck's avatar
    rhenck committed
    
    
    export class MathFieldElement extends InputElement implements MathFieldProperties {
      type: UIElementType = 'math-field';
    
    rhenck's avatar
    rhenck committed
      enableModeSwitch: boolean = false;
      position: PositionProperties | undefined;
    
      styling: BasicStyles & {
        lineHeight: number;
      };
    
      constructor(element: MathFieldProperties) {
    
    rhenck's avatar
    rhenck committed
        super(element);
    
        this.enableModeSwitch = element.enableModeSwitch;
        this.position = element.position;
        this.styling = element.styling;
    
    rhenck's avatar
    rhenck committed
      }
    
      hasAnswerScheme(): boolean {
        return Boolean(this.getAnswerScheme);
      }
    
      getAnswerScheme(): AnswerScheme {
        return {
          id: this.id,
          type: 'string',
    
          format: 'latex',
    
    rhenck's avatar
    rhenck committed
          multiple: false,
          nullable: !this.value && this.value !== '',
          values: [],
          valuesComplete: false
        };
      }
    
      getElementComponent(): Type<ElementComponent> {
        return MathFieldComponent;
      }
    }
    
    
    export interface MathFieldProperties extends InputElementProperties {
      enableModeSwitch: boolean;
      position?: PositionProperties;
      styling: BasicStyles & {
        lineHeight: number;
      };
    }