user can select reference-type filter multiple times in dmp-listing

This commit is contained in:
Sofia Papacharalampous 2024-06-27 13:13:39 +03:00
parent 55b7817ae1
commit 6efa045412
4 changed files with 25 additions and 31 deletions

View File

@ -47,7 +47,7 @@ export interface DescriptionFilter {
} }
export class ReferencesWithType { export class ReferencesWithType {
referenceType: ReferenceType; referenceType: Guid;
references: Guid[]; references: Guid[];
constructor() { constructor() {

View File

@ -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 { private buildAutocompleteLookup(like?: string, excludedIds?: Guid[], ids?: Guid[]): ReferenceTypeLookup {
const lookup: ReferenceTypeLookup = new ReferenceTypeLookup(); const lookup: ReferenceTypeLookup = new ReferenceTypeLookup();
lookup.page = { size: 100, offset: 0 }; lookup.page = { size: 100, offset: 0 };

View File

@ -67,11 +67,11 @@
</mat-form-field> </mat-form-field>
</div> </div>
</div> </div>
<div class="row" *ngIf="referenceForm.get('referenceType')?.value && selectReferenceAutocompleteConfiguration(referenceForm.get('referenceType').value.id)"> <div class="row" *ngIf="referenceForm.get('referenceType')?.value && selectReferenceAutocompleteConfiguration(referenceForm.get('referenceType').value)">
<div class="col-12"> <div class="col-12">
<mat-form-field class="w-100 mb-2"> <mat-form-field class="w-100 mb-2">
<mat-label>{{'DESCRIPTION-LISTING.FILTERS.REFERENCE-TYPES.REFERENCE' | translate}}</mat-label> <mat-label>{{'DESCRIPTION-LISTING.FILTERS.REFERENCE-TYPES.REFERENCE' | translate}}</mat-label>
<app-multiple-auto-complete [formControl]="referenceForm.get('references')" [configuration]="selectReferenceAutocompleteConfiguration(referenceForm.get('referenceType').value.id)"> <app-multiple-auto-complete [formControl]="referenceForm.get('references')" [configuration]="selectReferenceAutocompleteConfiguration(referenceForm.get('referenceType').value)">
</app-multiple-auto-complete> </app-multiple-auto-complete>
</mat-form-field> </mat-form-field>
</div> </div>

View File

@ -1,4 +1,3 @@
import { Component, Input, OnInit, Output, EventEmitter, OnChanges, SimpleChanges } from '@angular/core'; import { Component, Input, OnInit, Output, EventEmitter, OnChanges, SimpleChanges } from '@angular/core';
import { UntypedFormArray, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms'; import { UntypedFormArray, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
import { BaseCriteriaComponent } from '@app/ui/misc/criteria/base-criteria.component'; 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 { Guid } from '@common/types/guid';
import { ReferenceTypeService } from '@app/core/services/reference-type/reference-type.service'; import { ReferenceTypeService } from '@app/core/services/reference-type/reference-type.service';
import { takeUntil } from 'rxjs'; import { takeUntil } from 'rxjs';
import { ReferenceType } from '@app/core/model/reference-type/reference-type';
import { ReferenceService } from '@app/core/services/reference/reference.service'; import { ReferenceService } from '@app/core/services/reference/reference.service';
import { Reference } from '@app/core/model/reference/reference'; import { Reference } from '@app/core/model/reference/reference';
@ -36,7 +34,6 @@ export class DmpFilterComponent extends BaseCriteriaComponent implements OnInit,
sizeError = false; sizeError = false;
maxFileSize: number = 1048576; maxFileSize: number = 1048576;
filteringOrganisationsAsync = false; filteringOrganisationsAsync = false;
selectedReferenceTypes: Guid[];
descriptionTemplateAutoCompleteConfiguration: MultipleAutoCompleteConfiguration; descriptionTemplateAutoCompleteConfiguration: MultipleAutoCompleteConfiguration;
dmpBlueprintAutoCompleteConfiguration: MultipleAutoCompleteConfiguration; dmpBlueprintAutoCompleteConfiguration: MultipleAutoCompleteConfiguration;
@ -64,8 +61,7 @@ export class DmpFilterComponent extends BaseCriteriaComponent implements OnInit,
this.descriptionTemplateAutoCompleteConfiguration = this.descriptionTemplateService.descriptionTempalteGroupMultipleAutocompleteConfiguration; this.descriptionTemplateAutoCompleteConfiguration = this.descriptionTemplateService.descriptionTempalteGroupMultipleAutocompleteConfiguration;
this.dmpBlueprintAutoCompleteConfiguration = this.dmpBlueprintService.multipleAutocompleteConfiguration; this.dmpBlueprintAutoCompleteConfiguration = this.dmpBlueprintService.multipleAutocompleteConfiguration;
this.selectedReferenceTypes = this._buildSelectedReferenceTypes(this.filterFormGroup); this.referenceTypeAutocompleteConfiguration = this.getReferenceTypeAutocompleteConfiguration();
this.referenceTypeAutocompleteConfiguration = this.getReferenceTypeAutocompleteConfiguration(this.selectedReferenceTypes);
this.referenceAutocompleteConfiguration = new Map<string, MultipleAutoCompleteConfiguration>(); this.referenceAutocompleteConfiguration = new Map<string, MultipleAutoCompleteConfiguration>();
this.formGroup = this.filterFormGroup; this.formGroup = this.filterFormGroup;
@ -73,7 +69,7 @@ export class DmpFilterComponent extends BaseCriteriaComponent implements OnInit,
const formArray = this.formGroup.get('references') as UntypedFormArray; const formArray = this.formGroup.get('references') as UntypedFormArray;
formArray?.controls.forEach(control => { formArray?.controls.forEach(control => {
let referenceTypeId: string = control.get('referenceType')?.value?.id; let referenceTypeId: string = control.get('referenceType')?.value;
if (referenceTypeId && referenceTypeId != '') { if (referenceTypeId && referenceTypeId != '') {
let excludedReferences = control.get('references')?.value ?? []; let excludedReferences = control.get('references')?.value ?? [];
let referenceAutocomplete = this.getReferenceAutocompleteConfiguration(Guid.parse(referenceTypeId), excludedReferences); 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)) control.get('referenceType')?.valueChanges.pipe(takeUntil(this._destroyed))
.subscribe(referenceType => { .subscribe(referenceType => {
this.selectedReferenceTypes = this._buildSelectedReferenceTypes(this.formGroup); this.referenceTypeAutocompleteConfiguration = this.getReferenceTypeAutocompleteConfiguration();
this.referenceTypeAutocompleteConfiguration = this.getReferenceTypeAutocompleteConfiguration(this.selectedReferenceTypes);
if (referenceTypeId && referenceTypeId != '') { if (referenceTypeId && referenceTypeId != '') {
let excludedReferences = control.get('references')?.value ?? []; 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)) referenceForm?.get('referenceType')?.valueChanges.pipe(takeUntil(this._destroyed))
.subscribe((reference: ReferenceType) => { .subscribe((referenceTypeId: string) => {
this.selectedReferenceTypes = this._buildSelectedReferenceTypes(this.formGroup); this.referenceTypeAutocompleteConfiguration = this.getReferenceTypeAutocompleteConfiguration();
this.referenceTypeAutocompleteConfiguration = this.getReferenceTypeAutocompleteConfiguration(this.selectedReferenceTypes);
referenceForm.get('references')?.reset(); referenceForm.get('references')?.reset();
if (reference?.id) { if (referenceTypeId) {
let referenceAutocomplete = this.getReferenceAutocompleteConfiguration(reference.id, []); let referenceAutocomplete = this.getReferenceAutocompleteConfiguration(Guid.parse(referenceTypeId), []);
this.referenceAutocompleteConfiguration.set(reference?.id?.toString(), referenceAutocomplete); this.referenceAutocompleteConfiguration.set(referenceTypeId, referenceAutocomplete);
} }
}); });
@ -162,23 +156,12 @@ export class DmpFilterComponent extends BaseCriteriaComponent implements OnInit,
} }
selectReferenceAutocompleteConfiguration(referenceTypeId: string): MultipleAutoCompleteConfiguration { selectReferenceAutocompleteConfiguration(referenceTypeId: string): MultipleAutoCompleteConfiguration {
let foo = this.referenceAutocompleteConfiguration.get(referenceTypeId);
return this.referenceAutocompleteConfiguration.get(referenceTypeId); return this.referenceAutocompleteConfiguration.get(referenceTypeId);
}; };
private getReferenceTypeAutocompleteConfiguration(selectedReferenceTypes: Guid[]) { private getReferenceTypeAutocompleteConfiguration() {
return this.referenceTypeService.getSingleAutocompleteConfiguration(selectedReferenceTypes); return this.referenceTypeService.getSingleAutocompleteConfigurationForDmp();
}
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 getReferenceAutocompleteConfiguration(referenceTypeId: Guid, excludedIds: Reference[]): MultipleAutoCompleteConfiguration { private getReferenceAutocompleteConfiguration(referenceTypeId: Guid, excludedIds: Reference[]): MultipleAutoCompleteConfiguration {