From 6efa045412d7c329eabad13ada149dbe14b41391 Mon Sep 17 00:00:00 2001 From: Sofia Papacharalampous Date: Thu, 27 Jun 2024 13:13:39 +0300 Subject: [PATCH] user can select reference-type filter multiple times in dmp-listing --- .../src/app/core/query/description.lookup.ts | 2 +- .../reference-type/reference-type.service.ts | 11 ++++++ .../filtering/dmp-filter.component.html | 4 +- .../listing/filtering/dmp-filter.component.ts | 39 ++++++------------- 4 files changed, 25 insertions(+), 31 deletions(-) diff --git a/dmp-frontend/src/app/core/query/description.lookup.ts b/dmp-frontend/src/app/core/query/description.lookup.ts index ab4ea1999..d6cfc4196 100644 --- a/dmp-frontend/src/app/core/query/description.lookup.ts +++ b/dmp-frontend/src/app/core/query/description.lookup.ts @@ -47,7 +47,7 @@ export interface DescriptionFilter { } export class ReferencesWithType { - referenceType: ReferenceType; + referenceType: Guid; references: Guid[]; constructor() { diff --git a/dmp-frontend/src/app/core/services/reference-type/reference-type.service.ts b/dmp-frontend/src/app/core/services/reference-type/reference-type.service.ts index e0196f0a2..448e418e0 100644 --- a/dmp-frontend/src/app/core/services/reference-type/reference-type.service.ts +++ b/dmp-frontend/src/app/core/services/reference-type/reference-type.service.ts @@ -116,6 +116,17 @@ export class ReferenceTypeService { }; } + public getSingleAutocompleteConfigurationForDmp(excludedIds: Guid[] = null): SingleAutoCompleteConfiguration { + return { + initialItems: (data?: any) => this.query(this.buildAutocompleteLookup(null, excludedIds)).pipe(map(x => x.items)), + filterFn: (searchQuery: string, data?: any) => this.query(this.buildAutocompleteLookup(searchQuery, excludedIds)).pipe(map(x => x.items)), + getSelectedItem: (selectedItem: any) => this.query(this.buildAutocompleteLookup(null, null, [selectedItem])).pipe(map(x => x.items[0])), + displayFn: (item: ReferenceType) => item.name, + titleFn: (item: ReferenceType) => item.name, + valueAssign: (item: ReferenceType) => item.id, + }; + } + private buildAutocompleteLookup(like?: string, excludedIds?: Guid[], ids?: Guid[]): ReferenceTypeLookup { const lookup: ReferenceTypeLookup = new ReferenceTypeLookup(); lookup.page = { size: 100, offset: 0 }; diff --git a/dmp-frontend/src/app/ui/dmp/listing/filtering/dmp-filter.component.html b/dmp-frontend/src/app/ui/dmp/listing/filtering/dmp-filter.component.html index 2dbd63fb0..3012183e6 100644 --- a/dmp-frontend/src/app/ui/dmp/listing/filtering/dmp-filter.component.html +++ b/dmp-frontend/src/app/ui/dmp/listing/filtering/dmp-filter.component.html @@ -67,11 +67,11 @@ -
+
{{'DESCRIPTION-LISTING.FILTERS.REFERENCE-TYPES.REFERENCE' | translate}} - +
diff --git a/dmp-frontend/src/app/ui/dmp/listing/filtering/dmp-filter.component.ts b/dmp-frontend/src/app/ui/dmp/listing/filtering/dmp-filter.component.ts index 1baa77b18..091e277cd 100644 --- a/dmp-frontend/src/app/ui/dmp/listing/filtering/dmp-filter.component.ts +++ b/dmp-frontend/src/app/ui/dmp/listing/filtering/dmp-filter.component.ts @@ -1,4 +1,3 @@ - import { Component, Input, OnInit, Output, EventEmitter, OnChanges, SimpleChanges } from '@angular/core'; import { UntypedFormArray, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms'; import { BaseCriteriaComponent } from '@app/ui/misc/criteria/base-criteria.component'; @@ -14,7 +13,6 @@ import { SingleAutoCompleteConfiguration } from '@app/library/auto-complete/sing import { Guid } from '@common/types/guid'; import { ReferenceTypeService } from '@app/core/services/reference-type/reference-type.service'; import { takeUntil } from 'rxjs'; -import { ReferenceType } from '@app/core/model/reference-type/reference-type'; import { ReferenceService } from '@app/core/services/reference/reference.service'; import { Reference } from '@app/core/model/reference/reference'; @@ -36,7 +34,6 @@ export class DmpFilterComponent extends BaseCriteriaComponent implements OnInit, sizeError = false; maxFileSize: number = 1048576; filteringOrganisationsAsync = false; - selectedReferenceTypes: Guid[]; descriptionTemplateAutoCompleteConfiguration: MultipleAutoCompleteConfiguration; dmpBlueprintAutoCompleteConfiguration: MultipleAutoCompleteConfiguration; @@ -64,8 +61,7 @@ export class DmpFilterComponent extends BaseCriteriaComponent implements OnInit, this.descriptionTemplateAutoCompleteConfiguration = this.descriptionTemplateService.descriptionTempalteGroupMultipleAutocompleteConfiguration; this.dmpBlueprintAutoCompleteConfiguration = this.dmpBlueprintService.multipleAutocompleteConfiguration; - this.selectedReferenceTypes = this._buildSelectedReferenceTypes(this.filterFormGroup); - this.referenceTypeAutocompleteConfiguration = this.getReferenceTypeAutocompleteConfiguration(this.selectedReferenceTypes); + this.referenceTypeAutocompleteConfiguration = this.getReferenceTypeAutocompleteConfiguration(); this.referenceAutocompleteConfiguration = new Map(); this.formGroup = this.filterFormGroup; @@ -73,7 +69,7 @@ export class DmpFilterComponent extends BaseCriteriaComponent implements OnInit, const formArray = this.formGroup.get('references') as UntypedFormArray; formArray?.controls.forEach(control => { - let referenceTypeId: string = control.get('referenceType')?.value?.id; + let referenceTypeId: string = control.get('referenceType')?.value; if (referenceTypeId && referenceTypeId != '') { let excludedReferences = control.get('references')?.value ?? []; let referenceAutocomplete = this.getReferenceAutocompleteConfiguration(Guid.parse(referenceTypeId), excludedReferences); @@ -82,8 +78,7 @@ export class DmpFilterComponent extends BaseCriteriaComponent implements OnInit, control.get('referenceType')?.valueChanges.pipe(takeUntil(this._destroyed)) .subscribe(referenceType => { - this.selectedReferenceTypes = this._buildSelectedReferenceTypes(this.formGroup); - this.referenceTypeAutocompleteConfiguration = this.getReferenceTypeAutocompleteConfiguration(this.selectedReferenceTypes); + this.referenceTypeAutocompleteConfiguration = this.getReferenceTypeAutocompleteConfiguration(); if (referenceTypeId && referenceTypeId != '') { let excludedReferences = control.get('references')?.value ?? []; @@ -127,14 +122,13 @@ export class DmpFilterComponent extends BaseCriteriaComponent implements OnInit, }); referenceForm?.get('referenceType')?.valueChanges.pipe(takeUntil(this._destroyed)) - .subscribe((reference: ReferenceType) => { - this.selectedReferenceTypes = this._buildSelectedReferenceTypes(this.formGroup); - this.referenceTypeAutocompleteConfiguration = this.getReferenceTypeAutocompleteConfiguration(this.selectedReferenceTypes); + .subscribe((referenceTypeId: string) => { + this.referenceTypeAutocompleteConfiguration = this.getReferenceTypeAutocompleteConfiguration(); referenceForm.get('references')?.reset(); - if (reference?.id) { - let referenceAutocomplete = this.getReferenceAutocompleteConfiguration(reference.id, []); - this.referenceAutocompleteConfiguration.set(reference?.id?.toString(), referenceAutocomplete); + if (referenceTypeId) { + let referenceAutocomplete = this.getReferenceAutocompleteConfiguration(Guid.parse(referenceTypeId), []); + this.referenceAutocompleteConfiguration.set(referenceTypeId, referenceAutocomplete); } }); @@ -162,23 +156,12 @@ export class DmpFilterComponent extends BaseCriteriaComponent implements OnInit, } selectReferenceAutocompleteConfiguration(referenceTypeId: string): MultipleAutoCompleteConfiguration { + let foo = this.referenceAutocompleteConfiguration.get(referenceTypeId); return this.referenceAutocompleteConfiguration.get(referenceTypeId); }; - private getReferenceTypeAutocompleteConfiguration(selectedReferenceTypes: Guid[]) { - return this.referenceTypeService.getSingleAutocompleteConfiguration(selectedReferenceTypes); - } - - private _buildSelectedReferenceTypes(formGroup: UntypedFormGroup): Guid[] { - const formArray = formGroup.get('references') as UntypedFormArray; - - let selectedReferenceTypes = []; - formArray.controls.forEach(control => { - let id = control.get('referenceType')?.value?.id; - if (id) selectedReferenceTypes.push(Guid.parse(id)); - }); - - return selectedReferenceTypes; + private getReferenceTypeAutocompleteConfiguration() { + return this.referenceTypeService.getSingleAutocompleteConfigurationForDmp(); } private getReferenceAutocompleteConfiguration(referenceTypeId: Guid, excludedIds: Reference[]): MultipleAutoCompleteConfiguration {