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 5edff8cc5d0eb3d21fa844126231673459b77822..dfb19837b1514984ff7ba16754565c6decb24f94 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 ec488c13e9548488beb9a8e6a45e8d3518795af0..8e68461c1db863fe8861f81279a301b2ece353d1 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 56065cde7adebbd72496bb2f10ded129ff6aa201..432b25d5a599c3965b1fa5b1e44b6fbe66b3acad 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 5ff9a793928f89c7ee66bb93d79e2ebf66516acb..e69bc9093e1e047c950336301d71453e08f45c40 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:",