Newer
Older
import { Injectable } from '@angular/core';
import { TextMarkingService } from './text-marking.service';
DragNDropValueObject,
InputElement,
InputElementValue,
UIElement,
UIElementType
} from 'common/models/elements/element';
import { TextElement } from 'common/models/elements/text/text';
import { AudioElement } from 'common/models/elements/media-elements/audio';
import { VideoElement } from 'common/models/elements/media-elements/video';
import { ImageElement } from 'common/models/elements/media-elements/image';
@Injectable({
providedIn: 'root'
})
export class ElementModelElementCodeMappingService {
dragNDropValueObjects: DragNDropValueObject[] = [];
mapToElementModelValue = (
elementCodeValue: InputElementValue | undefined, elementModel: UIElement
): InputElementValue => {
case 'drop-list':
return (elementCodeValue !== undefined) ?
(elementCodeValue as string[]).map(id => this.getDragNDropValueObjectById(id)) as DragNDropValueObject[] :
(elementModel as InputElement).value;
return (elementCodeValue !== undefined) ?
TextMarkingService
.restoreMarkedTextIndices(elementCodeValue as string[], (elementModel as TextElement).text) :
(elementModel as TextElement).text;
return elementCodeValue !== undefined ?
elementCodeValue as number :
(elementModel as AudioElement).player.playbackTime;
return elementCodeValue !== undefined ?
elementCodeValue as number :
(elementModel as VideoElement).player.playbackTime;
case 'image':
return elementCodeValue !== undefined ?
elementCodeValue as boolean :
(elementModel as ImageElement).magnifierUsed;
case 'radio':
case 'radio-group-images':
case 'dropdown':
case 'toggle-button':
case 'likert-row':
return elementCodeValue !== undefined && elementCodeValue !== null ?
elementCodeValue as number - 1 : (elementModel as InputElement).value;
return elementCodeValue !== undefined ? elementCodeValue : (elementModel as InputElement).value;
mapToElementCodeValue = (elementModelValue: InputElementValue, elementType: UIElementType): InputElementValue => {
switch (elementType) {
return (elementModelValue as DragNDropValueObject[]).map(object => object.id);
case 'text':
return TextMarkingService.getMarkedTextIndices(elementModelValue as string);
case 'radio':
case 'radio-group-images':
case 'dropdown':
case 'toggle-button':
case 'likert-row':
return elementModelValue !== null ? elementModelValue as number + 1 : null;
return elementModelValue;
private getDragNDropValueObjectById(id: string): DragNDropValueObject | undefined {
return this.dragNDropValueObjects.find(dropListValue => dropListValue.id === id);