Skip to content
Snippets Groups Projects
Commit 51fce8b6 authored by rhenck's avatar rhenck
Browse files

Refactor IDService to not know about specific Element (class)

This avoids import cycles.
parent 087ea012
No related branches found
No related tags found
No related merge requests found
import { Unit } from './classes/unit';
import { Page } from './classes/page';
import { Section } from './classes/section';
import { UIElement } from './classes/uIElement';
export class IdService { export class IdService {
private static instance: IdService; private static instance: IdService;
...@@ -38,14 +33,8 @@ export class IdService { ...@@ -38,14 +33,8 @@ export class IdService {
return `${type}_${this.idCounter[type]}`; return `${type}_${this.idCounter[type]}`;
} }
readExistingIDs(unit: Unit): void { addID(id: string): void {
unit.pages.forEach((page: Page) => { this.givenIDs.push(id);
page.sections.forEach((section: Section) => {
section.elements.forEach((element: UIElement) => {
this.givenIDs.push(element.id);
});
});
});
} }
isIdAvailable(value: string): boolean { isIdAvailable(value: string): boolean {
......
...@@ -34,7 +34,13 @@ export class UnitService { ...@@ -34,7 +34,13 @@ export class UnitService {
loadUnitDefinition(unitDefinition: string): void { loadUnitDefinition(unitDefinition: string): void {
if (unitDefinition) { if (unitDefinition) {
this.unitModel = new Unit(JSON.parse(unitDefinition)); this.unitModel = new Unit(JSON.parse(unitDefinition));
IdService.getInstance().readExistingIDs(this.unitModel); this.unitModel.pages.forEach((page: Page) => {
page.sections.forEach((section: Section) => {
section.elements.forEach((element: UIElement) => {
IdService.getInstance().addID(element.id);
});
});
});
this._unit.next(this.unitModel); this._unit.next(this.unitModel);
} }
} }
......
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