Merge branch 'dmp-refactoring' of https://code-repo.d4science.org/MaDgiK-CITE/argos into dmp-refactoring

This commit is contained in:
Sofia Papacharalampous 2024-05-08 12:47:00 +03:00
commit ab5fc150a4
4 changed files with 32 additions and 4 deletions

View File

@ -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 };

View File

@ -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<Dmp>(x => x.blueprint), nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.descriptionTemplates), nameof<DescriptionTemplatesInSection>(x => x.label)].join('.'),
// (prefix ? prefix + '.' : '') + [nameof<Dmp>(x => x.blueprint), nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.descriptionTemplates), nameof<DescriptionTemplatesInSection>(x => x.minMultiplicity)].join('.'),
(prefix ? prefix + '.' : '') + [nameof<Dmp>(x => x.blueprint), nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.descriptionTemplates), nameof<DescriptionTemplatesInSection>(x => x.maxMultiplicity)].join('.'),
(prefix ? prefix + '.' : '') + [nameof<Dmp>(x => x.blueprint), nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.prefillingSources), nameof<PrefillingSource>(x => x.id)].join('.'),
(prefix ? prefix + '.' : '') + [nameof<Dmp>(x => x.dmpDescriptionTemplates), nameof<DmpDescriptionTemplate>(x => x.id)].join('.'),
(prefix ? prefix + '.' : '') + [nameof<Dmp>(x => x.dmpDescriptionTemplates), nameof<DmpDescriptionTemplate>(x => x.sectionId)].join('.'),

View File

@ -41,7 +41,7 @@
<mat-form-field class="col-md-12">
<app-single-auto-complete [required]="true" [formControl]="prefillForm.get('prefillingSourceId')"
placeholder="{{'PREFILL-DESCRIPTION-DIALOG.PREFILLING-SOURCE' | translate}}"
[configuration]="prefillingSourceService.singleAutocompleteConfiguration" (optionSelected)="changePreffillingSource($event)">
[configuration]="singlePrefillingSourceAutoCompleteConfiguration" (optionSelected)="changePreffillingSource($event)">
</app-single-auto-complete>
<mat-error *ngIf="prefillForm.get('prefillingSourceId').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
@ -53,7 +53,7 @@
<mat-form-field class="col-md-12">
<app-single-auto-complete [required]="true" [formControl]="prefillForm.get('data')"
placeholder="{{'PREFILL-DESCRIPTION-DIALOG.SEARCH' | translate}}"
[configuration]="prefillAutoCompleteConfiguration">
[configuration]="prefillObjectAutoCompleteConfiguration">
</app-single-auto-complete>
</mat-form-field>
</div>

View File

@ -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,