From 0fa6bf752b2fa5abe958142bf6b2400dcf6a9f16 Mon Sep 17 00:00:00 2001 From: RIHTARSIC Joze <joze.rihtarsic@ext.ec.europa.eu> Date: Thu, 10 Oct 2024 14:04:26 +0200 Subject: [PATCH] [EDELIVERY-14005] fix property dialog duplicate name --- .../document-property-dialog.component.html | 5 +++++ .../document-property-dialog.component.ts | 16 ++++++++++------ .../enums/utils/PropertyValueTypeEnumUtil.ts | 3 ++- smp-angular/src/assets/i18n/en.json | 1 + 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/smp-angular/src/app/common/dialogs/document-property-dialog/document-property-dialog.component.html b/smp-angular/src/app/common/dialogs/document-property-dialog/document-property-dialog.component.html index 5edff8cc5..dfb19837b 100644 --- a/smp-angular/src/app/common/dialogs/document-property-dialog/document-property-dialog.component.html +++ b/smp-angular/src/app/common/dialogs/document-property-dialog/document-property-dialog.component.html @@ -13,6 +13,11 @@ style="color:red; font-size: 70%"> {{ "document.property.dialog.error.property.already.exists" | translate }} </div> + <div + *ngIf="propertyForm.controls['property'].hasError('pattern')" + style="color:red; font-size: 70%"> + {{ "document.property.dialog.error.property.name.pattern" | translate }} + </div> </mat-form-field> <mat-form-field *ngIf="propertyForm.controls['type'].value !== PropertyValueTypeEnum.BOOLEAN" diff --git a/smp-angular/src/app/common/dialogs/document-property-dialog/document-property-dialog.component.ts b/smp-angular/src/app/common/dialogs/document-property-dialog/document-property-dialog.component.ts index ec488c13e..8e68461c1 100644 --- a/smp-angular/src/app/common/dialogs/document-property-dialog/document-property-dialog.component.ts +++ b/smp-angular/src/app/common/dialogs/document-property-dialog/document-property-dialog.component.ts @@ -8,12 +8,12 @@ import { AbstractControl, UntypedFormBuilder, UntypedFormControl, - UntypedFormGroup + UntypedFormGroup, Validators } from "@angular/forms"; import { AlertMessageService -} from "../../../common/alert-message/alert-message.service"; -import {EntityStatus} from "../../../common/enums/entity-status.enum"; +} from "../../alert-message/alert-message.service"; +import {EntityStatus} from "../../enums/entity-status.enum"; import {HttpClient} from "@angular/common/http"; import {DocumentPropertyRo} from "../../model/document-property-ro.model"; import {PropertyValueTypeEnum} from "../../enums/property-value-type.enum"; @@ -32,6 +32,7 @@ export class DocumentPropertyDialogComponent { public propertyTypes: string[] = Object.keys(PropertyValueTypeEnum) protected readonly PropertyValueTypeEnum = PropertyValueTypeEnum; + // regular expression pattern must start with a letter and contain only letters, numbers and dots and must not be bigger than 255 characters long formTitle = ""; current: DocumentPropertyRo; propertyForm: UntypedFormGroup; @@ -46,7 +47,10 @@ export class DocumentPropertyDialogComponent { } return (c: AbstractControl): { [key: string]: any } => { - if (c.value && c.value !== exception && list.includes(c.value)) + console.log("Check if value is in list: " + c.value + " type: " + typeof c.value); + let inputVal = typeof c?.value?.trim === "function" ? c.value.trim().toLowerCase() : c.value; + if (inputVal&& inputVal !== exception + && list.includes(inputVal)) return {'notInList': {valid: false}}; return null; } @@ -68,8 +72,8 @@ export class DocumentPropertyDialogComponent { (async () => this.updateFormTitle())(); this.propertyForm = fb.group({ - 'property': new UntypedFormControl({value: '', readonly: true}, [ - this.notInList(this.allPropertyNames, this.current.property)]), + 'property': new UntypedFormControl({value: '', readonly: true,}, [ + this.notInList(this.allPropertyNames, this.current.property), Validators.pattern(PropertyValueTypeEnumUtil.PROPERTY_NAME_PATTERN)] ), 'desc': new UntypedFormControl({value: '', readonly: true}, null), 'type': new UntypedFormControl({value: '', readonly: true}, null), 'value': new UntypedFormControl({value: ''}), diff --git a/smp-angular/src/app/common/enums/utils/PropertyValueTypeEnumUtil.ts b/smp-angular/src/app/common/enums/utils/PropertyValueTypeEnumUtil.ts index 56065cde7..432b25d5a 100644 --- a/smp-angular/src/app/common/enums/utils/PropertyValueTypeEnumUtil.ts +++ b/smp-angular/src/app/common/enums/utils/PropertyValueTypeEnumUtil.ts @@ -9,6 +9,8 @@ import {PropertyValueTypeEnum} from "../property-value-type.enum"; */ export class PropertyValueTypeEnumUtil { + // property name pattern. It must start with a letter and can contain letters, numbers and dots and must not be bigger than 255 characters long! + public static readonly PROPERTY_NAME_PATTERN = '^[a-zA-Z][a-zA-Z0-9.]{0,254}$'; static getKeyNames(): Array<string> { return Object.keys(PropertyValueTypeEnum).filter(k => typeof PropertyValueTypeEnum[k as any] === "number"); @@ -19,7 +21,6 @@ export class PropertyValueTypeEnumUtil { } static getDescription(enumItem: PropertyValueTypeEnum): string { - console.log("Get description for row " + enumItem) switch (enumItem) { case PropertyValueTypeEnum.STRING: return 'String'; diff --git a/smp-angular/src/assets/i18n/en.json b/smp-angular/src/assets/i18n/en.json index 5ff9a7939..e69bc9093 100644 --- a/smp-angular/src/assets/i18n/en.json +++ b/smp-angular/src/assets/i18n/en.json @@ -38,6 +38,7 @@ "document.property.dialog.button.ok": "OK", "document.property.dialog.button.cancel": "Cancel", "document.property.dialog.error.property.already.exists": "The property name already exists!", + "document.property.dialog.error.property.name.pattern": "Property name start with letter and contain only letters, digits, and dots and must be shorter than 255 characters.", "document.property.dialog.label.close": "Close", "document.property.dialog.label.property.description": "Property Description:", "document.property.dialog.label.property.name": "Property name:", -- GitLab