Skip to content
Snippets Groups Projects
UnitFactory.ts 5.04 KiB
Newer Older
import {
  AudioElement, ButtonElement,
  CheckboxElement, CompoundElementCorrection, DropdownElement,
  ImageElement, TextElement, RadioButtonGroupElement,
  TextFieldElement, Unit, UnitPage, UnitPageSection, UnitUIElement,
  VideoElement, TextAreaElement
} from '../../../common/unit';
const EXPORTED_MODULE_VERSION = 'iqb-aspect-module@0.1.1';

export function createUnit(): Unit {
    veronaModuleVersion: EXPORTED_MODULE_VERSION,
export function createUnitPage(pageIndex: number): UnitPage {
    id: `page${pageIndex}`,
    sections: [],
    maxWidth: 900,
    backgroundColor: 'white',
    alwaysVisible: false,
    alwaysVisiblePagePosition: 'left',
    alwaysVisibleAspectRatio: 50
  };
}

export function createUnitPageSection(): UnitPageSection {
  return {
    elements: [],
    height: 400,
    backgroundColor: 'white',
    dynamicPositioning: false,
    gridColumnSizes: '1fr 1fr',
    gridRowSizes: '1fr'
export function createUnitUIElement(type: string): UnitUIElement {
  return {
    type,
    id: 'id_placeholder',
    zIndex: 0,
    width: 180,
    height: 60,
    dynamicPositioning: false,
    xPosition: 0,
    yPosition: 0,
    gridColumnStart: 1,
    gridColumnEnd: 2,
    gridRowStart: 1,
    gridRowEnd: 2,
    marginLeft: 0,
    marginRight: 0,
    marginTop: 0,
    marginBottom: 0
rhenck's avatar
rhenck committed
  };
}

rhenck's avatar
rhenck committed
export function createTextUIElement(): Record<string, unknown> {
rhenck's avatar
rhenck committed
  return {
rhenck's avatar
rhenck committed
    fontColor: 'black',
rhenck's avatar
rhenck committed
    font: 'Roboto',
    fontSize: 18,
rhenck's avatar
rhenck committed
    bold: false,
    italic: false,
rhenck's avatar
rhenck committed
    underline: false
rhenck's avatar
rhenck committed
  };
}

rhenck's avatar
rhenck committed
export function createInputUIElement(
  label: string, value: string | number | boolean | undefined
): Record<string, unknown> {
rhenck's avatar
rhenck committed
  return {
    label: label,
    value: value,
    requiredWarnMessage: 'Eingabe erforderlich'
rhenck's avatar
rhenck committed
export function createSurfaceUIElement(): Record<string, unknown> {
    backgroundColor: 'lightgrey'
export function createTextElement(): TextElement {
rhenck's avatar
rhenck committed
  return <TextElement>{
    text: '<p>Lorem ipsum dolor sit amet</p>',
    fontColor: 'black',
    font: 'Roboto',
    bold: false,
    italic: false,
    underline: false,
    highlightable: false,
rhenck's avatar
rhenck committed
    ...createUnitUIElement('text'),
    ...createSurfaceUIElement(),
    backgroundColor: 'transparent',
  };
}

export function createButtonElement(): ButtonElement {
rhenck's avatar
rhenck committed
  return <ButtonElement>{
    label: 'Knopf Beschriftung',
    action: undefined,
rhenck's avatar
rhenck committed
    ...createUnitUIElement('button'),
    ...createTextUIElement(),
  };
}

export function createTextfieldElement(): TextFieldElement {
  return <TextFieldElement>{
    appearance: 'outline',
    minLength: undefined,
    minLengthWarnMessage: 'Eingabe zu kurz',
    maxLength: undefined,
    maxLengthWarnMessage: 'Eingabe zu lang',
    pattern: '',
    patternWarnMessage: 'Eingabe entspricht nicht der Vorgabe',
rhenck's avatar
rhenck committed
    ...createUnitUIElement('text-field'),
    ...createInputUIElement('Beispiel Beschriftung', ''),
rhenck's avatar
rhenck committed
    ...createTextUIElement(),
    ...createSurfaceUIElement(),
    backgroundColor: 'transparent',
export function createTextareaElement(): TextAreaElement {
  return <TextAreaElement>{
    resizeEnabled: false,
    appearance: 'outline',
rhenck's avatar
rhenck committed
    ...createUnitUIElement('text-area'),
    ...createInputUIElement('Beispiel Beschriftung', ''),
rhenck's avatar
rhenck committed
    ...createTextUIElement(),
    ...createSurfaceUIElement(),
    backgroundColor: 'transparent',
export function createCheckboxElement(): CheckboxElement {
  return <CheckboxElement>{
rhenck's avatar
rhenck committed
    ...createUnitUIElement('checkbox'),
    ...createInputUIElement('Beschriftung', false),
rhenck's avatar
rhenck committed
    ...createTextUIElement(),
    ...createSurfaceUIElement(),
    backgroundColor: 'transparent'
  };
}

export function createDropdownElement(): DropdownElement {
rhenck's avatar
rhenck committed
  return <DropdownElement><unknown>{
    options: [],
    allowUnset: false,
rhenck's avatar
rhenck committed
    ...createUnitUIElement('dropdown'),
    ...createInputUIElement('Beschriftung', undefined),
rhenck's avatar
rhenck committed
    ...createTextUIElement(),
    ...createSurfaceUIElement(),
    height: 83
  };
}

export function createRadioButtonGroupElement(): RadioButtonGroupElement {
rhenck's avatar
rhenck committed
  return <RadioButtonGroupElement><unknown>{
    options: [],
    alignment: 'column',
rhenck's avatar
rhenck committed
    ...createUnitUIElement('radio'),
    ...createInputUIElement('Beschriftung Optionsfeld', undefined),
rhenck's avatar
rhenck committed
    ...createTextUIElement(),
    ...createSurfaceUIElement(),
    backgroundColor: 'transparent'
  };
}

export function createImageElement(imageSrc: string): ImageElement {
  return {
    src: imageSrc,
    ...createUnitUIElement('image'),
    height: 100
  };
}

export function createAudioElement(audioSrc: string): AudioElement {
  return {
    src: audioSrc,
    ...createUnitUIElement('audio')
  };
}

export function createVideoElement(videoSrc: string): VideoElement {
  return {
    src: videoSrc,
    ...createUnitUIElement('video'),
    height: 100
  };
}

export function createCorrectionElement(): CompoundElementCorrection {
  return {
    text: 'dummy',
    sentences: [],
    ...createUnitUIElement('correction')
  };
}