Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit d3c6e01f authored by Joze RIHTARSIC's avatar Joze RIHTARSIC
Browse files

Pull request #163: [EDELIVERY-14005] fix property dialog duplicate name

Merge in EDELIVERY/smp from bugfix/EDELIVERY-14005-edit-document-user-is-able-to-add-the-same-property-if-it-has-space-at-the to development

* commit '0fa6bf75':
  [EDELIVERY-14005] fix property dialog duplicate name
parents 0b56ed4d 0fa6bf75
No related branches found
No related tags found
No related merge requests found
Pipeline #216215 failed
......@@ -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"
......
......@@ -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: ''}),
......
......@@ -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';
......
......@@ -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:",
......
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