From 0e72bde6bea274fc342b21c9b31b6f21f9ff63e0 Mon Sep 17 00:00:00 2001
From: rhenck <richard.henck@iqb.hu-berlin.de>
Date: Wed, 24 May 2023 18:47:56 +0200
Subject: [PATCH] [editor] Limit element IDs to 20 characters and no spaces

---
 .../element-model-properties.component.html                   | 3 ++-
 projects/editor/src/app/services/unit.service.ts              | 4 ++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/projects/editor/src/app/components/properties-panel/model-properties-tab/element-model-properties.component.html b/projects/editor/src/app/components/properties-panel/model-properties-tab/element-model-properties.component.html
index d631783ed..9ef43d179 100644
--- a/projects/editor/src/app/components/properties-panel/model-properties-tab/element-model-properties.component.html
+++ b/projects/editor/src/app/components/properties-panel/model-properties-tab/element-model-properties.component.html
@@ -2,7 +2,8 @@
   <mat-form-field appearance="fill">
     <mat-label>{{'propertiesPanel.id' | translate }}</mat-label>
     <input matInput type="text" *ngIf="selectedElements.length === 1" [value]="combinedProperties.id"
-           (input)="updateModel.emit({property: 'id', value: $any($event.target).value })">
+           (input)="updateModel.emit({property: 'id', value: $any($event.target).value })"
+           (keydown.space)="$event.preventDefault();">
     <input matInput type="text" disabled *ngIf="selectedElements.length > 1" [value]="'Muss eindeutig sein'">
   </mat-form-field>
 
diff --git a/projects/editor/src/app/services/unit.service.ts b/projects/editor/src/app/services/unit.service.ts
index 6dbb1ca36..158793a38 100644
--- a/projects/editor/src/app/services/unit.service.ts
+++ b/projects/editor/src/app/services/unit.service.ts
@@ -243,6 +243,10 @@ export class UnitService {
       if (property === 'id') {
         if (!this.idService.isIdAvailable((value as string))) { // prohibit existing IDs
           this.messageService.showError(this.translateService.instant('idTaken'));
+        } else if ((value as string).length > 20) {
+          this.messageService.showError('ID länger als 20 Zeichen');
+        } else if ((value as string).includes(' ')) {
+          this.messageService.showError('ID enthält unerlaubtes Leerzeichen');
         } else {
           this.idService.removeId(element.id);
           this.idService.addID(value as string);
-- 
GitLab