description template validation changes

This commit is contained in:
amentis 2024-02-09 15:07:15 +02:00
parent 510ec954fa
commit 1a6e776b41
4 changed files with 43 additions and 21 deletions

View File

@ -96,7 +96,8 @@ public enum FieldType implements DatabaseEnum<String> {
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){

View File

@ -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<string, DescriptionPropertyDefinitionFieldSetEditorModel> {
@ -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
});

View File

@ -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();

View File

@ -319,8 +319,8 @@
<div class="row align-items-baseline">
<mat-form-field class="col-md-4">
<input matInput class="col-md-12" [formControl]="propertiesFormGroup?.get(field.id).get('externalIdentifier')?.get('identifier')" placeholder="{{(field.data.label) + (isRequired? ' *': '')}}" [required]="isRequired">
<mat-error *ngIf="propertiesFormGroup?.get(field.id).get('externalIdentifier')?.get('identifier').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}
</mat-error>
<mat-error *ngIf="propertiesFormGroup?.get(field.id).get('externalIdentifier')?.get('identifier').hasError('backendError')">{{propertiesFormGroup?.get(field.id).get('externalIdentifier')?.get('identifier').getError('backendError').message}}</mat-error>
<mat-error *ngIf="propertiesFormGroup?.get(field.id).get('externalIdentifier')?.get('identifier').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
<mat-form-field class="col-md-4">
<mat-select class="col-md-12" [formControl]="propertiesFormGroup?.get(field.id).get('externalIdentifier')?.get('type')" [placeholder]="('TYPES.DATASET-PROFILE-VALIDATOR.REPOSITORIES-PLACEHOLDER' | translate) + (isRequired? ' *': '')">
@ -328,13 +328,13 @@
{{ type.name }}
</mat-option>
</mat-select>
<mat-error *ngIf="propertiesFormGroup?.get(field.id).get('externalIdentifier')?.get('type').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}
</mat-error>
<mat-error *ngIf="propertiesFormGroup?.get(field.id).get('externalIdentifier')?.get('type').hasError('backendError')">{{propertiesFormGroup?.get(field.id).get('externalIdentifier')?.get('type').getError('backendError').message}}</mat-error>
<mat-error *ngIf="propertiesFormGroup?.get(field.id).get('externalIdentifier')?.get('type').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
<div class="col-md-2">
<button type="button" mat-button class="lightblue-btn" (click)="validateId()" [disabled]="propertiesFormGroup?.get(field.id).get('externalIdentifier')?.get('identifier').disabled">{{ "TYPES.DATASET-PROFILE-VALIDATOR.ACTION" | translate }}</button>
<mat-error *ngIf="propertiesFormGroup?.get(field.id).get('externalIdentifier')?.get('identifier').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}
</mat-error>
<mat-error *ngIf="propertiesFormGroup?.get(field.id).get('externalIdentifier')?.get('identifier').hasError('backendError')">{{propertiesFormGroup?.get(field.id).get('externalIdentifier')?.get('identifier').getError('backendError').message}}</mat-error>
<mat-error *ngIf="propertiesFormGroup?.get(field.id).get('externalIdentifier')?.get('identifier').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</div>
<div class="col-md-1">
<mat-progress-spinner *ngIf="validationIcon === 'loading'" mode="indeterminate" [diameter]="24"></mat-progress-spinner>