fix dmp blueprint create and blueprint description template validators

This commit is contained in:
amentis 2024-01-24 17:50:34 +02:00
parent 0faa5f731a
commit 8828be7dfa
4 changed files with 18 additions and 19 deletions

View File

@ -4,9 +4,11 @@ import eu.eudat.commons.validation.BaseValidator;
import gr.cite.tools.validation.specification.Specification;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import eu.eudat.model.persist.descriptiontemplatedefinition.FieldPersist;
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;
@ -74,6 +76,8 @@ public class DescriptionTemplatePersist {
this.maxMultiplicity = maxMultiplicity;
}
@Component(DescriptionTemplatePersist.DescriptionTemplatePersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class DescriptionTemplatePersistValidator extends BaseValidator<DescriptionTemplatePersist> {
public static final String ValidatorName = "DmpBlueprint.DescriptionTemplatePersistValidator";

View File

@ -109,6 +109,7 @@
<mat-form-field class="w-100">
<mat-label>{{'DMP-BLUEPRINT-EDITOR.FIELDS.SYSTEM-FIELD' | translate}}</mat-label>
<input matInput disabled value="{{enumUtils.toDmpBlueprintSystemFieldTypeString(field.get('systemFieldType').value)}}" type="text" name="name">
<mat-error *ngIf="field.get('dataType').hasError('backendError')">{{field.get('dataType').getError('backendError').message}}</mat-error>
</mat-form-field>
</div>
<div class="col-auto" *ngIf="field.get('category').value === dmpBlueprintSectionFieldCategory.EXTRA">
@ -170,6 +171,7 @@
<!-- <mat-checkbox [formControl]="section.get('hasTemplates')" (change)="checkForBlueprints($event, sectionIndex)"> -->
<mat-checkbox [formControl]="section.get('hasTemplates')">
{{'DMP-BLUEPRINT-EDITOR.FIELDS.DESCRIPTION-TEMPLATES' | translate}}
<mat-error *ngIf="section.get('hasTemplates').hasError('backendError')">{{section.get('hasTemplates').getError('backendError').message}}</mat-error>
</mat-checkbox>
</div>
</div>
@ -180,8 +182,7 @@
<div class="col-12">
<mat-form-field class="w-100">
<mat-label>{{'DMP-BLUEPRINT-EDITOR.FIELDS.DESCRIPTION-TEMPLATES' | translate}}</mat-label>
<app-multiple-auto-complete [disabled]="formGroup.disabled" [hidePlaceholder]="true" required='false' [configuration]="blueprintsAutoCompleteConfiguration" (optionRemoved)="onRemoveDescritionTemplate($event, sectionIndex)" (optionSelected)="onSelectDescritionTemplate($event, sectionIndex)">
</app-multiple-auto-complete>
<app-multiple-auto-complete [disabled]="formGroup.disabled" [hidePlaceholder]="true" required='false' [configuration]="templatesAutoCompleteConfiguration" (optionRemoved)="onRemoveDescritionTemplate($event, sectionIndex)" (optionSelected)="onSelectDescritionTemplate($event, sectionIndex)"></app-multiple-auto-complete>
</mat-form-field>
</div>
</div>

View File

@ -35,6 +35,8 @@ import { map, takeUntil } from 'rxjs/operators';
import { DescriptionTemplatesInSectionEditorModel, DmpBlueprintDefinitionSectionEditorModel, DmpBlueprintEditorModel, FieldInSectionEditorModel } from './dmp-blueprint-editor.model';
import { DmpBlueprintEditorResolver } from './dmp-blueprint-editor.resolver';
import { DmpBlueprintEditorService } from './dmp-blueprint-editor.service';
import { DescriptionTemplateService } from '@app/core/services/description-template/description-template.service';
import { SingleAutoCompleteConfiguration } from '@app/library/auto-complete/single/single-auto-complete-configuration';
@Component({
@ -55,16 +57,7 @@ export class DmpBlueprintEditorComponent extends BaseEditor<DmpBlueprintEditorMo
public dmpBlueprintSystemFieldTypeEnum = this.enumUtils.getEnumValues<DmpBlueprintSystemFieldType>(DmpBlueprintSystemFieldType);
dmpBlueprintExtraFieldDataType = DmpBlueprintExtraFieldDataType;
public dmpBlueprintExtraFieldDataTypeEnum = this.enumUtils.getEnumValues<DmpBlueprintExtraFieldDataType>(DmpBlueprintExtraFieldDataType);
//TODO refactor
// blueprintsAutoCompleteConfiguration: MultipleAutoCompleteConfiguration = {
// filterFn: this.filterDescriptionTempaltes.bind(this),
// initialItems: (excludedItems: any[]) => this.filterDescriptionTempaltes('').pipe(map(result => result.filter(resultItem => (excludedItems || []).map(x => x.id).indexOf(resultItem.id) === -1))),
// displayFn: (item: DatasetProfileModel) => item.label,
// titleFn: (item: DatasetProfileModel) => item.label,
// subtitleFn: (item: DatasetProfileModel) => item.description,
// popupItemActionIcon: 'visibility'
// };
templatesAutoCompleteConfiguration: SingleAutoCompleteConfiguration
protected get canDelete(): boolean {
return !this.isDeleted && !this.isNew && this.hasPermission(this.authService.permissionEnum.DeleteDmpBlueprint);
@ -103,9 +96,10 @@ export class DmpBlueprintEditorComponent extends BaseEditor<DmpBlueprintEditorMo
private dmpBlueprintEditorService: DmpBlueprintEditorService,
private fileUtils: FileUtils,
private matomoService: MatomoService,
private dmpService: DmpService
private descriptionTemplateService: DescriptionTemplateService
) {
super(dialog, language, formService, router, uiNotificationService, httpErrorHandlingService, filterService, datePipe, route, queryParamsService);
this.templatesAutoCompleteConfiguration = this.descriptionTemplateService.singleAutocompleteConfiguration;
}
ngOnInit(): void {
@ -173,9 +167,9 @@ export class DmpBlueprintEditorComponent extends BaseEditor<DmpBlueprintEditorMo
formSubmit(): void {
this.formService.touchAllFormFields(this.formGroup);
if (!this.isFormValid()) {
return;
}
// if (!this.isFormValid()) {
// return;
// }
this.persistEntity();
}

View File

@ -12,7 +12,7 @@ import { Guid } from "@common/types/guid";
export class DmpBlueprintEditorModel extends BaseEditorModel implements DmpBlueprintPersist {
label: string;
definition: DmpBlueprintDefinitionEditorModel;
definition: DmpBlueprintDefinitionEditorModel = new DmpBlueprintDefinitionEditorModel();
status: DmpBlueprintStatus = DmpBlueprintStatus.Draft;
description: string;
permissions: string[];
@ -285,7 +285,7 @@ export class DmpBlueprintDefinitionSectionEditorModel implements DmpBlueprintDef
)
);
(formGroup.get('fields') as FormArray).controls?.forEach(
(formGroup.get('descriptionTemplates') as FormArray).controls?.forEach(
(control, index) => DescriptionTemplatesInSectionEditorModel.reapplyValidators({
formGroup: control as UntypedFormGroup,
rootPath: `${rootPath}descriptionTemplates[${index}].`,