Skip to content
Snippets Groups Projects
Commit 1b1a1122 authored by rhenck's avatar rhenck
Browse files

Fix reading of DropListSimple valueIds

Now checks when creating or updating object if IDs are okay.
parent 0c249d57
No related branches found
No related tags found
No related merge requests found
import { ElementFactory } from 'common/util/element.factory'; import { ElementFactory } from 'common/util/element.factory';
import { BasicStyles, InputElement } from 'common/models/elements/element'; import { BasicStyles, DragNDropValueObject, InputElement, UIElementValue } from 'common/models/elements/element';
import { Type } from '@angular/core'; import { Type } from '@angular/core';
import { ElementComponent } from 'common/directives/element-component.directive'; import { ElementComponent } from 'common/directives/element-component.directive';
import { import {
DropListSimpleComponent DropListSimpleComponent
} from 'common/components/compound-elements/cloze/cloze-child-elements/drop-list-simple.component'; } from 'common/components/compound-elements/cloze/cloze-child-elements/drop-list-simple.component';
import { IDManager } from 'common/util/id-manager';
export class DropListSimpleElement extends InputElement { export class DropListSimpleElement extends InputElement {
value: DragNDropValueObject[] = [];
connectedTo: string[] = []; connectedTo: string[] = [];
copyOnDrop: boolean = false; copyOnDrop: boolean = false;
highlightReceivingDropList: boolean = false; highlightReceivingDropList: boolean = false;
...@@ -17,7 +19,9 @@ export class DropListSimpleElement extends InputElement { ...@@ -17,7 +19,9 @@ export class DropListSimpleElement extends InputElement {
constructor(element: Partial<DropListSimpleElement>, ...args: unknown[]) { constructor(element: Partial<DropListSimpleElement>, ...args: unknown[]) {
super({ width: 150, height: 30, ...element }, ...args); super({ width: 150, height: 30, ...element }, ...args);
this.value = element.value || []; if (element.value) {
this.value = DropListSimpleElement.checkAndRepairValueIDs(element.value);
}
if (element.connectedTo) this.connectedTo = element.connectedTo; if (element.connectedTo) this.connectedTo = element.connectedTo;
if (element.copyOnDrop) this.copyOnDrop = element.copyOnDrop; if (element.copyOnDrop) this.copyOnDrop = element.copyOnDrop;
if (element.highlightReceivingDropList) this.highlightReceivingDropList = element.highlightReceivingDropList; if (element.highlightReceivingDropList) this.highlightReceivingDropList = element.highlightReceivingDropList;
...@@ -30,6 +34,25 @@ export class DropListSimpleElement extends InputElement { ...@@ -30,6 +34,25 @@ export class DropListSimpleElement extends InputElement {
}; };
} }
setProperty(property: string, value: UIElementValue) {
if (property === 'value') {
this.value = DropListSimpleElement.checkAndRepairValueIDs(value as DragNDropValueObject[]);
} else {
super.setProperty(property, value);
}
}
private static checkAndRepairValueIDs(valueList: DragNDropValueObject[]): DragNDropValueObject[] {
valueList.forEach(valueObject => {
if (IDManager.getInstance().isIdAvailable(valueObject.id)) {
IDManager.getInstance().addID(valueObject.id);
} else {
valueObject.id = IDManager.getInstance().getNewID('value');
}
});
return valueList;
}
getComponentFactory(): Type<ElementComponent> { getComponentFactory(): Type<ElementComponent> {
return DropListSimpleComponent; return DropListSimpleComponent;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment