From 12b49fe68fb4190690af05ec4a8849c9a5db7bd6 Mon Sep 17 00:00:00 2001 From: amentis Date: Wed, 8 May 2024 12:26:55 +0300 Subject: [PATCH] check available prefilling sources with blueprint prefilling sources --- .../prefilling-source.service.ts | 22 +++++++++++++++++++ .../editor/description-editor.resolver.ts | 2 ++ .../prefill-description.component.html | 4 ++-- .../prefill-description.component.ts | 8 +++++-- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/dmp-frontend/src/app/core/services/prefilling-source/prefilling-source.service.ts b/dmp-frontend/src/app/core/services/prefilling-source/prefilling-source.service.ts index 807200b91..879b8d644 100644 --- a/dmp-frontend/src/app/core/services/prefilling-source/prefilling-source.service.ts +++ b/dmp-frontend/src/app/core/services/prefilling-source/prefilling-source.service.ts @@ -86,6 +86,17 @@ export class PrefillingSourceService { titleFn: (item: PrefillingSource) => item.label, valueAssign: (item: PrefillingSource) => item.id, }; + + public getSingleAutocompleteConfiguration(ids: Guid[]): SingleAutoCompleteConfiguration { + return { + initialItems: (data?: any) => this.query(this.buildAutocompleteLookup(null, null, ids && ids.length > 0 ? ids: null)).pipe(map(x => x.items)), + filterFn: (searchQuery: string, data?: any) => this.query(this.buildAutocompleteLookup(searchQuery, null, ids && ids.length > 0 ? ids: null)).pipe(map(x => x.items)), + getSelectedItem: (selectedItem: any) => this.query(this.buildAutocompleteLookup(null, null, [selectedItem])).pipe(map(x => x.items[0])), + displayFn: (item: PrefillingSource) => item.label, + titleFn: (item: PrefillingSource) => item.label, + valueAssign: (item: PrefillingSource) => item.id, + } + } public multipleAutocompleteConfiguration: MultipleAutoCompleteConfiguration = { initialItems: (excludedItems: any[], data?: any) => this.query(this.buildAutocompleteLookup(null, excludedItems ? excludedItems : null)).pipe(map(x => x.items)), @@ -96,6 +107,17 @@ export class PrefillingSourceService { valueAssign: (item: PrefillingSource) => item.id, }; + public getMltipleAutocompleteConfiguration(ids: Guid[]): MultipleAutoCompleteConfiguration { + return { + initialItems: (excludedItems: any[], data?: any) => this.query(this.buildAutocompleteLookup(null, excludedItems ? excludedItems : null, ids && ids.length > 0 ? ids: null)).pipe(map(x => x.items)), + filterFn: (searchQuery: string, excludedItems: any[]) => this.query(this.buildAutocompleteLookup(searchQuery, excludedItems, ids && ids.length > 0 ? ids: null)).pipe(map(x => x.items)), + getSelectedItems: (selectedItems: any[]) => this.query(this.buildAutocompleteLookup(null, null, selectedItems)).pipe(map(x => x.items)), + displayFn: (item: PrefillingSource) => item.label, + titleFn: (item: PrefillingSource) => item.label, + valueAssign: (item: PrefillingSource) => item.id, + } + } + private buildAutocompleteLookup(like?: string, excludedIds?: Guid[], ids?: Guid[]): PrefillingSourceLookup { const lookup: PrefillingSourceLookup = new PrefillingSourceLookup(); lookup.page = { size: 100, offset: 0 }; diff --git a/dmp-frontend/src/app/ui/description/editor/description-editor.resolver.ts b/dmp-frontend/src/app/ui/description/editor/description-editor.resolver.ts index 6353213ab..c5ad2372c 100644 --- a/dmp-frontend/src/app/ui/description/editor/description-editor.resolver.ts +++ b/dmp-frontend/src/app/ui/description/editor/description-editor.resolver.ts @@ -6,6 +6,7 @@ import { DescriptionTemplate, DescriptionTemplateBaseFieldData, DescriptionTempl import { Description, DescriptionExternalIdentifier, DescriptionField, DescriptionPropertyDefinition, DescriptionPropertyDefinitionFieldSet, DescriptionPropertyDefinitionFieldSetItem, DescriptionReference, DescriptionReferenceData, DescriptionTag } from '@app/core/model/description/description'; import { DescriptionTemplatesInSection, DmpBlueprint, DmpBlueprintDefinition, DmpBlueprintDefinitionSection } from '@app/core/model/dmp-blueprint/dmp-blueprint'; import { Dmp, DmpDescriptionTemplate } from '@app/core/model/dmp/dmp'; +import { PrefillingSource } from '@app/core/model/prefilling-source/prefilling-source'; import { ReferenceType } from '@app/core/model/reference-type/reference-type'; import { Reference } from '@app/core/model/reference/reference'; import { Tag } from '@app/core/model/tag/tag'; @@ -127,6 +128,7 @@ export class DescriptionEditorResolver extends BaseEditorResolver { // (prefix ? prefix + '.' : '') + [nameof(x => x.blueprint), nameof(x => x.definition), nameof(x => x.sections), nameof(x => x.descriptionTemplates), nameof(x => x.label)].join('.'), // (prefix ? prefix + '.' : '') + [nameof(x => x.blueprint), nameof(x => x.definition), nameof(x => x.sections), nameof(x => x.descriptionTemplates), nameof(x => x.minMultiplicity)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.blueprint), nameof(x => x.definition), nameof(x => x.sections), nameof(x => x.descriptionTemplates), nameof(x => x.maxMultiplicity)].join('.'), + (prefix ? prefix + '.' : '') + [nameof(x => x.blueprint), nameof(x => x.definition), nameof(x => x.sections), nameof(x => x.prefillingSources), nameof(x => x.id)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.dmpDescriptionTemplates), nameof(x => x.id)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.dmpDescriptionTemplates), nameof(x => x.sectionId)].join('.'), diff --git a/dmp-frontend/src/app/ui/description/editor/prefill-description/prefill-description.component.html b/dmp-frontend/src/app/ui/description/editor/prefill-description/prefill-description.component.html index 2bec2d109..10d077767 100644 --- a/dmp-frontend/src/app/ui/description/editor/prefill-description/prefill-description.component.html +++ b/dmp-frontend/src/app/ui/description/editor/prefill-description/prefill-description.component.html @@ -41,7 +41,7 @@ + [configuration]="singlePrefillingSourceAutoCompleteConfiguration" (optionSelected)="changePreffillingSource($event)"> {{'GENERAL.VALIDATION.REQUIRED' | translate}} @@ -53,7 +53,7 @@ + [configuration]="prefillObjectAutoCompleteConfiguration"> diff --git a/dmp-frontend/src/app/ui/description/editor/prefill-description/prefill-description.component.ts b/dmp-frontend/src/app/ui/description/editor/prefill-description/prefill-description.component.ts index 7b299552a..ebef93e16 100644 --- a/dmp-frontend/src/app/ui/description/editor/prefill-description/prefill-description.component.ts +++ b/dmp-frontend/src/app/ui/description/editor/prefill-description/prefill-description.component.ts @@ -28,7 +28,8 @@ import { DescriptionPrefillingRequestEditorModel } from "./prefill-description-e export class PrefillDescriptionDialogComponent extends BaseComponent implements OnInit { progressIndication = false; - prefillAutoCompleteConfiguration: SingleAutoCompleteConfiguration; + singlePrefillingSourceAutoCompleteConfiguration: SingleAutoCompleteConfiguration; + prefillObjectAutoCompleteConfiguration: SingleAutoCompleteConfiguration; prefillSelected: boolean = false; prefillForm: UntypedFormGroup; @@ -49,13 +50,16 @@ export class PrefillDescriptionDialogComponent extends BaseComponent implements } ngOnInit() { + const availablePrefillingSourcesIds = this.dmp.blueprint.definition.sections.filter(x => x.id === this.dmpSectionId)[0].prefillingSources?.map(x => x.id) || null; + this.singlePrefillingSourceAutoCompleteConfiguration = this.prefillingSourceService.getSingleAutocompleteConfiguration(availablePrefillingSourcesIds); + this.progressIndicationService.getProgressIndicationObservable().pipe(takeUntil(this._destroyed)).subscribe(x => { setTimeout(() => { this.progressIndication = x; }); }); const editorModel = new DescriptionPrefillingRequestEditorModel(); this.prefillForm = editorModel.buildForm(null, false); - this.prefillAutoCompleteConfiguration = { + this.prefillObjectAutoCompleteConfiguration = { filterFn: this.searchDescriptions.bind(this), loadDataOnStart: false, displayFn: (item: Prefilling) => (item.label.length > 60) ? (item.label.substr(0, 60) + "...") : item.label,