description template validation changes
This commit is contained in:
parent
510ec954fa
commit
1a6e776b41
|
@ -96,7 +96,8 @@ public enum FieldType implements DatabaseEnum<String> {
|
||||||
public static boolean isTextType(FieldType fieldType){
|
public static boolean isTextType(FieldType fieldType){
|
||||||
return fieldType.equals(FieldType.FREE_TEXT) || fieldType.equals(FieldType.CHECK_BOX) || fieldType.equals(FieldType.TEXT_AREA) ||
|
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.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){
|
public static boolean isTextListType(FieldType fieldType){
|
||||||
|
|
|
@ -91,7 +91,7 @@ export class DescriptionEditorModel extends BaseEditorModel implements Descripti
|
||||||
const { formGroup, validationErrorModel } = params;
|
const { formGroup, validationErrorModel } = params;
|
||||||
const control = formGroup?.get('properties');
|
const control = formGroup?.get('properties');
|
||||||
DescriptionPropertyDefinitionEditorModel.reapplyValidators({
|
DescriptionPropertyDefinitionEditorModel.reapplyValidators({
|
||||||
formArray: control.get('fieldSets') as UntypedFormArray,
|
formGroup: control.get('fieldSets') as UntypedFormGroup,
|
||||||
rootPath: `properties.`,
|
rootPath: `properties.`,
|
||||||
validationErrorModel: validationErrorModel
|
validationErrorModel: validationErrorModel
|
||||||
});
|
});
|
||||||
|
@ -151,12 +151,22 @@ export class DescriptionPropertyDefinitionEditorModel implements DescriptionProp
|
||||||
}
|
}
|
||||||
|
|
||||||
static reapplyValidators(params: {
|
static reapplyValidators(params: {
|
||||||
formArray: UntypedFormArray,
|
formGroup: UntypedFormGroup,
|
||||||
validationErrorModel: ValidationErrorModel,
|
validationErrorModel: ValidationErrorModel,
|
||||||
rootPath: string
|
rootPath: string
|
||||||
}): void {
|
}): 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> {
|
private calculateProperties(item: DescriptionPropertyDefinition, descriptionTemplate: DescriptionTemplate, descriptionReferences: DescriptionReference[]): Map<string, DescriptionPropertyDefinitionFieldSetEditorModel> {
|
||||||
|
@ -373,13 +383,22 @@ export class DescriptionPropertyDefinitionFieldSetItemEditorModel implements Des
|
||||||
validationErrorModel
|
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 => {
|
['comment', 'ordinal'].forEach(keyField => {
|
||||||
const control = formGroup?.get(keyField);
|
const control = formGroup?.get(keyField);
|
||||||
control?.clearValidators();
|
control?.clearValidators();
|
||||||
control?.addValidators(context.getValidation(keyField).validators);
|
control?.addValidators(context.getValidation(keyField).validators);
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -390,7 +409,7 @@ export class DescriptionFieldEditorModel implements DescriptionFieldPersist {
|
||||||
dateValue: Date;
|
dateValue: Date;
|
||||||
references: ReferencePersist[];
|
references: ReferencePersist[];
|
||||||
reference: ReferencePersist;
|
reference: ReferencePersist;
|
||||||
externalIdentifier?: DescriptionExternalIdentifierEditorModel;
|
externalIdentifier?: DescriptionExternalIdentifierEditorModel = new DescriptionExternalIdentifierEditorModel(this.validationErrorModel);
|
||||||
|
|
||||||
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
|
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
|
||||||
|
|
||||||
|
@ -428,7 +447,10 @@ export class DescriptionFieldEditorModel implements DescriptionFieldPersist {
|
||||||
textListValue: [{ value: this.textListValue, disabled: disabled }, context.getValidation('textListValue').validators],
|
textListValue: [{ value: this.textListValue, disabled: disabled }, context.getValidation('textListValue').validators],
|
||||||
dateValue: [{ value: this.dateValue, disabled: disabled }, context.getValidation('dateValue').validators],
|
dateValue: [{ value: this.dateValue, disabled: disabled }, context.getValidation('dateValue').validators],
|
||||||
references: [{ value: this.references, disabled: disabled }, context.getValidation('references').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: 'dateValue', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}dateValue`)] });
|
||||||
baseValidationArray.push({ key: 'references', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}references`)] });
|
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: 'reference', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}references`)] });
|
||||||
|
baseValidationArray.push({ key: 'externalIdentifier', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}externalIdentifier`)] });
|
||||||
baseContext.validation = baseValidationArray;
|
baseContext.validation = baseValidationArray;
|
||||||
return baseContext;
|
return baseContext;
|
||||||
}
|
}
|
||||||
|
@ -456,7 +479,7 @@ export class DescriptionFieldEditorModel implements DescriptionFieldPersist {
|
||||||
}): void {
|
}): void {
|
||||||
|
|
||||||
const { formGroup, rootPath, validationErrorModel } = params;
|
const { formGroup, rootPath, validationErrorModel } = params;
|
||||||
const context = DescriptionPropertyDefinitionFieldSetItemEditorModel.createValidationContext({
|
const context = DescriptionFieldEditorModel.createValidationContext({
|
||||||
rootPath,
|
rootPath,
|
||||||
validationErrorModel
|
validationErrorModel
|
||||||
});
|
});
|
||||||
|
|
|
@ -75,8 +75,8 @@ export class DescriptionFormFieldSetComponent extends BaseComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
const item: DescriptionPropertyDefinitionFieldSetEditorModel = new DescriptionPropertyDefinitionEditorModel(this.validationErrorModel).calculateFieldSetProperties(this.fieldSet, null, null);
|
const item: DescriptionPropertyDefinitionFieldSetEditorModel = new DescriptionPropertyDefinitionEditorModel(this.validationErrorModel).calculateFieldSetProperties(this.fieldSet, null, null);
|
||||||
//TODO: akis
|
formArray.push((item.buildForm({rootPath: `properties.fieldSets[${this.fieldSet.id}].`}).get('items') as UntypedFormArray).at(0));
|
||||||
formArray.push((item.buildForm({rootPath: ''}).get('items') as UntypedFormArray).at(0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteMultiplicityField(fieldSetIndex: number): void {
|
deleteMultiplicityField(fieldSetIndex: number): void {
|
||||||
|
@ -86,14 +86,12 @@ export class DescriptionFormFieldSetComponent extends BaseComponent {
|
||||||
fieldSet.get('ordinal').setValue(index + 1);
|
fieldSet.get('ordinal').setValue(index + 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
//TODO: akis
|
|
||||||
//Reapply validators
|
//Reapply validators
|
||||||
DescriptionPropertyDefinitionFieldSetEditorModel.reapplyValidators(
|
DescriptionPropertyDefinitionFieldSetEditorModel.reapplyValidators(
|
||||||
{
|
{
|
||||||
formArray: this.propertiesFormGroup.get('items') as UntypedFormArray,
|
formArray: formArray,
|
||||||
validationErrorModel: this.validationErrorModel,
|
validationErrorModel: this.validationErrorModel,
|
||||||
//TODO
|
rootPath: `properties.fieldSets[${this.fieldSet.id}].`
|
||||||
rootPath: ''
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
formArray.markAsDirty();
|
formArray.markAsDirty();
|
||||||
|
|
|
@ -319,8 +319,8 @@
|
||||||
<div class="row align-items-baseline">
|
<div class="row align-items-baseline">
|
||||||
<mat-form-field class="col-md-4">
|
<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">
|
<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 *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>
|
<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>
|
||||||
<mat-form-field class="col-md-4">
|
<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? ' *': '')">
|
<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 }}
|
{{ type.name }}
|
||||||
</mat-option>
|
</mat-option>
|
||||||
</mat-select>
|
</mat-select>
|
||||||
<mat-error *ngIf="propertiesFormGroup?.get(field.id).get('externalIdentifier')?.get('type').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}
|
<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>
|
<mat-error *ngIf="propertiesFormGroup?.get(field.id).get('externalIdentifier')?.get('type').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
<div class="col-md-2">
|
<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>
|
<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 *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>
|
<mat-error *ngIf="propertiesFormGroup?.get(field.id).get('externalIdentifier')?.get('identifier').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-1">
|
<div class="col-md-1">
|
||||||
<mat-progress-spinner *ngIf="validationIcon === 'loading'" mode="indeterminate" [diameter]="24"></mat-progress-spinner>
|
<mat-progress-spinner *ngIf="validationIcon === 'loading'" mode="indeterminate" [diameter]="24"></mat-progress-spinner>
|
||||||
|
|
Loading…
Reference in New Issue