From 1a6e776b41432aeed59d8287897e18a113b32eb9 Mon Sep 17 00:00:00 2001 From: amentis Date: Fri, 9 Feb 2024 15:07:15 +0200 Subject: [PATCH] description template validation changes --- .../eu/eudat/commons/enums/FieldType.java | 3 +- .../editor/description-editor.model.ts | 39 +++++++++++++++---- .../form-field-set.component.ts | 10 ++--- .../form-field/form-field.component.html | 12 +++--- 4 files changed, 43 insertions(+), 21 deletions(-) diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/enums/FieldType.java b/dmp-backend/core/src/main/java/eu/eudat/commons/enums/FieldType.java index 97324ed53..9217180f4 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/enums/FieldType.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/enums/FieldType.java @@ -96,7 +96,8 @@ public enum FieldType implements DatabaseEnum { public static boolean isTextType(FieldType fieldType){ return fieldType.equals(FieldType.FREE_TEXT) || fieldType.equals(FieldType.CHECK_BOX) || fieldType.equals(FieldType.TEXT_AREA) || fieldType.equals(FieldType.RICH_TEXT_AREA) || fieldType.equals(FieldType.UPLOAD) || fieldType.equals(FieldType.BOOLEAN_DECISION) || - fieldType.equals(FieldType.RADIO_BOX) || fieldType.equals(FieldType.CURRENCY); + fieldType.equals(FieldType.RADIO_BOX) || fieldType.equals(FieldType.CURRENCY) || fieldType.equals(FieldType.SELECT) || + fieldType.equals(FieldType.INTERNAL_DMP_ENTRIES_DMPS) || fieldType.equals(FieldType.INTERNAL_DMP_ENTRIES_DATASETS); } public static boolean isTextListType(FieldType fieldType){ diff --git a/dmp-frontend/src/app/ui/description/editor/description-editor.model.ts b/dmp-frontend/src/app/ui/description/editor/description-editor.model.ts index 94a95087b..678244664 100644 --- a/dmp-frontend/src/app/ui/description/editor/description-editor.model.ts +++ b/dmp-frontend/src/app/ui/description/editor/description-editor.model.ts @@ -91,7 +91,7 @@ export class DescriptionEditorModel extends BaseEditorModel implements Descripti const { formGroup, validationErrorModel } = params; const control = formGroup?.get('properties'); DescriptionPropertyDefinitionEditorModel.reapplyValidators({ - formArray: control.get('fieldSets') as UntypedFormArray, + formGroup: control.get('fieldSets') as UntypedFormGroup, rootPath: `properties.`, validationErrorModel: validationErrorModel }); @@ -151,12 +151,22 @@ export class DescriptionPropertyDefinitionEditorModel implements DescriptionProp } static reapplyValidators(params: { - formArray: UntypedFormArray, + formGroup: UntypedFormGroup, validationErrorModel: ValidationErrorModel, rootPath: string }): void { - //TODO + const { formGroup, rootPath, validationErrorModel } = params; + + const keys = Object.keys(formGroup.value as Object); + keys.forEach((key) => { + const formArray = formGroup?.get(key); + DescriptionPropertyDefinitionFieldSetEditorModel.reapplyValidators({ + formArray: formArray.get('items') as UntypedFormArray, + rootPath: `${rootPath}fieldSets[${key}].`, + validationErrorModel: validationErrorModel + }) + }); } private calculateProperties(item: DescriptionPropertyDefinition, descriptionTemplate: DescriptionTemplate, descriptionReferences: DescriptionReference[]): Map { @@ -373,13 +383,22 @@ export class DescriptionPropertyDefinitionFieldSetItemEditorModel implements Des validationErrorModel }); - //TODO + const fields = formGroup?.get('fields') as UntypedFormGroup; + const keys = Object.keys(fields.value as Object); + keys.forEach((key) => { + const control = fields?.get(key); + DescriptionFieldEditorModel.reapplyValidators({ + formGroup: control as UntypedFormGroup, + rootPath: `${rootPath}fields.`, + validationErrorModel: validationErrorModel + }) + }); ['comment', 'ordinal'].forEach(keyField => { const control = formGroup?.get(keyField); control?.clearValidators(); control?.addValidators(context.getValidation(keyField).validators); - }) + }); } } @@ -390,7 +409,7 @@ export class DescriptionFieldEditorModel implements DescriptionFieldPersist { dateValue: Date; references: ReferencePersist[]; reference: ReferencePersist; - externalIdentifier?: DescriptionExternalIdentifierEditorModel; + externalIdentifier?: DescriptionExternalIdentifierEditorModel = new DescriptionExternalIdentifierEditorModel(this.validationErrorModel); protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); @@ -428,7 +447,10 @@ export class DescriptionFieldEditorModel implements DescriptionFieldPersist { textListValue: [{ value: this.textListValue, disabled: disabled }, context.getValidation('textListValue').validators], dateValue: [{ value: this.dateValue, disabled: disabled }, context.getValidation('dateValue').validators], references: [{ value: this.references, disabled: disabled }, context.getValidation('references').validators], - reference: [{ value: this.reference, disabled: disabled }, context.getValidation('reference').validators] + reference: [{ value: this.reference, disabled: disabled }, context.getValidation('reference').validators], + externalIdentifier: this.externalIdentifier.buildForm({ + rootPath: `${rootPath}externalIdentifier.` + }), }); } @@ -445,6 +467,7 @@ export class DescriptionFieldEditorModel implements DescriptionFieldPersist { baseValidationArray.push({ key: 'dateValue', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}dateValue`)] }); baseValidationArray.push({ key: 'references', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}references`)] }); baseValidationArray.push({ key: 'reference', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}references`)] }); + baseValidationArray.push({ key: 'externalIdentifier', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}externalIdentifier`)] }); baseContext.validation = baseValidationArray; return baseContext; } @@ -456,7 +479,7 @@ export class DescriptionFieldEditorModel implements DescriptionFieldPersist { }): void { const { formGroup, rootPath, validationErrorModel } = params; - const context = DescriptionPropertyDefinitionFieldSetItemEditorModel.createValidationContext({ + const context = DescriptionFieldEditorModel.createValidationContext({ rootPath, validationErrorModel }); diff --git a/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field-set/form-field-set.component.ts b/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field-set/form-field-set.component.ts index 6feef20bb..d3ed1c9fc 100644 --- a/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field-set/form-field-set.component.ts +++ b/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field-set/form-field-set.component.ts @@ -75,8 +75,8 @@ export class DescriptionFormFieldSetComponent extends BaseComponent { } const item: DescriptionPropertyDefinitionFieldSetEditorModel = new DescriptionPropertyDefinitionEditorModel(this.validationErrorModel).calculateFieldSetProperties(this.fieldSet, null, null); - //TODO: akis - formArray.push((item.buildForm({rootPath: ''}).get('items') as UntypedFormArray).at(0)); + formArray.push((item.buildForm({rootPath: `properties.fieldSets[${this.fieldSet.id}].`}).get('items') as UntypedFormArray).at(0)); + } deleteMultiplicityField(fieldSetIndex: number): void { @@ -86,14 +86,12 @@ export class DescriptionFormFieldSetComponent extends BaseComponent { fieldSet.get('ordinal').setValue(index + 1); }); - //TODO: akis //Reapply validators DescriptionPropertyDefinitionFieldSetEditorModel.reapplyValidators( { - formArray: this.propertiesFormGroup.get('items') as UntypedFormArray, + formArray: formArray, validationErrorModel: this.validationErrorModel, - //TODO - rootPath: '' + rootPath: `properties.fieldSets[${this.fieldSet.id}].` } ); formArray.markAsDirty(); diff --git a/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field/form-field.component.html b/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field/form-field.component.html index c29c404f9..117e7eee6 100644 --- a/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field/form-field.component.html +++ b/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field/form-field.component.html @@ -319,8 +319,8 @@
- {{'GENERAL.VALIDATION.REQUIRED' | translate}} - + {{propertiesFormGroup?.get(field.id).get('externalIdentifier')?.get('identifier').getError('backendError').message}} + {{'GENERAL.VALIDATION.REQUIRED' | translate}} @@ -328,13 +328,13 @@ {{ type.name }} - {{'GENERAL.VALIDATION.REQUIRED' | translate}} - + {{propertiesFormGroup?.get(field.id).get('externalIdentifier')?.get('type').getError('backendError').message}} + {{'GENERAL.VALIDATION.REQUIRED' | translate}}
- {{'GENERAL.VALIDATION.REQUIRED' | translate}} - + {{propertiesFormGroup?.get(field.id).get('externalIdentifier')?.get('identifier').getError('backendError').message}} + {{'GENERAL.VALIDATION.REQUIRED' | translate}}