add dmp blueprint prefilling source and validation prefilling source fixes
This commit is contained in:
parent
141d6346fb
commit
dad32207e3
|
@ -37,6 +37,10 @@ public class SectionEntity {
|
|||
@XmlElement(name = "descriptionTemplate")
|
||||
private List<DescriptionTemplateEntity> descriptionTemplates;
|
||||
|
||||
@XmlElementWrapper(name = "prefillingSourcesIds")
|
||||
@XmlElement(name = "id")
|
||||
private List<UUID> prefillingSourcesIds;
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
@ -86,6 +90,14 @@ public class SectionEntity {
|
|||
this.descriptionTemplates = descriptionTemplates;
|
||||
}
|
||||
|
||||
public List<UUID> getPrefillingSourcesIds() {
|
||||
return prefillingSourcesIds;
|
||||
}
|
||||
|
||||
public void setPrefillingSourcesIds(List<UUID> prefillingSourcesIds) {
|
||||
this.prefillingSourcesIds = prefillingSourcesIds;
|
||||
}
|
||||
|
||||
public List<FieldEntity> getAllField(){
|
||||
return this.getFields() != null ? this.getFields() : new ArrayList<>();
|
||||
}
|
||||
|
|
|
@ -4,9 +4,13 @@ import eu.eudat.authorization.AuthorizationFlags;
|
|||
import eu.eudat.commons.enums.DmpBlueprintFieldCategory;
|
||||
import eu.eudat.commons.types.dmpblueprint.*;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.PrefillingSourceEntity;
|
||||
import eu.eudat.model.builder.BaseBuilder;
|
||||
import eu.eudat.model.builder.PrefillingSourceBuilder;
|
||||
import eu.eudat.model.dmpblueprintdefinition.Section;
|
||||
import eu.eudat.query.PrefillingSourceQuery;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.fieldset.FieldSet;
|
||||
import gr.cite.tools.logging.DataLogEntry;
|
||||
|
@ -24,13 +28,15 @@ import java.util.*;
|
|||
public class SectionBuilder extends BaseBuilder<Section, SectionEntity> {
|
||||
|
||||
private final BuilderFactory builderFactory;
|
||||
private final QueryFactory queryFactory;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
@Autowired
|
||||
public SectionBuilder(
|
||||
ConventionService conventionService, BuilderFactory builderFactory) {
|
||||
ConventionService conventionService, BuilderFactory builderFactory, QueryFactory queryFactory) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(SectionBuilder.class)));
|
||||
this.builderFactory = builderFactory;
|
||||
this.queryFactory = queryFactory;
|
||||
}
|
||||
|
||||
public SectionBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
|
@ -48,6 +54,7 @@ public class SectionBuilder extends BaseBuilder<Section, SectionEntity> {
|
|||
//Not Bulk Build because is XML no interaction with db
|
||||
FieldSet descriptionTemplatesFields = fields.extractPrefixed(this.asPrefix(Section._descriptionTemplates));
|
||||
FieldSet fieldsFields = fields.extractPrefixed(this.asPrefix(Section._fields));
|
||||
FieldSet prefillingSourcesFields = fields.extractPrefixed(this.asPrefix(Section._prefillingSources));
|
||||
|
||||
List<Section> models = new ArrayList<>();
|
||||
for (SectionEntity d : data) {
|
||||
|
@ -67,6 +74,10 @@ public class SectionBuilder extends BaseBuilder<Section, SectionEntity> {
|
|||
List<ReferenceTypeFieldEntity> referenceFieldEntities = d.getFields().stream().filter(x-> DmpBlueprintFieldCategory.ReferenceType.equals(x.getCategory())).map(x-> (ReferenceTypeFieldEntity)x).toList();
|
||||
m.getFields().addAll(this.builderFactory.builder(ReferenceFieldBuilder.class).authorize(this.authorize).build(fieldsFields, referenceFieldEntities));
|
||||
}
|
||||
if (!prefillingSourcesFields.isEmpty() && d.getPrefillingSourcesIds() != null) {
|
||||
List<PrefillingSourceEntity> prefillingSourceEntities = this.queryFactory.query(PrefillingSourceQuery.class).authorize(this.authorize).ids(d.getPrefillingSourcesIds()).collectAs(prefillingSourcesFields);
|
||||
m.setPrefillingSources(this.builderFactory.builder(PrefillingSourceBuilder.class).authorize(this.authorize).build(prefillingSourcesFields, prefillingSourceEntities));
|
||||
}
|
||||
models.add(m);
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package eu.eudat.model.dmpblueprintdefinition;
|
||||
|
||||
|
||||
import eu.eudat.model.PrefillingSource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -27,6 +29,9 @@ public class Section {
|
|||
public final static String _descriptionTemplates = "descriptionTemplates";
|
||||
private List<DescriptionTemplate> descriptionTemplates;
|
||||
|
||||
public final static String _prefillingSources = "prefillingSources";
|
||||
private List<PrefillingSource> prefillingSources;
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
@ -82,6 +87,14 @@ public class Section {
|
|||
public void setDescriptionTemplates(List<DescriptionTemplate> descriptionTemplates) {
|
||||
this.descriptionTemplates = descriptionTemplates;
|
||||
}
|
||||
|
||||
public List<PrefillingSource> getPrefillingSources() {
|
||||
return prefillingSources;
|
||||
}
|
||||
|
||||
public void setPrefillingSources(List<PrefillingSource> prefillingSources) {
|
||||
this.prefillingSources = prefillingSources;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -45,6 +45,10 @@ public class SectionPersist {
|
|||
|
||||
public static final String _descriptionTemplates = "descriptionTemplates";
|
||||
|
||||
private List<UUID> prefillingSourcesIds= null;
|
||||
|
||||
public static final String _prefillingSourcesIds = "prefillingSourcesIds";
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
@ -101,6 +105,14 @@ public class SectionPersist {
|
|||
this.descriptionTemplates = descriptionTemplates;
|
||||
}
|
||||
|
||||
public List<UUID> getPrefillingSourcesIds() {
|
||||
return prefillingSourcesIds;
|
||||
}
|
||||
|
||||
public void setPrefillingSourcesIds(List<UUID> prefillingSourcesIds) {
|
||||
this.prefillingSourcesIds = prefillingSourcesIds;
|
||||
}
|
||||
|
||||
@Component(SectionPersistValidator.ValidatorName)
|
||||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public static class SectionPersistValidator extends BaseValidator<SectionPersist> {
|
||||
|
|
|
@ -91,7 +91,11 @@ public class PrefillingSourceDefinitionFieldPersist {
|
|||
|
||||
@Override
|
||||
protected List<Specification> specifications(PrefillingSourceDefinitionFieldPersist item) {
|
||||
return Arrays.asList();
|
||||
return Arrays.asList(
|
||||
this.spec()
|
||||
.must(() -> !this.isEmpty(item.getCode()))
|
||||
.failOn(PrefillingSourceDefinitionFieldPersist._code).failWith(messageSource.getMessage("Validation_Required", new Object[]{PrefillingSourceDefinitionFieldPersist._code}, LocaleContextHolder.getLocale()))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,9 @@ public class PrefillingSourceDefinitionPersist {
|
|||
private ExternalFetcherApiSourceConfigurationPersist getConfiguration;
|
||||
public static final String _getConfiguration = "getConfiguration";
|
||||
|
||||
private Boolean getEnabled;
|
||||
public static final String _getEnabled = "getEnabled";
|
||||
|
||||
private List<PrefillingSourceDefinitionFieldPersist> fields;
|
||||
public static final String _fields = "fields";
|
||||
|
||||
|
@ -42,6 +45,14 @@ public class PrefillingSourceDefinitionPersist {
|
|||
this.getConfiguration = getConfiguration;
|
||||
}
|
||||
|
||||
public Boolean getGetEnabled() {
|
||||
return getEnabled;
|
||||
}
|
||||
|
||||
public void setGetEnabled(Boolean getEnabled) {
|
||||
this.getEnabled = getEnabled;
|
||||
}
|
||||
|
||||
public List<PrefillingSourceDefinitionFieldPersist> getFields() {
|
||||
return fields;
|
||||
}
|
||||
|
@ -82,11 +93,11 @@ public class PrefillingSourceDefinitionPersist {
|
|||
.on(PrefillingSourceDefinitionPersist._searchConfiguration)
|
||||
.over(item.getSearchConfiguration())
|
||||
.using(() -> this.validatorFactory.validator(ExternalFetcherApiSourceConfigurationPersist.ExternalFetcherApiSourceConfigurationPersistValidator.class)),
|
||||
// this.refSpec() TODO
|
||||
// .iff(() -> !this.isNull(item.getGetConfiguration()))
|
||||
// .on(PrefillingSourceDefinitionPersist._getConfiguration)
|
||||
// .over(item.getGetConfiguration())
|
||||
// .using(() -> this.validatorFactory.validator(ExternalFetcherApiSourceConfigurationPersist.ExternalFetcherApiSourceConfigurationPersistValidator.class)),
|
||||
this.refSpec()
|
||||
.iff(() -> !this.isNull(item.getGetConfiguration()) && item.getGetEnabled())
|
||||
.on(PrefillingSourceDefinitionPersist._getConfiguration)
|
||||
.over(item.getGetConfiguration())
|
||||
.using(() -> this.validatorFactory.validator(ExternalFetcherApiSourceConfigurationPersist.ExternalFetcherApiSourceConfigurationPersistValidator.class)),
|
||||
this.navSpec()
|
||||
.iff(() -> !this.isListNullOrEmpty(item.getFields()))
|
||||
.on(PrefillingSourceDefinitionPersist._fields)
|
||||
|
|
|
@ -216,6 +216,7 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
|
|||
data.setLabel(persist.getLabel());
|
||||
data.setOrdinal(persist.getOrdinal());
|
||||
data.setHasTemplates(persist.getHasTemplates());
|
||||
data.setPrefillingSourcesIds(persist.getPrefillingSourcesIds());
|
||||
if (!this.conventionService.isListNullOrEmpty(persist.getFields())) {
|
||||
data.setFields(new ArrayList<>());
|
||||
for (FieldPersist fieldPersist : persist.getFields()) {
|
||||
|
|
|
@ -117,7 +117,7 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService {
|
|||
if (persist.getSearchConfiguration() != null ) {
|
||||
data.setSearchConfiguration(this.buildExternalFetcherApiConfigEntity(persist.getSearchConfiguration()));
|
||||
}
|
||||
if (persist.getGetConfiguration() != null ) {
|
||||
if (persist.getGetConfiguration() != null && persist.getGetEnabled()) {
|
||||
data.setGetConfiguration(this.buildExternalFetcherApiConfigEntity(persist.getGetConfiguration()));
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import { DmpBlueprintSystemFieldType } from "@app/core/common/enum/dmp-blueprint
|
|||
import { BaseEntity, BaseEntityPersist } from "@common/base/base-entity.model";
|
||||
import { Guid } from "@common/types/guid";
|
||||
import { ReferenceType } from "../reference-type/reference-type";
|
||||
import { PrefillingSource } from "../prefilling-source/prefilling-source";
|
||||
|
||||
|
||||
export interface DmpBlueprint extends BaseEntity {
|
||||
|
@ -28,6 +29,7 @@ export interface DmpBlueprintDefinitionSection {
|
|||
fields: FieldInSection[];
|
||||
hasTemplates: boolean;
|
||||
descriptionTemplates?: DescriptionTemplatesInSection[];
|
||||
prefillingSources: PrefillingSource[];
|
||||
}
|
||||
|
||||
export interface DescriptionTemplatesInSection {
|
||||
|
@ -87,6 +89,7 @@ export interface DmpBlueprintDefinitionSectionPersist {
|
|||
fields: FieldInSectionPersist[];
|
||||
hasTemplates: boolean;
|
||||
descriptionTemplates?: DescriptionTemplatesInSectionPersist[];
|
||||
prefillingSourcesIds: Guid[];
|
||||
}
|
||||
|
||||
export interface DescriptionTemplatesInSectionPersist {
|
||||
|
|
|
@ -176,8 +176,8 @@ export class EnumUtils {
|
|||
|
||||
toExternalFetcherSourceTypeString(status: ExternalFetcherSourceType): string {
|
||||
switch (status) {
|
||||
case ExternalFetcherSourceType.API: return this.language.instant('TYPES.REFERENCE-TYPE-SOURCE-TYPE.API');
|
||||
case ExternalFetcherSourceType.STATIC: return this.language.instant('TYPES.REFERENCE-TYPE-SOURCE-TYPE.STATIC');
|
||||
case ExternalFetcherSourceType.API: return this.language.instant('TYPES.EXTERNAL-FETCHER-SOURCE-TYPE.API');
|
||||
case ExternalFetcherSourceType.STATIC: return this.language.instant('TYPES.EXTERNAL-FETCHER-SOURCE-TYPE.STATIC');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -191,8 +191,8 @@ export class EnumUtils {
|
|||
|
||||
toExternalFetcherApiHTTPMethodTypeString(status: ExternalFetcherApiHTTPMethodType): string {
|
||||
switch (status) {
|
||||
case ExternalFetcherApiHTTPMethodType.GET: return this.language.instant('TYPES.REFERENCE-TYPE-EXTERNAL-API-HTTP-METHOD-TYPE.GET');
|
||||
case ExternalFetcherApiHTTPMethodType.POST: return this.language.instant('TYPES.REFERENCE-TYPE-EXTERNAL-API-HTTP-METHOD-TYPE.POST');
|
||||
case ExternalFetcherApiHTTPMethodType.GET: return this.language.instant('TYPES.EXTERNAL-FETCHER-API-HTTP-METHOD-TYPE.GET');
|
||||
case ExternalFetcherApiHTTPMethodType.POST: return this.language.instant('TYPES.EXTERNAL-FETCHER-API-HTTP-METHOD-TYPE.POST');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -247,6 +247,13 @@
|
|||
</div>
|
||||
<mat-error *ngIf="section.get('descriptionTemplates').hasError('backendError')">{{section.get('descriptionTemplates').getError('backendError').message}}</mat-error>
|
||||
</div>
|
||||
<div *ngIf="section.get('hasTemplates').value == true">
|
||||
<mat-form-field class="col-6">
|
||||
<mat-label>{{'DMP-BLUEPRINT-EDITOR.FIELDS.PREFILLING-SOURCES' | translate}}</mat-label>
|
||||
<app-multiple-auto-complete [formControl]="section.get('prefillingSourcesIds')" [configuration]="prefillingSourceService.multipleAutocompleteConfiguration"></app-multiple-auto-complete>
|
||||
<mat-error *ngIf="section.get('prefillingSourcesIds').hasError('backendError')">{{section.get('prefillingSourcesIds').getError('backendError').message}}</mat-error>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</mat-card>
|
||||
|
||||
</div>
|
||||
|
|
|
@ -42,6 +42,7 @@ import { DmpBlueprintEditorResolver } from './dmp-blueprint-editor.resolver';
|
|||
import { DmpBlueprintEditorService } from './dmp-blueprint-editor.service';
|
||||
import { ReferenceTypeService } from '@app/core/services/reference-type/reference-type.service';
|
||||
import { SemanticsService } from '@app/core/services/semantic/semantics.service';
|
||||
import { PrefillingSourceService } from '@app/core/services/prefilling-source/prefilling-source.service';
|
||||
|
||||
|
||||
@Component({
|
||||
|
@ -124,7 +125,8 @@ export class DmpBlueprintEditorComponent extends BaseEditor<DmpBlueprintEditorMo
|
|||
private matomoService: MatomoService,
|
||||
public descriptionTemplateService: DescriptionTemplateService,
|
||||
public referenceTypeService: ReferenceTypeService,
|
||||
public semanticsService: SemanticsService
|
||||
public semanticsService: SemanticsService,
|
||||
public prefillingSourceService: PrefillingSourceService
|
||||
) {
|
||||
super(dialog, language, formService, router, uiNotificationService, httpErrorHandlingService, filterService, datePipe, route, queryParamsService);
|
||||
}
|
||||
|
@ -223,7 +225,6 @@ export class DmpBlueprintEditorComponent extends BaseEditor<DmpBlueprintEditorMo
|
|||
|
||||
formSubmit(): void {
|
||||
this.formService.touchAllFormFields(this.formGroup);
|
||||
console.log(this.formGroup);
|
||||
if (!this.isFormValid()) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -173,6 +173,7 @@ export class DmpBlueprintDefinitionSectionEditorModel implements DmpBlueprintDef
|
|||
fields: FieldInSectionEditorModel[] = [];
|
||||
hasTemplates: boolean;
|
||||
descriptionTemplates?: DescriptionTemplatesInSectionEditorModel[] = [];
|
||||
prefillingSourcesIds: Guid[]= [];
|
||||
|
||||
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
|
||||
|
||||
|
@ -189,6 +190,7 @@ export class DmpBlueprintDefinitionSectionEditorModel implements DmpBlueprintDef
|
|||
this.hasTemplates = item.hasTemplates;
|
||||
if (item.fields) { item.fields.map(x => this.fields.push(new FieldInSectionEditorModel(this.validationErrorModel).fromModel(x))); }
|
||||
if (item.descriptionTemplates) { item.descriptionTemplates.map(x => this.descriptionTemplates.push(new DescriptionTemplatesInSectionEditorModel(this.validationErrorModel).fromModel(x))); }
|
||||
if (item.prefillingSources) this.prefillingSourcesIds = item.prefillingSources.map(x => x.id);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -227,7 +229,8 @@ export class DmpBlueprintDefinitionSectionEditorModel implements DmpBlueprintDef
|
|||
disabled: disabled
|
||||
})
|
||||
), context.getValidation('descriptionTemplates').validators
|
||||
)
|
||||
),
|
||||
prefillingSourcesIds: [{ value: this.prefillingSourcesIds, disabled: disabled }, context.getValidation('prefillingSourcesIds').validators],
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -246,6 +249,7 @@ export class DmpBlueprintDefinitionSectionEditorModel implements DmpBlueprintDef
|
|||
baseValidationArray.push({ key: 'hasTemplates', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}hasTemplates`)] });
|
||||
baseValidationArray.push({ key: 'fields', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}fields`)] });
|
||||
baseValidationArray.push({ key: 'descriptionTemplates', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}descriptionTemplates`)] });
|
||||
baseValidationArray.push({ key: 'prefillingSourcesIds', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}prefillingSourcesIds`)] });
|
||||
baseValidationArray.push({ key: 'hash', validators: [] });
|
||||
|
||||
baseContext.validation = baseValidationArray;
|
||||
|
@ -263,7 +267,7 @@ export class DmpBlueprintDefinitionSectionEditorModel implements DmpBlueprintDef
|
|||
validationErrorModel
|
||||
});
|
||||
|
||||
['id', 'label', 'ordinal', 'description', 'hasTemplates', 'hash'].forEach(keyField => {
|
||||
['id', 'label', 'ordinal', 'description', 'hasTemplates', 'prefillingSourcesIds', 'hash'].forEach(keyField => {
|
||||
const control = formGroup?.get(keyField);
|
||||
control?.clearValidators();
|
||||
control?.addValidators(context.getValidation(keyField).validators);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
|
||||
import { DescriptionTemplatesInSection, DmpBlueprint, DmpBlueprintDefinition, DmpBlueprintDefinitionSection, ExtraFieldInSection, FieldInSection, ReferenceTypeFieldInSection, SystemFieldInSection } from '@app/core/model/dmp-blueprint/dmp-blueprint';
|
||||
import { PrefillingSource } from '@app/core/model/prefilling-source/prefilling-source';
|
||||
import { ReferenceType } from '@app/core/model/reference-type/reference-type';
|
||||
import { DmpBlueprintService } from '@app/core/services/dmp/dmp-blueprint.service';
|
||||
import { BreadcrumbService } from '@app/ui/misc/breadcrumb/breadcrumb.service';
|
||||
|
@ -46,6 +47,10 @@ export class DmpBlueprintEditorResolver extends BaseEditorResolver {
|
|||
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.descriptionTemplates), nameof<DescriptionTemplatesInSection>(x => x.label)].join('.'),
|
||||
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.descriptionTemplates), nameof<DescriptionTemplatesInSection>(x => x.minMultiplicity)].join('.'),
|
||||
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.descriptionTemplates), nameof<DescriptionTemplatesInSection>(x => x.maxMultiplicity)].join('.'),
|
||||
|
||||
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.prefillingSources), nameof<PrefillingSource>(x => x.id)].join('.'),
|
||||
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.prefillingSources), nameof<PrefillingSource>(x => x.label)].join('.'),
|
||||
|
||||
nameof<DmpBlueprint>(x => x.createdAt),
|
||||
nameof<DmpBlueprint>(x => x.hash),
|
||||
nameof<DmpBlueprint>(x => x.isActive)
|
||||
|
|
|
@ -113,7 +113,7 @@
|
|||
<mat-card-content>
|
||||
<app-external-fetcher-source-component [formGroup]="formGroup.get('definition').get('searchConfiguration')" [validationErrorModel]="editorModel.validationErrorModel" [validationRootPath]="'definition.searchConfiguration.'"></app-external-fetcher-source-component>
|
||||
<div>
|
||||
<mat-checkbox [formControl]="formGroup.get('definition').get('getEnabled')">
|
||||
<mat-checkbox [formControl]="formGroup.get('definition').get('getEnabled')" (change)="getEnabledChanged($event)">
|
||||
{{'PREFILLING-SOURCE-EDITOR.FIELDS.GET-SOURCE-CONFIGURATION' | translate}}
|
||||
<mat-error *ngIf="formGroup.get('definition').get('getEnabled').hasError('backendError')">{{formGroup.get('definition').get('getEnabled').getError('backendError').message}}</mat-error>
|
||||
<mat-error *ngIf="formGroup.get('definition').get('getEnabled').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||
|
|
|
@ -25,9 +25,10 @@ import { TranslateService } from '@ngx-translate/core';
|
|||
import { map, takeUntil } from 'rxjs/operators';
|
||||
import { PrefillingSourceEditorResolver } from './prefilling-source-editor.resolver';
|
||||
import { PrefillingSourceEditorService } from './prefilling-source-editor.service';
|
||||
import { PrefillingSourceEditorModel } from './prefilling-source-editor.model';
|
||||
import { PrefillingSourceDefinitionEditorModel, PrefillingSourceEditorModel } from './prefilling-source-editor.model';
|
||||
import { ResultFieldsMappingConfigurationEditorModel } from '@app/ui/external-fetcher/external-fetcher-source-editor.model';
|
||||
import { SemanticsService } from '@app/core/services/semantic/semantics.service';
|
||||
import { MatCheckboxChange } from '@angular/material/checkbox';
|
||||
|
||||
@Component({
|
||||
selector: 'app-prefilling-source-editor-component',
|
||||
|
@ -110,9 +111,6 @@ export class PrefillingSourceEditorComponent extends BaseEditor<PrefillingSource
|
|||
this.addFieldMapping("label", "searchConfiguration");
|
||||
this.addFieldMapping("description", "searchConfiguration");
|
||||
|
||||
this.addFieldMapping("prefilling_id", "getConfiguration");
|
||||
this.addFieldMapping("label", "getConfiguration");
|
||||
this.addFieldMapping("description", "getConfiguration");
|
||||
}
|
||||
|
||||
refreshData(): void {
|
||||
|
@ -145,6 +143,12 @@ export class PrefillingSourceEditorComponent extends BaseEditor<PrefillingSource
|
|||
}
|
||||
|
||||
formSubmit(): void {
|
||||
PrefillingSourceEditorModel.reApplyDefinitionValidators(
|
||||
{
|
||||
formGroup: this.formGroup,
|
||||
validationErrorModel: this.editorModel.validationErrorModel
|
||||
}
|
||||
)
|
||||
this.formService.touchAllFormFields(this.formGroup);
|
||||
// if (!this.isFormValid()) {
|
||||
// return;
|
||||
|
@ -181,6 +185,18 @@ export class PrefillingSourceEditorComponent extends BaseEditor<PrefillingSource
|
|||
this.formService.validateAllFormFields(this.formGroup);
|
||||
}
|
||||
|
||||
getEnabledChanged(event: MatCheckboxChange){
|
||||
if(event.checked == true){
|
||||
const definition = new PrefillingSourceDefinitionEditorModel(this.editorModel.validationErrorModel);
|
||||
definition.buildGetConfiguration(this.formGroup.get('definition') as UntypedFormGroup, "definition.");
|
||||
|
||||
this.addFieldMapping("prefilling_id", "getConfiguration");
|
||||
this.addFieldMapping("label", "getConfiguration");
|
||||
this.addFieldMapping("description", "getConfiguration");
|
||||
this.submitFields();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// fields
|
||||
|
@ -206,7 +222,7 @@ export class PrefillingSourceEditorComponent extends BaseEditor<PrefillingSource
|
|||
fieldForm.markAsDirty();
|
||||
|
||||
this.removeFieldMapping((this.formGroup.get('definition').get('searchConfiguration') as FormGroup), fieldCode);
|
||||
this.removeFieldMapping((this.formGroup.get('definition').get('getConfiguration') as FormGroup), fieldCode);
|
||||
if(this.formGroup.get('definition').get('getEnabled').value == true) this.removeFieldMapping((this.formGroup.get('definition').get('getConfiguration') as FormGroup), fieldCode);
|
||||
}
|
||||
|
||||
submitFields(): void {
|
||||
|
@ -216,7 +232,7 @@ export class PrefillingSourceEditorComponent extends BaseEditor<PrefillingSource
|
|||
for (let i = 0; i < fieldsFormArray.length; i++) {
|
||||
const code = fieldsFormArray.at(i).get('code').value;
|
||||
this.addFieldMapping(code, "searchConfiguration");
|
||||
this.addFieldMapping(code, "getConfiguration");
|
||||
if(this.formGroup.get('definition').get('getEnabled').value == true) this.addFieldMapping(code, "getConfiguration");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import { Validation, ValidationContext } from "@common/forms/validation/validati
|
|||
|
||||
export class PrefillingSourceEditorModel extends BaseEditorModel implements PrefillingSourcePersist {
|
||||
label: string;
|
||||
definition: PrefillingSourceDefinitionEditorModel = new PrefillingSourceDefinitionEditorModel();
|
||||
definition: PrefillingSourceDefinitionEditorModel = new PrefillingSourceDefinitionEditorModel(this.validationErrorModel);
|
||||
permissions: string[];
|
||||
|
||||
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel();
|
||||
|
@ -57,9 +57,9 @@ export class PrefillingSourceEditorModel extends BaseEditorModel implements Pref
|
|||
}): void {
|
||||
|
||||
const { formGroup, validationErrorModel } = params;
|
||||
const control = formGroup?.get('definition');
|
||||
|
||||
PrefillingSourceDefinitionEditorModel.reapplyValidators({
|
||||
formArray: control.get('fields') as UntypedFormArray,
|
||||
formGroup: formGroup?.get('definition') as UntypedFormGroup,
|
||||
rootPath: `definition.`,
|
||||
validationErrorModel: validationErrorModel
|
||||
});
|
||||
|
@ -73,7 +73,7 @@ export class PrefillingSourceEditorModel extends BaseEditorModel implements Pref
|
|||
|
||||
export class PrefillingSourceDefinitionEditorModel implements PrefillingSourceDefinitionPersist {
|
||||
fields: PrefillingSourceDefinitionFieldEditorModel[] = [];
|
||||
searchConfiguration: ExternalFetcherBaseSourceConfigurationEditorModel = new ExternalFetcherBaseSourceConfigurationEditorModel();
|
||||
searchConfiguration: ExternalFetcherBaseSourceConfigurationEditorModel = new ExternalFetcherBaseSourceConfigurationEditorModel(this.validationErrorModel);
|
||||
getConfiguration: ExternalFetcherBaseSourceConfigurationEditorModel;
|
||||
getEnabled = false;
|
||||
|
||||
|
@ -122,7 +122,7 @@ export class PrefillingSourceDefinitionEditorModel implements PrefillingSourceDe
|
|||
getEnabled: [{ value: this.getEnabled, disabled: disabled }, context.getValidation('getEnabled').validators],
|
||||
});
|
||||
|
||||
if (this.getConfiguration != null) {
|
||||
if (this.getEnabled == true) {
|
||||
form.addControl('getConfiguration', this.getConfiguration.buildForm({
|
||||
rootPath: `${rootPath}getConfiguration.`
|
||||
}));
|
||||
|
@ -130,6 +130,17 @@ export class PrefillingSourceDefinitionEditorModel implements PrefillingSourceDe
|
|||
return form;
|
||||
}
|
||||
|
||||
buildGetConfiguration(
|
||||
form: UntypedFormGroup,
|
||||
rootPath?: string
|
||||
){
|
||||
form.addControl('getConfiguration', new ExternalFetcherBaseSourceConfigurationEditorModel(this.validationErrorModel)
|
||||
.buildForm({
|
||||
rootPath: `${rootPath}getConfiguration.`
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
static createValidationContext(params: {
|
||||
rootPath?: string,
|
||||
validationErrorModel: ValidationErrorModel
|
||||
|
@ -148,18 +159,32 @@ export class PrefillingSourceDefinitionEditorModel implements PrefillingSourceDe
|
|||
}
|
||||
|
||||
static reapplyValidators(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('fields') as UntypedFormArray).controls?.forEach(
|
||||
(control, index) => PrefillingSourceDefinitionFieldEditorModel.reapplyValidators({
|
||||
formGroup: control as UntypedFormGroup,
|
||||
rootPath: `${rootPath}fields[${index}].`,
|
||||
validationErrorModel: validationErrorModel
|
||||
})
|
||||
);
|
||||
|
||||
ExternalFetcherBaseSourceConfigurationEditorModel.reapplyValidators({
|
||||
formGroup: formGroup.get('searchConfiguration') as UntypedFormGroup,
|
||||
rootPath: `${rootPath}searchConfiguration.`,
|
||||
validationErrorModel: validationErrorModel
|
||||
});
|
||||
|
||||
if(formGroup.get('getEnabled').value == true){
|
||||
ExternalFetcherBaseSourceConfigurationEditorModel.reapplyValidators({
|
||||
formGroup: formGroup.get('getConfiguration') as UntypedFormGroup,
|
||||
rootPath: `${rootPath}getConfiguration.`,
|
||||
validationErrorModel: validationErrorModel
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import { ReferenceType } from '@app/core/model/reference-type/reference-type';
|
|||
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
|
||||
import { BaseComponent } from '@common/base/base.component';
|
||||
import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model';
|
||||
import { QueryCaseConfigEditorModel, QueryConfigEditorModel, StaticOptionEditorModel } from './external-fetcher-source-editor.model';
|
||||
import { ExternalFetcherBaseSourceConfigurationEditorModel, QueryCaseConfigEditorModel, QueryConfigEditorModel, StaticOptionEditorModel } from './external-fetcher-source-editor.model';
|
||||
import { Guid } from '@common/types/guid';
|
||||
|
||||
@Component({
|
||||
|
@ -34,7 +34,16 @@ export class ExternalFetcherSourceComponent extends BaseComponent implements OnI
|
|||
) { super(); }
|
||||
|
||||
ngOnInit() {
|
||||
console.log(this.referenceTypeSourceIndex);
|
||||
}
|
||||
|
||||
private reApplyValidators(){
|
||||
ExternalFetcherBaseSourceConfigurationEditorModel.reapplyValidators(
|
||||
{
|
||||
formGroup: this.formGroup,
|
||||
validationErrorModel: this.validationErrorModel,
|
||||
rootPath: this.validationRootPath
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -50,7 +59,9 @@ export class ExternalFetcherSourceComponent extends BaseComponent implements OnI
|
|||
|
||||
removeQuery(queryIndex: number): void {
|
||||
const formArray = (this.formGroup.get('queries') as FormArray);
|
||||
formArray.removeAt(queryIndex);
|
||||
formArray.removeAt(queryIndex);
|
||||
this.reApplyValidators();
|
||||
formArray.markAsDirty();
|
||||
}
|
||||
|
||||
// cases
|
||||
|
@ -65,6 +76,8 @@ export class ExternalFetcherSourceComponent extends BaseComponent implements OnI
|
|||
removeCase(queryIndex: number, index: number): void {
|
||||
const formArray = (this.formGroup.get('queries') as FormArray).at(queryIndex).get('cases') as FormArray;
|
||||
formArray.removeAt(index);
|
||||
this.reApplyValidators();
|
||||
formArray.markAsDirty();
|
||||
}
|
||||
|
||||
// Options
|
||||
|
@ -88,6 +101,8 @@ export class ExternalFetcherSourceComponent extends BaseComponent implements OnI
|
|||
removeOption(optionIndex: number): void {
|
||||
const formArray = (this.formGroup.get('options') as FormArray);
|
||||
formArray.removeAt(optionIndex);
|
||||
this.reApplyValidators();
|
||||
formArray.markAsDirty();
|
||||
}
|
||||
|
||||
setReferenceTypeDependenciesMap(ids: Guid[], index: number){
|
||||
|
|
|
@ -1681,7 +1681,8 @@
|
|||
"OPTIONS-ROOT": "Options Root",
|
||||
"LABEL": "Label",
|
||||
"VALUE": "Value"
|
||||
}
|
||||
},
|
||||
"PREFILLING-SOURCES":"Prefilling Sources"
|
||||
},
|
||||
"ACTIONS": {
|
||||
"ADD-FIELD": "Add Field",
|
||||
|
@ -2364,11 +2365,11 @@
|
|||
"TEXT": "Text",
|
||||
"DATE": "Date"
|
||||
},
|
||||
"REFERENCE-TYPE-SOURCE-TYPE": {
|
||||
"EXTERNAL-FETCHER-SOURCE-TYPE": {
|
||||
"API": "API",
|
||||
"STATIC": "Static"
|
||||
},
|
||||
"REFERENCE-TYPE-EXTERNAL-API-HTTP-METHOD-TYPE": {
|
||||
"EXTERNAL-FETCHER-API-HTTP-METHOD-TYPE": {
|
||||
"GET": "GET",
|
||||
"POST": "POST"
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue