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 9eb68971e..2a95291f2 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 @@ -236,8 +236,11 @@ public class ExternalSelectDataPersist extends BaseFieldDataPersist { protected List specifications(ExternalSelectSourceBindingPersist item) { return Arrays.asList( this.spec() - .must(() -> !this.isNull(item.getLabel())) - .failOn(ExternalSelectSourceBindingPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{ExternalSelectSourceBindingPersist._label}, LocaleContextHolder.getLocale())) + .must(() -> !this.isEmpty(item.getLabel())) + .failOn(ExternalSelectSourceBindingPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{ExternalSelectSourceBindingPersist._label}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getValue())) + .failOn(ExternalSelectSourceBindingPersist._value).failWith(messageSource.getMessage("Validation_Required", new Object[]{ExternalSelectSourceBindingPersist._value}, LocaleContextHolder.getLocale())) ); } } diff --git a/dmp-backend/web/src/main/resources/messages.properties b/dmp-backend/web/src/main/resources/messages.properties index 2df90f56c..b7bff3873 100644 --- a/dmp-backend/web/src/main/resources/messages.properties +++ b/dmp-backend/web/src/main/resources/messages.properties @@ -20,4 +20,5 @@ Validation_Required={0} is required Validation_OverPosting=Too much info Validation_MaxLength={0} too long Validation_UnexpectedValue=Unexpected value in field {0} -Validation_Unique= {0} must be unique \ No newline at end of file +Validation_Unique= {0} must be unique +Validation.LowerThanMin= value must be equal or larger than {0} \ No newline at end of file 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 b7dd9fbcb..57779ab5d 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 @@ -66,7 +66,7 @@
+ [validationErrorModel]="validationErrorModel" [rootPath]="rootPath + 'fields[' + i + '].'" (delete)="deleteField(i)">
  • 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 4d5a0c756..5b13e71d6 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 @@ -573,7 +573,7 @@ export class DescriptionTemplateEditorCompositeFieldComponent extends BaseCompon } } - (this.form.get('fields')).push(new DescriptionTemplateFieldEditorModel().fromModel(field).buildForm()); + (this.form.get('fields')).push(new DescriptionTemplateFieldEditorModel(this.validationErrorModel).fromModel(field).buildForm({rootPath: this.rootPath + 'fields[' + this.fieldsArray.length + '].'})); this.inputs.init(); // fieldForm.get('viewStyle').get('renderStyle').updateValueAndValidity(); // fieldForm.get('data').updateValueAndValidity(); 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 7989c535c..c1d412f01 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 @@ -1,6 +1,6 @@ import { Component, Input, OnInit } from '@angular/core'; import { UntypedFormArray, UntypedFormGroup } from '@angular/forms'; -import { DescriptionTemplateExternalSelectSourceEditorModel } from '../../../description-template-editor.model'; +import { DescriptionTemplateExternalSelectDataEditorModel, DescriptionTemplateExternalSelectSourceEditorModel } from '../../../description-template-editor.model'; 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'; @@ -35,5 +35,12 @@ export class DescriptionTemplateEditorExternalSelectFieldComponent implements On removeSource(index: number) { (this.form.get('data').get('sources')).removeAt(index); + DescriptionTemplateExternalSelectDataEditorModel.reapplyValidators({ + formGroup: this.form?.get('data') as UntypedFormGroup, + rootPath: `${this.rootPath}data.`, + validationErrorModel: this.validationErrorModel + }); + + this.form.get('data').get('sources').markAsDirty(); } } diff --git a/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/radio-box/description-template-editor-radio-box-field.component.ts b/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/radio-box/description-template-editor-radio-box-field.component.ts index 913d69678..ac0984fc7 100644 --- a/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/radio-box/description-template-editor-radio-box-field.component.ts +++ b/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/radio-box/description-template-editor-radio-box-field.component.ts @@ -1,6 +1,6 @@ import { Component, Input, OnInit } from '@angular/core'; import { UntypedFormArray, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms'; -import { DescriptionTemplateRadioBoxOptionEditorModel } from '../../../description-template-editor.model'; +import { DescriptionTemplateRadioBoxDataEditorModel, DescriptionTemplateRadioBoxOptionEditorModel } from '../../../description-template-editor.model'; import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model'; @Component({ @@ -26,6 +26,16 @@ export class DescriptionTemplateEditorRadioBoxFieldComponent implements OnInit { } deleteRow(intex: number) { - if (this.form.get('data').get('options')) { (this.form.get('data').get('options')).removeAt(intex); } + if (this.form.get('data').get('options')) { + (this.form.get('data').get('options')).removeAt(intex); + + DescriptionTemplateRadioBoxDataEditorModel.reapplyRadioBoxValidators({ + formGroup: this.form.get('data') as UntypedFormGroup, + rootPath: `${this.rootPath}data.`, + validationErrorModel: this.validationErrorModel + }); + + this.form.get('data').get('options').markAsDirty(); + } } } diff --git a/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/select/description-template-editor-select-field.component.ts b/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/select/description-template-editor-select-field.component.ts index a65ea98b3..a3e64aa28 100644 --- a/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/select/description-template-editor-select-field.component.ts +++ b/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/select/description-template-editor-select-field.component.ts @@ -1,6 +1,6 @@ import { Component, Input, OnInit } from '@angular/core'; import { UntypedFormArray, UntypedFormGroup } from '@angular/forms'; -import { DescriptionTemplateSelectOptionEditorModel } from '../../../description-template-editor.model'; +import { DescriptionTemplateSelectDataEditorModel, DescriptionTemplateSelectOptionEditorModel } from '../../../description-template-editor.model'; import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model'; @Component({ @@ -24,6 +24,16 @@ export class DescriptionTemplateEditorSelectFieldComponent implements OnInit { } deleteRow(intex: number) { - if (this.form.get('data').get('options')) { (this.form.get('data').get('options')).removeAt(intex); } + if (this.form.get('data').get('options')) { + (this.form.get('data').get('options')).removeAt(intex); + + DescriptionTemplateSelectDataEditorModel.reapplySelectValidators({ + formGroup: this.form?.get('data') as UntypedFormGroup, + rootPath: `${this.rootPath}data.`, + validationErrorModel: this.validationErrorModel + }); + + this.form.get('data').get('options').markAsDirty(); + } } } diff --git a/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/upload/description-template-editor-upload-field.component.ts b/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/upload/description-template-editor-upload-field.component.ts index a996e2b5d..ae5af1f21 100644 --- a/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/upload/description-template-editor-upload-field.component.ts +++ b/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/upload/description-template-editor-upload-field.component.ts @@ -2,7 +2,7 @@ import { Component, Input, OnInit } from '@angular/core'; import { UntypedFormArray, UntypedFormBuilder, UntypedFormControl, UntypedFormGroup } from '@angular/forms'; import { DescriptionTemplateUploadOption } from '@app/core/model/description-template/description-template'; import { ConfigurationService } from "@app/core/services/configuration/configuration.service"; -import { DescriptionTemplateUploadOptionEditorModel } from '../../../description-template-editor.model'; +import { DescriptionTemplateUploadDataEditorModel, DescriptionTemplateUploadOptionEditorModel } from '../../../description-template-editor.model'; import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model'; @Component({ @@ -92,7 +92,18 @@ export class DescriptionTemplateEditorUploadFieldComponent implements OnInit { } deleteRow(index: number) { - if (this.form.get('data').get('types')) { (this.form.get('data').get('types')).removeAt(index); } + if (this.form.get('data').get('types')) { + (this.form.get('data').get('types')).removeAt(index); + DescriptionTemplateUploadDataEditorModel.reapplyUploadDataValidators( + { + formGroup: this.form.get('data') as UntypedFormGroup, + validationErrorModel: this.validationErrorModel, + rootPath: `${this.rootPath}data.`, + } + ); + + this.form.get('data').get('types').markAsDirty(); + } } public getConfiguration() { diff --git a/dmp-frontend/src/app/ui/admin/description-template/editor/components/field/description-template-editor-field.component.html b/dmp-frontend/src/app/ui/admin/description-template/editor/components/field/description-template-editor-field.component.html index 37d52d996..b90307448 100644 --- a/dmp-frontend/src/app/ui/admin/description-template/editor/components/field/description-template-editor-field.component.html +++ b/dmp-frontend/src/app/ui/admin/description-template/editor/components/field/description-template-editor-field.component.html @@ -200,7 +200,7 @@

    {{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.FIELDS.RULES-TITLE' | translate}}

    - + diff --git a/dmp-frontend/src/app/ui/admin/description-template/editor/components/visibility-rule/description-template-editor-visibility-rule.component.ts b/dmp-frontend/src/app/ui/admin/description-template/editor/components/visibility-rule/description-template-editor-visibility-rule.component.ts index 426fcba51..d10646d34 100644 --- a/dmp-frontend/src/app/ui/admin/description-template/editor/components/visibility-rule/description-template-editor-visibility-rule.component.ts +++ b/dmp-frontend/src/app/ui/admin/description-template/editor/components/visibility-rule/description-template-editor-visibility-rule.component.ts @@ -22,6 +22,7 @@ export class DescriptionTemplateEditorRuleComponent implements OnInit { @Input() formArrayOptionsForCheck: UntypedFormArray; @Input() viewOnly: boolean; @Input() validationErrorModel: ValidationErrorModel; + @Input() rootPath: string; options: OptionItem[]; @@ -44,7 +45,13 @@ export class DescriptionTemplateEditorRuleComponent implements OnInit { deleteRule(index) { this.form.removeAt(index); - // TODO akis reply validators fix + this.form.controls?.forEach( + (control, index) => DescriptionTemplateRuleEditorModel.reapplyValidators({ + formGroup: control as UntypedFormGroup, + rootPath: `${this.rootPath}visibilityRules[${index}].`, + validationErrorModel: this.validationErrorModel + }) + ); this.form.markAsDirty();//deactivate guard } 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 dc51b1f6e..104b426a1 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 @@ -688,8 +688,8 @@ export class DescriptionTemplateEditorComponent extends BaseEditor 0){ + const currentSectionFormArray = this.getUpdatedSectionFormArray(parentSections, tceId); + if (currentSectionFormArray != null || currentSectionFormArray != undefined){ + return currentSectionFormArray; + } + } + } + + return null; + } + onRemoveEntry(tce: ToCEntry) { const dialogRef = this.dialog.open(ConfirmationDialogComponent, { @@ -818,7 +840,7 @@ export class DescriptionTemplateEditorComponent extends BaseEditor= 0) { - this._updateSelectedItem(tce); - const parentFormArray = (pages.at(pageIndex).get('sections') as UntypedFormArray).at(parentSectionIndex).get('sections') as UntypedFormArray; - parentFormArray.removeAt(sectionIndex); + // if (sectionIndex >= 0) { + // this._updateSelectedItem(tce); + // const parentFormArray = (pages.at(pageIndex).get('sections') as UntypedFormArray).at(parentSectionIndex).get('sections') as UntypedFormArray; + // parentFormArray.removeAt(sectionIndex); - //update odrinal + // //update odrinal - for (let i = 0; i < parentFormArray.length; i++) { - parentFormArray.at(i).get('ordinal').patchValue(i); + // for (let i = 0; i < parentFormArray.length; i++) { + // parentFormArray.at(i).get('ordinal').patchValue(i); + // } + // } + + for (let j = 0; j < pages.length; j++) { + const parentSections = pages.at(j).get('sections') as UntypedFormArray; + const sectionFormArray = this.getUpdatedSectionFormArray(parentSections, tce.id); + + if (sectionFormArray){ + //update ordinal + for (let i = 0; i < sectionFormArray.length; i++) { + sectionFormArray.at(i).get('ordinal').patchValue(i); + } + break; } } 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 bbc0956e7..d13b2b195 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 @@ -774,8 +774,8 @@ export class DescriptionTemplateFieldEditorModel implements DescriptionTemplateF this.validationErrorModel ).fromModel(item).buildForm({ rootPath: `${rootPath}visibilityRules[${index}].` - }), context.getValidation('visibilityRules') - ) + }) + ), context.getValidation('visibilityRules').validators ) }); } @@ -864,6 +864,42 @@ export class DescriptionTemplateFieldEditorModel implements DescriptionTemplateF validationErrorModel: validationErrorModel }); + if(formGroup?.get('data').get('fieldType').value != undefined){ + switch (formGroup?.get('data').get('fieldType').value) { + case DescriptionTemplateFieldType.UPLOAD: + DescriptionTemplateUploadDataEditorModel.reapplyUploadDataValidators({ + formGroup: formGroup?.get('data') as UntypedFormGroup, + rootPath: `${rootPath}data.`, + validationErrorModel: validationErrorModel + }); + case DescriptionTemplateFieldType.RADIO_BOX: + DescriptionTemplateRadioBoxDataEditorModel.reapplyRadioBoxValidators({ + formGroup: formGroup?.get('data') as UntypedFormGroup, + rootPath: `${rootPath}data.`, + validationErrorModel: validationErrorModel + }); + case DescriptionTemplateFieldType.SELECT: + DescriptionTemplateSelectDataEditorModel.reapplySelectValidators({ + formGroup: formGroup?.get('data') as UntypedFormGroup, + rootPath: `${rootPath}data.`, + validationErrorModel: validationErrorModel + }); + case DescriptionTemplateFieldType.EXTERNAL_SELECT: + DescriptionTemplateExternalSelectDataEditorModel.reapplyValidators({ + formGroup: formGroup?.get('data') as UntypedFormGroup, + rootPath: `${rootPath}data.`, + validationErrorModel: validationErrorModel + }); + case DescriptionTemplateFieldType.EXTERNAL_DATASETS: + DescriptionTemplateExternalDatasetDataEditorModel.reapplyValidators({ + formGroup: formGroup?.get('data') as UntypedFormGroup, + rootPath: `${rootPath}data.`, + validationErrorModel: validationErrorModel + }); + + } + } + (formGroup.get('visibilityRules') as FormArray).controls?.forEach( (control, index) => DescriptionTemplateRuleEditorModel.reapplyValidators({ formGroup: control as UntypedFormGroup, @@ -1227,7 +1263,7 @@ export class DescriptionTemplateExternalSelectDataEditorModel extends Descriptio control?.addValidators(context.getValidation(keyField).validators); }); - (formGroup.get('options') as FormArray).controls?.forEach( + (formGroup.get('sources') as FormArray).controls?.forEach( (control, index) => DescriptionTemplateExternalSelectSourceEditorModel.reapplyValidators({ formGroup: control as UntypedFormGroup, rootPath: `${rootPath}sources[${index}].`, @@ -1559,12 +1595,12 @@ export class DescriptionTemplateRadioBoxDataEditorModel extends DescriptionTempl } static reapplyRadioBoxValidators(params: { - formArray: UntypedFormArray, + formGroup: UntypedFormGroup, validationErrorModel: ValidationErrorModel, rootPath: string }): void { - const { validationErrorModel, rootPath, formArray } = params; - formArray?.controls?.forEach( + const { validationErrorModel, rootPath, formGroup } = params; + (formGroup.get('options') as FormArray).controls?.forEach( (control, index) => DescriptionTemplateRadioBoxOptionEditorModel.reapplyValidators({ formGroup: control as UntypedFormGroup, rootPath: `${rootPath}options[${index}].`, @@ -1705,7 +1741,7 @@ export class DescriptionTemplateSelectDataEditorModel extends DescriptionTemplat return baseContext; } - static reapplyDepedencyValidators(params: { + static reapplySelectValidators(params: { formGroup: UntypedFormGroup, validationErrorModel: ValidationErrorModel, rootPath: string @@ -1867,19 +1903,31 @@ export class DescriptionTemplateUploadDataEditorModel extends DescriptionTemplat } static reapplyUploadDataValidators(params: { - formArray: UntypedFormArray, + formGroup: UntypedFormGroup, validationErrorModel: ValidationErrorModel, rootPath: string }): void { - const { validationErrorModel, rootPath, formArray } = params; - formArray?.controls?.forEach( + const { validationErrorModel, rootPath, formGroup } = params; + + const context = DescriptionTemplateUploadDataEditorModel.createValidationContext({ + rootPath, + validationErrorModel + }); + + (formGroup.get('types') as FormArray).controls?.forEach( (control, index) => DescriptionTemplateUploadOptionEditorModel.reapplyValidators({ formGroup: control as UntypedFormGroup, rootPath: `${rootPath}types[${index}].`, validationErrorModel: validationErrorModel }) ); + + ['maxFileSizeInMB'].forEach(keyField => { + const control = formGroup?.get(keyField); + control?.clearValidators(); + control?.addValidators(context.getValidation(keyField).validators); + }); } }