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

[editor] Fix combined property logic and copy values before setting them

The copy is needed to not have cross references between elements.
parent 45e321f9
No related branches found
No related tags found
No related merge requests found
export abstract class Copy {
static getCopy(objectToCopy: any): any {
if (objectToCopy instanceof Array) {
return [...objectToCopy];
}
if (objectToCopy instanceof Object) {
return { ...objectToCopy };
}
return objectToCopy;
}
}
......@@ -31,7 +31,10 @@ export class ElementModelPropertiesComponent {
addOption(property: string, value: string): void {
(this.combinedProperties[property] as string[]).push(value);
this.updateModel.emit({ property: property, value: this.combinedProperties[property] as string[] });
this.updateModel.emit({
property: property,
value: [...this.combinedProperties[property] as string[]]
});
}
reorderOptions(property: string, event: CdkDragDrop<string[]>): void {
......
......@@ -70,9 +70,8 @@ export class ElementPropertiesComponent implements OnInit, OnDestroy {
Object.keys(this.combinedProperties).forEach((property: keyof UIElement) => {
if (Object.prototype.hasOwnProperty.call(flattenedSelectedElements[i], property)) {
if (Array.isArray(flattenedSelectedElements[i][property])) {
if (flattenedSelectedElements[i][property]!.toString() === this.combinedProperties[property]!.toString()) {
// @ts-ignore TODO
flattenedSelectedElements[property] = flattenedSelectedElements[i][property];
if (flattenedSelectedElements[i][property]?.toString() === this.combinedProperties[property]?.toString()) {
this.combinedProperties[property] = flattenedSelectedElements[i][property];
}
}
if (flattenedSelectedElements[i][property] !== this.combinedProperties[property]) {
......
......@@ -25,6 +25,7 @@ import { LikertElementRow } from '../../../../common/ui-elements/likert/likert-e
import { SelectionService } from './selection.service';
import { ElementFactory } from '../../../../common/util/element.factory';
import { ClozeParser } from '../util/cloze-parser';
import { Copy } from '../../../../common/util/copy';
@Injectable({
providedIn: 'root'
......@@ -260,7 +261,7 @@ export class UnitService {
} else if (property === 'text' && element.type === 'cloze') {
element.setProperty('parts', ClozeParser.createClozeParts(value as string, this.idService));
} else {
element.setProperty(property, value);
element.setProperty(property, Copy.getCopy(value));
}
}
this.elementPropertyUpdated.next();
......
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