Skip to content
Snippets Groups Projects
spell-correct.ts 2.32 KiB
Newer Older
import { Type } from '@angular/core';
import {
rhenck's avatar
rhenck committed
  PositionedUIElement, TextInputElement, TextInputElementProperties, UIElementType
} from 'common/models/elements/element';
import { ElementComponent } from 'common/directives/element-component.directive';
import { SpellCorrectComponent } from 'common/components/input-elements/spell-correct.component';
import { VariableInfo } from '@iqb/responses';
rhenck's avatar
rhenck committed
  BasicStyles, PositionProperties, PropertyGroupGenerators, PropertyGroupValidators
} from 'common/models/elements/property-group-interfaces';
rhenck's avatar
rhenck committed
import { environment } from 'common/environment';
import { InstantiationEror } from 'common/util/errors';
export class SpellCorrectElement extends TextInputElement implements PositionedUIElement, SpellCorrectProperties {
  type: UIElementType = 'spell-correct';
  position: PositionProperties;
  styling: BasicStyles;

rhenck's avatar
rhenck committed
  constructor(element?: SpellCorrectProperties) {
rhenck's avatar
rhenck committed
    if (element && isValid(element)) {
      this.position = { ...element.position };
      this.styling = { ...element.styling };
rhenck's avatar
rhenck committed
    } else {
      if (environment.strictInstantiation) {
        throw new InstantiationEror('Error at SpellCorrect instantiation', element);
      }
      this.dimensions = PropertyGroupGenerators.generateDimensionProps({
        width: 230,
        height: 80,
        ...element?.dimensions
      });
      this.position = PropertyGroupGenerators.generatePositionProps(element?.position);
      this.styling = PropertyGroupGenerators.generateBasicStyleProps(element?.styling);
    }
  getVariableInfos(): VariableInfo[] {
    return [{
      id: this.id,
      type: 'string',
      format: '',
      multiple: false,
      nullable: true,
      valuePositionLabels: [],
      page: '',
  getElementComponent(): Type<ElementComponent> {
    return SpellCorrectComponent;
  }

  getDuplicate(): SpellCorrectElement {
    return new SpellCorrectElement(this);
  }

export interface SpellCorrectProperties extends TextInputElementProperties {
  position: PositionProperties;
  styling: BasicStyles;
}
rhenck's avatar
rhenck committed

function isValid(blueprint?: SpellCorrectProperties): boolean {
  if (!blueprint) return false;
  return PropertyGroupValidators.isValidPosition(blueprint.position) &&
    PropertyGroupValidators.isValidBasicStyles(blueprint.styling);
}