From fc756a17807770a8fee45d1035b7ab944cfe9469 Mon Sep 17 00:00:00 2001 From: amentis Date: Mon, 5 Feb 2024 17:59:11 +0200 Subject: [PATCH] description templates validation fixes (in progress) --- .../MultiplicityPersist.java | 27 ++- .../fielddata/ExternalSelectDataPersist.java | 15 +- .../fielddata/UploadDataPersist.java | 9 +- ...late-editor-composite-field.component.html | 7 +- ...mplate-editor-composite-field.component.ts | 3 + ...mplate-editor-default-value.component.html | 8 + ...ditor-external-select-field.component.html | 2 +- ...-editor-external-select-field.component.ts | 8 +- ...late-editor-radio-box-field.component.html | 8 +- ...mplate-editor-radio-box-field.component.ts | 11 +- ...-template-editor-select-field.component.ts | 8 +- ...emplate-editor-upload-field.component.html | 10 +- ...-template-editor-upload-field.component.ts | 8 +- ...ption-template-editor-field.component.html | 11 +- ...ription-template-editor-field.component.ts | 11 +- ...ate-editor-section-fieldset.component.html | 4 +- ...plate-editor-section-fieldset.component.ts | 3 + ...ion-template-editor-section.component.html | 2 +- ...late-editor-visibility-rule.component.html | 3 +- ...mplate-editor-visibility-rule.component.ts | 6 +- ...description-template-editor.component.html | 8 +- .../description-template-editor.component.ts | 219 +++++++++++------- .../description-template-editor.model.ts | 35 +-- .../editor/reference-editor.component.html | 2 +- .../editor/reference-editor.model.ts | 2 +- dmp-frontend/src/assets/i18n/en.json | 4 +- 26 files changed, 295 insertions(+), 139 deletions(-) diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/MultiplicityPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/MultiplicityPersist.java index 435259d7e..41b9cf86d 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/MultiplicityPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/MultiplicityPersist.java @@ -4,18 +4,23 @@ import eu.eudat.commons.validation.BaseValidator; import gr.cite.tools.validation.specification.Specification; import eu.eudat.convention.ConventionService; import eu.eudat.errorcode.ErrorThesaurusProperties; -import org.apache.commons.compress.utils.Lists; import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.MessageSource; import org.springframework.context.annotation.Scope; +import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Component; +import java.util.Arrays; import java.util.List; public class MultiplicityPersist { private Integer min = null; + public static final String _min = "min"; private Integer max = null; + public static final String _max = "max"; + private String placeholder = null; @@ -59,8 +64,11 @@ public class MultiplicityPersist { public static final String ValidatorName = "DescriptionTemplate.MultiplicityValidator"; - protected MultiplicityValidator(ConventionService conventionService, ErrorThesaurusProperties errors) { + private final MessageSource messageSource; + + protected MultiplicityValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { super(conventionService, errors); + this.messageSource = messageSource; } @Override @@ -70,7 +78,20 @@ public class MultiplicityPersist { @Override protected List specifications(MultiplicityPersist item) { - return Lists.newArrayList(); + return Arrays.asList( + this.spec() + .iff(() -> !this.isNull(item.getMin())) + .must(() -> item.getMin() >= 0) + .failOn(MultiplicityPersist._min).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{MultiplicityPersist._min}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isNull(item.getMax())) + .must(() -> item.getMax() >= 0) + .failOn(MultiplicityPersist._max).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{MultiplicityPersist._max}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isNull(item.getMax())) + .must(() -> !this.isNull(item.getMin()) && (item.getMax() >= item.getMin())) + .failOn(MultiplicityPersist._max).failWith(messageSource.getMessage("Validation.LowerThanMin", new Object[]{MultiplicityPersist._min}, LocaleContextHolder.getLocale())) + ); } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/ExternalSelectDataPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/ExternalSelectDataPersist.java index a469fdc44..9eb68971e 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/ExternalSelectDataPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/ExternalSelectDataPersist.java @@ -161,7 +161,10 @@ public class ExternalSelectDataPersist extends BaseFieldDataPersist { protected List specifications(ExternalSelectSourcePersist item) { return Arrays.asList( this.spec() - .must(() -> !this.isNull(item.getUrl())) + .must(() -> !this.isEmpty(item.getMethod())) + .failOn(ExternalSelectSourcePersist._method).failWith(messageSource.getMessage("Validation_Required", new Object[]{ExternalSelectSourcePersist._method}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getUrl())) .failOn(ExternalSelectSourcePersist._url).failWith(messageSource.getMessage("Validation_Required", new Object[]{ExternalSelectSourcePersist._url}, LocaleContextHolder.getLocale())), this.spec() .iff(() -> !this.isNull(item.getHasAuth()) && item.getHasAuth()) @@ -314,8 +317,14 @@ public class ExternalSelectDataPersist extends BaseFieldDataPersist { protected List specifications(ExternalSelectAuthDataPersist item) { return Arrays.asList( this.spec() - .must(() -> !this.isNull(item.getUrl())) - .failOn(ExternalSelectAuthDataPersist._url).failWith(messageSource.getMessage("Validation_Required", new Object[]{ExternalSelectAuthDataPersist._url}, LocaleContextHolder.getLocale())) + .must(() -> !this.isEmpty(item.getUrl())) + .failOn(ExternalSelectAuthDataPersist._url).failWith(messageSource.getMessage("Validation_Required", new Object[]{ExternalSelectAuthDataPersist._url}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getMethod())) + .failOn(ExternalSelectAuthDataPersist._method).failWith(messageSource.getMessage("Validation_Required", new Object[]{ExternalSelectAuthDataPersist._method}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getType())) + .failOn(ExternalSelectAuthDataPersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{ExternalSelectAuthDataPersist._type}, LocaleContextHolder.getLocale())) ); } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/UploadDataPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/UploadDataPersist.java index a4b003bac..986e5d260 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/UploadDataPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/UploadDataPersist.java @@ -63,8 +63,15 @@ public class UploadDataPersist extends BaseFieldDataPersist { List specifications = getBaseSpecifications(item); specifications.addAll(Arrays.asList( this.spec() - .must(() -> !this.isNull(item.getTypes())) + .must(() -> !this.isListNullOrEmpty(item.getTypes())) .failOn(UploadDataPersist._types).failWith(messageSource.getMessage("Validation_Required", new Object[]{UploadDataPersist._types}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getMaxFileSizeInMB())) + .failOn(UploadDataPersist._maxFileSizeInMB).failWith(messageSource.getMessage("Validation_Required", new Object[]{UploadDataPersist._maxFileSizeInMB}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isNull(item.getMaxFileSizeInMB())) + .must(() -> item.getMaxFileSizeInMB() > 0 && item.getMaxFileSizeInMB() <= 10) + .failOn(UploadDataPersist._maxFileSizeInMB).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{UploadDataPersist._maxFileSizeInMB}, LocaleContextHolder.getLocale())), this.navSpec() .iff(() -> !this.isNull(item.getTypes())) .on(UploadDataPersist._types) diff --git a/dmp-frontend/src/app/ui/admin/description-template/editor/components/composite-field/description-template-editor-composite-field.component.html b/dmp-frontend/src/app/ui/admin/description-template/editor/components/composite-field/description-template-editor-composite-field.component.html index 749c912a5..b7dd9fbcb 100644 --- a/dmp-frontend/src/app/ui/admin/description-template/editor/components/composite-field/description-template-editor-composite-field.component.html +++ b/dmp-frontend/src/app/ui/admin/description-template/editor/components/composite-field/description-template-editor-composite-field.component.html @@ -34,12 +34,12 @@
- + {{form.get('multiplicity').get('min').getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}} - + {{form.get('multiplicity').get('max').getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}} @@ -65,7 +65,8 @@
- +
  • diff --git a/dmp-frontend/src/app/ui/admin/description-template/editor/components/composite-field/description-template-editor-composite-field.component.ts b/dmp-frontend/src/app/ui/admin/description-template/editor/components/composite-field/description-template-editor-composite-field.component.ts index 1350463c9..4d5a0c756 100644 --- a/dmp-frontend/src/app/ui/admin/description-template/editor/components/composite-field/description-template-editor-composite-field.component.ts +++ b/dmp-frontend/src/app/ui/admin/description-template/editor/components/composite-field/description-template-editor-composite-field.component.ts @@ -28,6 +28,7 @@ import { debounceTime, delay, map, takeUntil, tap } from 'rxjs/operators'; import { GENERAL_ANIMATIONS } from '../../animations/animations'; import { EditorCustomValidators } from '../../custom-validators/editor-custom-validators'; import { DescriptionTemplateFieldEditorModel, DescriptionTemplateRuleEditorModel, DescriptionTemplateSectionEditorModel } from '../../description-template-editor.model'; +import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model'; @Component({ selector: 'app-description-template-editor-composite-field-component', @@ -46,6 +47,8 @@ export class DescriptionTemplateEditorCompositeFieldComponent extends BaseCompon @Input() numbering: string; @Input() hasFocus: boolean = false; @ViewChild("inputs") inputs: TransitionGroupComponent; + @Input() validationErrorModel: ValidationErrorModel; + @Input() rootPath: string; showPreview: boolean = true; previewDirty: boolean = false; diff --git a/dmp-frontend/src/app/ui/admin/description-template/editor/components/default-value/description-template-editor-default-value.component.html b/dmp-frontend/src/app/ui/admin/description-template/editor/components/default-value/description-template-editor-default-value.component.html index be0e1f7dd..f44fa5a1f 100644 --- a/dmp-frontend/src/app/ui/admin/description-template/editor/components/default-value/description-template-editor-default-value.component.html +++ b/dmp-frontend/src/app/ui/admin/description-template/editor/components/default-value/description-template-editor-default-value.component.html @@ -12,6 +12,7 @@ | translate}} + {{form.getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}} @@ -22,6 +23,7 @@ {{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.DEFAULT-VALUES.CHECK-BOX.CHECKED' | translate}} {{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.DEFAULT-VALUES.CHECK-BOX.UNCHECKED' | translate}} + {{form.getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}} @@ -32,6 +34,7 @@ {{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.DEFAULT-VALUES.NONE' | translate }} {{opt.get('label').value}} + {{form.getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}} @@ -39,6 +42,7 @@ {{placeHolder}} + {{form.getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}} @@ -49,6 +53,7 @@ {{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.DEFAULT-VALUES.NONE' | translate}} {{opt.get('label').value}} + {{form.getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}} @@ -56,6 +61,7 @@ {{placeHolder}} + {{form.getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}} @@ -63,6 +69,7 @@ {{placeHolder}} + {{form.getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}} @@ -73,6 +80,7 @@ + {{form.getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}} diff --git a/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/external-select/description-template-editor-external-select-field.component.html b/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/external-select/description-template-editor-external-select-field.component.html index 0a22a829d..319cf0202 100644 --- a/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/external-select/description-template-editor-external-select-field.component.html +++ b/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/external-select/description-template-editor-external-select-field.component.html @@ -77,7 +77,7 @@ {{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.FIELDS.FIELD-AUTOCOMPLETE-URL' | translate}} - {{singleForm.get('auth').get('method').getError('backendError').message}} + {{singleForm.get('auth').get('url').getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}} diff --git a/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/external-select/description-template-editor-external-select-field.component.ts b/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/external-select/description-template-editor-external-select-field.component.ts index c1d082200..7989c535c 100644 --- a/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/external-select/description-template-editor-external-select-field.component.ts +++ b/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/external-select/description-template-editor-external-select-field.component.ts @@ -4,6 +4,7 @@ import { DescriptionTemplateExternalSelectSourceEditorModel } from '../../../des import { EnumUtils } from '@app/core/services/utilities/enum-utils.service'; import { DescriptionTemplateExternalSelectHttpMethodType } from '@app/core/common/enum/description-template-external-select-http-method-type'; import { DescriptionTemplateExternalSelectAuthType } from '@app/core/common/enum/description-template-external-select-auth-type'; +import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model'; @Component({ selector: 'app-description-template-editor-external-select-field-component', @@ -13,6 +14,9 @@ import { DescriptionTemplateExternalSelectAuthType } from '@app/core/common/enum export class DescriptionTemplateEditorExternalSelectFieldComponent implements OnInit { @Input() form: UntypedFormGroup; + @Input() validationErrorModel: ValidationErrorModel; + @Input() rootPath: string; + methodTypeValues = this.enumUtils.getEnumValues(DescriptionTemplateExternalSelectHttpMethodType); authTypeValues = this.enumUtils.getEnumValues(DescriptionTemplateExternalSelectAuthType); @@ -24,7 +28,9 @@ export class DescriptionTemplateEditorExternalSelectFieldComponent implements On } addSource() { - (this.form.get('data').get('sources')).push(new DescriptionTemplateExternalSelectSourceEditorModel().buildForm()); + const externalDataset = new DescriptionTemplateExternalSelectSourceEditorModel(this.validationErrorModel); + const externalSelectArray = this.form.get('data').get('sources') as UntypedFormArray; + externalSelectArray.push(externalDataset.buildForm({rootPath: this.rootPath + 'data.sources[' + externalSelectArray.length + '].'})); } removeSource(index: number) { diff --git a/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/radio-box/description-template-editor-radio-box-field.component.html b/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/radio-box/description-template-editor-radio-box-field.component.html index 084d5c032..255585aef 100644 --- a/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/radio-box/description-template-editor-radio-box-field.component.html +++ b/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/radio-box/description-template-editor-radio-box-field.component.html @@ -18,13 +18,13 @@
    {{'DATASET-PROFILE-EDITOR.STEPS.FORM.FIELD.FIELDS.FIELD-RADIO-BOX-LABEL' | translate}} - - {{form.get('data').get('options').get(''+i).get('label').getError('backendError').message}} + + {{option.get('label').getError('backendError').message}} {{'DATASET-PROFILE-EDITOR.STEPS.FORM.FIELD.FIELDS.FIELD-RADIO-BOX-VALUE' | translate}} - - {{form.get('data').get('options').get(''+i).get('value').getError('backendError').message}} + + {{option.get('value').getError('backendError').message}}
    @@ -212,7 +213,8 @@
- +
@@ -225,6 +227,8 @@
{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.PAGE-INFO.ACTIONS.NOTHING-HERE-HINT'| translate}} +

{{'DMP-BLUEPRINT-EDITOR.FIELDS-REQUIRED' | translate}}

+

{{formGroup.get('definition').get('pages').getError('backendError').message}}

diff --git a/dmp-frontend/src/app/ui/admin/description-template/editor/description-template-editor.component.ts b/dmp-frontend/src/app/ui/admin/description-template/editor/description-template-editor.component.ts index e314e7b01..dc51b1f6e 100644 --- a/dmp-frontend/src/app/ui/admin/description-template/editor/description-template-editor.component.ts +++ b/dmp-frontend/src/app/ui/admin/description-template/editor/description-template-editor.component.ts @@ -70,6 +70,7 @@ export class DescriptionTemplateEditorComponent extends BaseEditor = new Map(); userFormControl = new FormControl(); + rootPath: string = null; // selectedSystemFields: Array = []; @@ -571,18 +572,19 @@ export class DescriptionTemplateEditorComponent extends BaseEditor x.get('id')?.value === parent.id).get('sections') as UntypedFormArray; + for (let i = 0; i < pages?.length; i++) { + let page = pages.at(i); + let pageId = page.get('id').value; + + if (pageId == parent.id) { + pageIndex = i; + break; + } + } + sectionsArray = pages.controls.find(x => x.get('id')?.value === parent.id).get('sections') as UntypedFormArray; try { const max = sectionsArray.controls.map(control => control.get('ordinal').value) .reduce((a, b) => Math.max(a, b)); @@ -605,10 +616,26 @@ export class DescriptionTemplateEditorComponent extends BaseEditor 0){ + pageIndex = j; + break; + } + } + let parentSectionRootPath = ''; + if(sectionIndexes.length > 0){ + sectionIndexes.forEach(index => { + parentSectionRootPath = parentSectionRootPath + 'sections[' + index +'].' + }); + } + sectionsArray = parent.form.get('sections') as UntypedFormArray; //adding page parent MAYBE NOT NEEDED @@ -619,7 +646,7 @@ export class DescriptionTemplateEditorComponent extends BaseEditor 0){ + pageIndex = j; + break; } } - if (sectionIndex > -1) { + let parentSectionRootPath = ''; + if(sectionIndexes.length > 0){ + sectionIndexes.forEach(index => { + parentSectionRootPath = parentSectionRootPath + 'sections[' + index +'].' + }); + } + if (sectionIndexes.length > 0) { //create one field form fieldset const field: DescriptionTemplateFieldEditorModel = new DescriptionTemplateFieldEditorModel(this.editorModel.validationErrorModel); field.id = Guid.create().toString(); field.ordinal = 0;//first filed in the fields list - // const fieldForm = field.buildForm(); - // fieldForm.setValidators(this.customFieldValidator()); - // fieldForm.get('viewStyle').get('renderStyle').setValidators(Validators.required); - - // fieldSet.fields.push(field); - // field.ordinal = fieldSet.fields.length-1; const fieldSetsArray = parent.form.get('fieldSets') as UntypedFormArray - const fieldForm = field.buildForm({ rootPath: 'definition.sections[' + sectionIndex + '].fieldSets[' + fieldSetsArray.length + '].fields[' + 0 + '].' }); + //store rootPath for next levels/components + this.rootPath = 'definition.pages['+ pageIndex +'].'+ parentSectionRootPath+ 'fieldSets[' + fieldSetsArray.length + '].fields[' + 0 + '].'; + const fieldForm = field.buildForm({ rootPath: this.rootPath}); //give fieldset id and ordinal const fieldSet: DescriptionTemplateFieldSetEditorModel = new DescriptionTemplateFieldSetEditorModel(this.editorModel.validationErrorModel); @@ -680,7 +702,7 @@ export class DescriptionTemplateEditorComponent extends BaseEditor 0){ + const indexes: number[]= this.findSectionIndex(parentSections, parentId); + if (indexes && indexes.length > 0){ + indexes.unshift(i); + return indexes; + } + } + } + + return null; + } onRemoveEntry(tce: ToCEntry) { @@ -719,12 +761,12 @@ export class DescriptionTemplateEditorComponent extends BaseEditor { - if (section.get('page').value === tce.id) { - sectionsIndexToBeRemoved.push(idx); - } - }); - - if (sectionsIndexToBeRemoved.length) { - sectionsIndexToBeRemoved.reverse().forEach(index => { - sections.removeAt(index); - }); - } //update page ordinals for (let i = 0; i < pages.length; i++) { @@ -772,30 +797,29 @@ export class DescriptionTemplateEditorComponent extends BaseEditor= 0) { //section found + if (sectionIndex >= 0) { //section found - const sections = (this.formGroup.get('definition').get('sections') as UntypedFormArray); + const sections = pages.at(pageIndex).get('sections') as UntypedFormArray; //remove section this._updateSelectedItem(tce); - sections.removeAt(index); + sections.removeAt(sectionIndex); //update ordinal for (let i = 0; i < sections.length; i++) { @@ -804,19 +828,42 @@ export class DescriptionTemplateEditorComponent extends BaseEditor= 0) { + + // let parentFormArray = tce.form.parent as UntypedFormArray; + + // for (let i = 0; i < parentFormArray.length; i++) { + // let section = parentFormArray.at(i); + + // if (section.get('id').value == tce.id) { + // index = i; + // break; + // } + // } + if (sectionIndex >= 0) { this._updateSelectedItem(tce); - parentFormArray.removeAt(index); + const parentFormArray = (pages.at(pageIndex).get('sections') as UntypedFormArray).at(parentSectionIndex).get('sections') as UntypedFormArray; + parentFormArray.removeAt(sectionIndex); //update odrinal @@ -877,14 +924,30 @@ export class DescriptionTemplateEditorComponent extends BaseEditor { + // if (section.get('id').value === tce.id) { + // isFirstLevel = true; + // } + // }); + let isFirstLevel: boolean = false; - firstLevelSections.controls.forEach(section => { - if (section.get('id').value === tce.id) { - isFirstLevel = true; + for (let j = 0; j < pages.length; j++) { + const sections = pages.at(j).get('sections') as UntypedFormArray; + for (let i = 0; i < sections?.length; i++) { + let section = sections.at(i); + let sectionId = section.get('id').value; + + if (sectionId == tce.id) { + isFirstLevel = true; + break; + } } - }); + } + let parentId = null; if (isFirstLevel) { diff --git a/dmp-frontend/src/app/ui/admin/description-template/editor/description-template-editor.model.ts b/dmp-frontend/src/app/ui/admin/description-template/editor/description-template-editor.model.ts index c674862a9..bbc0956e7 100644 --- a/dmp-frontend/src/app/ui/admin/description-template/editor/description-template-editor.model.ts +++ b/dmp-frontend/src/app/ui/admin/description-template/editor/description-template-editor.model.ts @@ -18,7 +18,7 @@ export class DescriptionTemplateEditorModel extends BaseEditorModel implements D language: string; type: Guid; status: DescriptionTemplateStatus = DescriptionTemplateStatus.Draft; - definition: DescriptionTemplateDefinitionEditorModel = new DescriptionTemplateDefinitionEditorModel(); + definition: DescriptionTemplateDefinitionEditorModel = new DescriptionTemplateDefinitionEditorModel(this.validationErrorModel); users: UserDescriptionTemplateEditorModel[] = []; permissions: string[]; @@ -229,8 +229,8 @@ export class DescriptionTemplateDefinitionEditorModel implements DescriptionTemp this.validationErrorModel ).fromModel(item).buildForm({ rootPath: `${rootPath}pages[${index}].` - }), context.getValidation('pages') - ) + }) + ), context.getValidation('pages').validators ), }); } @@ -311,8 +311,8 @@ export class DescriptionTemplatePageEditorModel implements DescriptionTemplatePa this.validationErrorModel ).fromModel(item).buildForm({ rootPath: `${rootPath}sections[${index}].` - }), context.getValidation('sections') - ) + }) + ), context.getValidation('sections').validators ), }); } @@ -428,8 +428,8 @@ export class DescriptionTemplateSectionEditorModel implements DescriptionTemplat this.validationErrorModel ).fromModel(item).buildForm({ rootPath: `${rootPath}sections[${index}].` - }), context.getValidation('sections') - ) + }) + ), context.getValidation('sections').validators ), fieldSets: this.formBuilder.array( (this.fieldSets ?? []).map( @@ -437,8 +437,8 @@ export class DescriptionTemplateSectionEditorModel implements DescriptionTemplat this.validationErrorModel ).fromModel(item).buildForm({ rootPath: `${rootPath}fieldSets[${index}].` - }), context.getValidation('fieldSets') - ) + }) + ), context.getValidation('fieldSets').validators ) }); } @@ -509,7 +509,7 @@ export class DescriptionTemplateFieldSetEditorModel implements DescriptionTempla description: string; extendedDescription: string; additionalInformation: string; - multiplicity: DescriptionTemplateMultiplicityEditorModel = new DescriptionTemplateMultiplicityEditorModel(); + multiplicity: DescriptionTemplateMultiplicityEditorModel = new DescriptionTemplateMultiplicityEditorModel(this.validationErrorModel); hasCommentField: boolean = false; fields: DescriptionTemplateFieldEditorModel[] = []; @@ -567,8 +567,8 @@ export class DescriptionTemplateFieldSetEditorModel implements DescriptionTempla this.validationErrorModel ).fromModel(item).buildForm({ rootPath: `${rootPath}fields[${index}].` - }), context.getValidation('fields') - ) + }) + ), context.getValidation('fields').validators ) }); } @@ -722,7 +722,7 @@ export class DescriptionTemplateFieldEditorModel implements DescriptionTemplateF visibilityRules: DescriptionTemplateRuleEditorModel[] = []; validations: DescriptionTemplateFieldValidationType[] = []; includeInExport: boolean = false; - data: DescriptionTemplateLabelDataEditorModel = new DescriptionTemplateLabelDataEditorModel(); + data: DescriptionTemplateLabelDataEditorModel = new DescriptionTemplateLabelDataEditorModel(this.validationErrorModel); protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); @@ -1242,9 +1242,9 @@ export class DescriptionTemplateExternalSelectSourceEditorModel implements Descr url: string; method: string; optionsRoot: string; - sourceBinding: DescriptionTemplateExternalSelectSourceBindingEditorModel = new DescriptionTemplateExternalSelectSourceBindingEditorModel(); + sourceBinding: DescriptionTemplateExternalSelectSourceBindingEditorModel = new DescriptionTemplateExternalSelectSourceBindingEditorModel(this.validationErrorModel); hasAuth: boolean; - auth: DescriptionTemplateExternalSelectAuthDataEditorModel = new DescriptionTemplateExternalSelectAuthDataEditorModel(); + auth: DescriptionTemplateExternalSelectAuthDataEditorModel = new DescriptionTemplateExternalSelectAuthDataEditorModel(this.validationErrorModel); protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); constructor( @@ -1849,8 +1849,9 @@ export class DescriptionTemplateUploadDataEditorModel extends DescriptionTemplat this.validationErrorModel ).fromModel(item).buildForm({ rootPath: `${rootPath}types[${index}].` - }), context.getValidation('types') - ))); + }) + ), context.getValidation('types').validators + )); return formGroup; } diff --git a/dmp-frontend/src/app/ui/admin/reference/editor/reference-editor.component.html b/dmp-frontend/src/app/ui/admin/reference/editor/reference-editor.component.html index b514d918e..73b029153 100644 --- a/dmp-frontend/src/app/ui/admin/reference/editor/reference-editor.component.html +++ b/dmp-frontend/src/app/ui/admin/reference/editor/reference-editor.component.html @@ -139,7 +139,7 @@
{{'REFERENCE-EDITOR.FIELDS.VALUE' | translate}} - + {{field.get('value').getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}} diff --git a/dmp-frontend/src/app/ui/admin/reference/editor/reference-editor.model.ts b/dmp-frontend/src/app/ui/admin/reference/editor/reference-editor.model.ts index 93ec43129..32bda05f1 100644 --- a/dmp-frontend/src/app/ui/admin/reference/editor/reference-editor.model.ts +++ b/dmp-frontend/src/app/ui/admin/reference/editor/reference-editor.model.ts @@ -220,7 +220,7 @@ export class FieldEditorModel implements FieldPersist { baseValidationArray.push({ key: 'code', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}code`)] }); baseValidationArray.push({ key: 'dataType', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}dataType`)] }); - baseValidationArray.push({ key: 'value', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}value`)] }); + baseValidationArray.push({ key: 'value', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}value`)] }); baseContext.validation = baseValidationArray; return baseContext; diff --git a/dmp-frontend/src/assets/i18n/en.json b/dmp-frontend/src/assets/i18n/en.json index 3579d37ce..cc87a0fc8 100644 --- a/dmp-frontend/src/assets/i18n/en.json +++ b/dmp-frontend/src/assets/i18n/en.json @@ -574,7 +574,9 @@ "PRODUCED": "Produced dataset", "REUSED": "Reused dataset", "OTHER": "Other" - } + }, + "FIELD-LABEL": "Label", + "FIELD-MULTIPLE-SELECT": "Multiple Select" }, "ERROR-MESSAGES": { "FIELD-OTHER-SOURCES-REQUIRED": "At least one source must be provided.",