From 1899d651bb7153472740a8c640ebe78de4c5e6d9 Mon Sep 17 00:00:00 2001
From: jojohoch <joachim.hoch@iqb.hu-berlin.de>
Date: Mon, 24 Jan 2022 15:03:47 +0100
Subject: [PATCH] [editor] Reset IdService when loading a new unit definition

---
 projects/editor/src/app/app.component.ts                   | 3 +++
 .../editor/src/app/components/toolbar/toolbar.component.ts | 7 ++++++-
 projects/editor/src/app/services/id.service.ts             | 4 ++++
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/projects/editor/src/app/app.component.ts b/projects/editor/src/app/app.component.ts
index 8755780ad..7d7276a34 100644
--- a/projects/editor/src/app/app.component.ts
+++ b/projects/editor/src/app/app.component.ts
@@ -4,6 +4,7 @@ import { registerLocaleData } from '@angular/common';
 import localeDe from '@angular/common/locales/de';
 import { VeronaAPIService, VoeStartCommand } from './services/verona-api.service';
 import { UnitService } from './services/unit.service';
+import { IdService } from './services/id.service';
 
 @Component({
   selector: 'editor-aspect',
@@ -21,6 +22,7 @@ export class AppComponent implements OnInit {
   isStandalone = (): boolean => window === window.parent;
 
   constructor(private unitService: UnitService,
+              private idService: IdService,
               private translateService: TranslateService,
               private veronaApiService: VeronaAPIService) {
     translateService.addLangs(['de']);
@@ -30,6 +32,7 @@ export class AppComponent implements OnInit {
   ngOnInit(): void {
     this.veronaApiService.voeStartCommand
       .subscribe((message: VoeStartCommand): void => {
+        this.idService.reset();
         this.unitService.loadUnitDefinition(message.unitDefinition);
       });
     this.veronaApiService.voeGetDefinitionRequest
diff --git a/projects/editor/src/app/components/toolbar/toolbar.component.ts b/projects/editor/src/app/components/toolbar/toolbar.component.ts
index e9e91c3d4..10b5af1a2 100644
--- a/projects/editor/src/app/components/toolbar/toolbar.component.ts
+++ b/projects/editor/src/app/components/toolbar/toolbar.component.ts
@@ -1,5 +1,6 @@
 import { Component } from '@angular/core';
 import { UnitService } from '../../services/unit.service';
+import { IdService } from '../../services/id.service';
 
 @Component({
   selector: 'app-toolbar',
@@ -10,13 +11,17 @@ import { UnitService } from '../../services/unit.service';
   ]
 })
 export class ToolbarComponent {
-  constructor(private unitService: UnitService) { }
+  constructor(
+    private unitService: UnitService,
+    private idService: IdService
+  ) { }
 
   save(): void {
     this.unitService.saveUnit();
   }
 
   async load(): Promise<void> {
+    this.idService.reset();
     await this.unitService.loadUnitFromFile();
   }
 }
diff --git a/projects/editor/src/app/services/id.service.ts b/projects/editor/src/app/services/id.service.ts
index 5622c2656..1c2f3272c 100644
--- a/projects/editor/src/app/services/id.service.ts
+++ b/projects/editor/src/app/services/id.service.ts
@@ -53,4 +53,8 @@ export class IdService { // TODO rename: capitalize
   removeId(id: string): void {
     this.givenIDs.splice(this.givenIDs.indexOf(id, 0), 1);
   }
+
+  reset(): void {
+    this.givenIDs = [];
+  }
 }
-- 
GitLab