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 {
referenceType: ReferenceType;
referenceType: Guid;
references: Guid[];
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 {
const lookup: ReferenceTypeLookup = new ReferenceTypeLookup();
lookup.page = { size: 100, offset: 0 };

View File

@ -67,11 +67,11 @@
</mat-form-field>
</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">
<mat-form-field class="w-100 mb-2">
<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>
</mat-form-field>
</div>

View File

@ -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<string, MultipleAutoCompleteConfiguration>();
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 {