dmp reference-filter refactor

This commit is contained in:
Sofia Papacharalampous 2024-06-27 15:44:09 +03:00
parent 6efa045412
commit 403190c786
8 changed files with 180 additions and 140 deletions

View File

@ -47,8 +47,10 @@ export interface DescriptionFilter {
} }
export class ReferencesWithType { export class ReferencesWithType {
referenceType: Guid; referenceType?: Guid;
references: Guid[]; referenceTypeId?: Guid;
referenceIds?: Guid[];
references?: Guid[];
constructor() { constructor() {
} }

View File

@ -1,5 +1,5 @@
import { Component, OnInit, ViewChild } from '@angular/core'; import { Component, OnInit, ViewChild } from '@angular/core';
import { FormBuilder, UntypedFormArray, UntypedFormBuilder, UntypedFormControl, UntypedFormGroup } from '@angular/forms'; import { UntypedFormBuilder, UntypedFormControl, UntypedFormGroup } from '@angular/forms';
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import { MatPaginator } from '@angular/material/paginator'; import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort'; import { MatSort } from '@angular/material/sort';
@ -34,11 +34,8 @@ import { Observable } from 'rxjs';
import { UiNotificationService } from '@app/core/services/notification/ui-notification-service'; import { UiNotificationService } from '@app/core/services/notification/ui-notification-service';
import { QueryParamsService } from '@app/core/services/utilities/query-params.service'; import { QueryParamsService } from '@app/core/services/utilities/query-params.service';
import { ReferencesWithType } from '@app/core/query/description.lookup'; import { ReferencesWithType } from '@app/core/query/description.lookup';
import { DmpDescriptionTemplateLookup } from '@app/core/query/dmp-description-template.lookup';
import { DmpBlueprintLookup } from '@app/core/query/dmp-blueprint.lookup';
import { DmpUserLookup } from '@app/core/query/dmp-user.lookup';
import { Guid } from '@common/types/guid'; import { Guid } from '@common/types/guid';
import { DmpReferenceLookup } from '@app/core/query/reference.lookup'; import { DmpFilterService } from './filtering/services/dmp-filter.service';
@Component({ @Component({
selector: 'app-dmp-listing-component', selector: 'app-dmp-listing-component',
@ -109,7 +106,6 @@ export class DmpListingComponent extends BaseListingComponent<BaseDmp, DmpLookup
private authService: AuthService, private authService: AuthService,
private guidedTourService: GuidedTourService, private guidedTourService: GuidedTourService,
private analyticsService: AnalyticsService, private analyticsService: AnalyticsService,
private formBuilder: FormBuilder,
) { ) {
super(router, route, uiNotificationService, httpErrorHandlingService, queryParamsService); super(router, route, uiNotificationService, httpErrorHandlingService, queryParamsService);
} }
@ -128,9 +124,14 @@ export class DmpListingComponent extends BaseListingComponent<BaseDmp, DmpLookup
const queryParams = this.route.snapshot.queryParams; const queryParams = this.route.snapshot.queryParams;
if (!this.lookup && queryParams['lookup']) { if (!this.lookup && queryParams['lookup']) {
this.lookup = this._parseLookupFromParams(queryParams) this.lookup = this._parseLookupFromParams(queryParams);
this.referenceFilters = [{
referenceTypeId: null,
referenceIds: this.lookup?.dmpReferenceSubQuery?.referenceIds ?? [],
}];
this.filtersCount = this._countFilters(this.lookup); this.filtersCount = this._countFilters(this.lookup);
} else if (!this.lookup) this.lookup = this.initializeLookup(); }
else if (!this.lookup) this.lookup = this.initializeLookup();
if ((this.formGroup.get('order')?.value == null || (!this.isAscending && !this.isDescending)) && this.lookup.order.items && this.lookup.order.items.length > 0) { if ((this.formGroup.get('order')?.value == null || (!this.isAscending && !this.isDescending)) && this.lookup.order.items && this.lookup.order.items.length > 0) {
@ -269,7 +270,8 @@ export class DmpListingComponent extends BaseListingComponent<BaseDmp, DmpLookup
panelClass: 'dialog-side-panel', panelClass: 'dialog-side-panel',
data: { data: {
isPublic: this.isPublic ?? true, isPublic: this.isPublic ?? true,
filterForm: this._buildFormFromLookup(this.lookup, this.referenceFilters), filterForm: this._buildFormFromLookup(this.lookup),
referencesWithTypeItems: this.referenceFilters ?? [],
} }
}); });
@ -350,7 +352,7 @@ export class DmpListingComponent extends BaseListingComponent<BaseDmp, DmpLookup
// Description Templates // Description Templates
let descriptionTemplates = formGroup.get("descriptionTemplates")?.value ?? null; let descriptionTemplates = formGroup.get("descriptionTemplates")?.value ?? null;
if (descriptionTemplates && descriptionTemplates?.length > 0) { if (descriptionTemplates && descriptionTemplates?.length > 0) {
lookup.dmpDescriptionTemplateSubQuery = this.initializeDmpDescriptionTemplateLookup(); lookup.dmpDescriptionTemplateSubQuery = DmpFilterService.initializeDmpDescriptionTemplateLookup();
lookup.dmpDescriptionTemplateSubQuery.descriptionTemplateGroupIds = descriptionTemplates; lookup.dmpDescriptionTemplateSubQuery.descriptionTemplateGroupIds = descriptionTemplates;
} else lookup.dmpDescriptionTemplateSubQuery = null; } else lookup.dmpDescriptionTemplateSubQuery = null;
@ -358,23 +360,23 @@ export class DmpListingComponent extends BaseListingComponent<BaseDmp, DmpLookup
let dmpBlueprints = formGroup.get("dmpBlueprints")?.value ?? null; let dmpBlueprints = formGroup.get("dmpBlueprints")?.value ?? null;
if (dmpBlueprints && dmpBlueprints?.length > 0) { if (dmpBlueprints && dmpBlueprints?.length > 0) {
lookup.dmpBlueprintSubQuery = this.initializeDmpBlueprintLookup(); lookup.dmpBlueprintSubQuery = DmpFilterService.initializeDmpBlueprintLookup();
lookup.dmpBlueprintSubQuery.ids = dmpBlueprints; lookup.dmpBlueprintSubQuery.ids = dmpBlueprints;
} else lookup.dmpBlueprintSubQuery = null; } else lookup.dmpBlueprintSubQuery = null;
// Dmps // Dmps
let roles = formGroup.get("role")?.value !== null ? [formGroup.get("role")?.value] : null; let roles = formGroup.get("role")?.value !== null ? [formGroup.get("role")?.value] : null;
if (roles && roles?.length > 0) { if (roles && roles?.length > 0) {
lookup.dmpUserSubQuery = this.initializeDmpUserLookup(); lookup.dmpUserSubQuery = DmpFilterService.initializeDmpUserLookup();
lookup.dmpUserSubQuery.userRoles = roles; lookup.dmpUserSubQuery.userRoles = roles;
} else lookup.dmpUserSubQuery = null; } else lookup.dmpUserSubQuery = null;
let references: Guid[] = formGroup.get("references")?.value let references: Guid[] = formGroup.get("references")?.value
?.filter((reference: ReferencesWithType) => reference.referenceType != null && reference.references?.length > 0) ?.filter((reference: ReferencesWithType) => reference.referenceTypeId != null && reference.referenceIds?.length > 0)
?.flatMap((referencesWithType: ReferencesWithType) => referencesWithType.references) as Guid[]; ?.flatMap((referencesWithType: ReferencesWithType) => referencesWithType.referenceIds) as Guid[];
if (references && references?.length > 0) { if (references && references?.length > 0) {
lookup.dmpReferenceSubQuery = this.initializeDmpReferenceLookup(); lookup.dmpReferenceSubQuery = DmpFilterService.initializeDmpReferenceLookup();
lookup.dmpReferenceSubQuery.referenceIds = references; lookup.dmpReferenceSubQuery.referenceIds = references;
} else lookup.dmpReferenceSubQuery = null; } else lookup.dmpReferenceSubQuery = null;
@ -383,26 +385,15 @@ export class DmpListingComponent extends BaseListingComponent<BaseDmp, DmpLookup
} }
_patchReferenceFiltersFromForm(formGroup: UntypedFormGroup): ReferencesWithType[] { _patchReferenceFiltersFromForm(formGroup: UntypedFormGroup): ReferencesWithType[] {
return formGroup?.get("references")?.value?.filter(reference => reference.referenceType != null && reference.references?.length > 0) ?? null; return formGroup?.get("references")?.value?.filter(( referencesWithType: ReferencesWithType ) => referencesWithType != null && referencesWithType.referenceIds?.length > 0) ?? null;
} }
private _buildFormFromLookup(lookup: DmpLookup, referenceFilters: ReferencesWithType[]): UntypedFormGroup { private _buildFormFromLookup(lookup: DmpLookup): UntypedFormGroup {
const formArray = this.formBuilder.array([]) as UntypedFormArray;
referenceFilters?.forEach(reference => {
let referenceForm = this.formBuilder.group({
referenceType: reference.referenceType,
references: reference.references?.length > 0 ? [reference.references] : []
});
formArray.push(referenceForm);
});
return (new UntypedFormBuilder()).group({ return (new UntypedFormBuilder()).group({
status: [lookup.statuses?.length > 0 ? lookup.statuses[0] : null], status: [lookup.statuses?.length > 0 ? lookup.statuses[0] : null],
descriptionTemplates: lookup.dmpDescriptionTemplateSubQuery?.descriptionTemplateGroupIds ? [lookup.dmpDescriptionTemplateSubQuery?.descriptionTemplateGroupIds] : [], descriptionTemplates: lookup.dmpDescriptionTemplateSubQuery?.descriptionTemplateGroupIds ? [lookup.dmpDescriptionTemplateSubQuery?.descriptionTemplateGroupIds] : [],
dmpBlueprints: lookup.dmpBlueprintSubQuery?.ids ? [lookup.dmpBlueprintSubQuery?.ids]: [], dmpBlueprints: lookup.dmpBlueprintSubQuery?.ids ? [lookup.dmpBlueprintSubQuery?.ids]: [],
role: lookup.dmpUserSubQuery?.userRoles ? lookup.dmpUserSubQuery?.userRoles[0] : null, role: lookup.dmpUserSubQuery?.userRoles ? lookup.dmpUserSubQuery?.userRoles[0] : null,
references: formArray
}); });
} }
@ -471,60 +462,6 @@ export class DmpListingComponent extends BaseListingComponent<BaseDmp, DmpLookup
[nameof<Dmp>(x => x.dmpDescriptionTemplates), nameof<DmpDescriptionTemplate>(x => x.sectionId)].join('.'), [nameof<Dmp>(x => x.dmpDescriptionTemplates), nameof<DmpDescriptionTemplate>(x => x.sectionId)].join('.'),
[nameof<Dmp>(x => x.dmpDescriptionTemplates), nameof<DmpDescriptionTemplate>(x => x.descriptionTemplateGroupId)].join('.'), [nameof<Dmp>(x => x.dmpDescriptionTemplates), nameof<DmpDescriptionTemplate>(x => x.descriptionTemplateGroupId)].join('.'),
[nameof<Dmp>(x => x.dmpDescriptionTemplates), nameof<DmpDescriptionTemplate>(x => x.isActive)].join('.'), [nameof<Dmp>(x => x.dmpDescriptionTemplates), nameof<DmpDescriptionTemplate>(x => x.isActive)].join('.'),
]; ];
} }
protected initializeDmpDescriptionTemplateLookup(): DmpDescriptionTemplateLookup {
const lookup = new DmpDescriptionTemplateLookup();
lookup.metadata = { countAll: true };
lookup.isActive = [IsActive.Active];
lookup.project = {
fields: [
[nameof<Dmp>(x => x.dmpDescriptionTemplates), nameof<DmpDescriptionTemplate>(x => x.descriptionTemplateGroupId)].join('.'),
[nameof<Dmp>(x => x.dmpDescriptionTemplates), nameof<DmpDescriptionTemplate>(x => x.dmp), nameof<Dmp>(x => x.id)].join('.'),
]
};
return lookup;
}
protected initializeDmpBlueprintLookup(): DmpBlueprintLookup {
const lookup = new DmpBlueprintLookup();
lookup.metadata = { countAll: true };
lookup.isActive = [IsActive.Active];
lookup.project = {
fields: [
[nameof<Dmp>(x => x.blueprint), nameof<DmpBlueprint>(x => x.id)].join('.'),
]
};
return lookup;
}
protected initializeDmpUserLookup(): DmpUserLookup {
const lookup = new DmpUserLookup();
lookup.metadata = { countAll: true };
lookup.isActive = [IsActive.Active];
lookup.project = {
fields: [
[nameof<Dmp>(x => x.dmpUsers), nameof<DmpUser>(x => x.role)].join('.'),
]
};
return lookup;
}
private initializeDmpReferenceLookup(): DmpReferenceLookup {
const lookup = new DmpReferenceLookup();
lookup.metadata = { countAll: true };
lookup.isActive = [IsActive.Active];
lookup.project = {
fields: [
[nameof<Dmp>(x => x.dmpReferences), nameof<Reference>(x => x.id)].join('.'),
]
};
return lookup;
}
} }

View File

@ -11,6 +11,7 @@ import { DmpInvitationDialogModule } from '../invitation/dialog/dmp-invitation-d
import { DmpFilterDialogComponent } from './filtering/dmp-filter-dialog/dmp-filter-dialog.component'; import { DmpFilterDialogComponent } from './filtering/dmp-filter-dialog/dmp-filter-dialog.component';
import { DmpFilterComponent } from './filtering/dmp-filter.component'; import { DmpFilterComponent } from './filtering/dmp-filter.component';
import { AutoCompleteModule } from '@app/library/auto-complete/auto-complete.module'; import { AutoCompleteModule } from '@app/library/auto-complete/auto-complete.module';
import { DmpFilterService } from './filtering/services/dmp-filter.service';
@NgModule({ @NgModule({
imports: [ imports: [
@ -31,6 +32,7 @@ import { AutoCompleteModule } from '@app/library/auto-complete/auto-complete.mod
], ],
exports: [ exports: [
DmpListingItemComponent DmpListingItemComponent
] ],
providers: [ DmpFilterService ]
}) })
export class DmpListingModule { } export class DmpListingModule { }

View File

@ -1,6 +1,7 @@
<a class="col-auto d-flex pointer" (click)="onClose()"><span class="ml-auto mt-3 material-icons clear-icon">clear</span></a> <a class="col-auto d-flex pointer" (click)="onClose()"><span class="ml-auto mt-3 material-icons clear-icon">clear</span></a>
<app-dmp-filter-component <app-dmp-filter-component
[filterFormGroup]="data.filterForm" [filterFormGroup]="data.filterForm"
[referencesWithTypeItems]="data.referencesWithTypeItems"
[isPublic]="data.isPublic" [isPublic]="data.isPublic"
(filterChanged)="onFilterChanged($event)" (filterChanged)="onFilterChanged($event)"
></app-dmp-filter-component> ></app-dmp-filter-component>

View File

@ -3,6 +3,7 @@ import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { UntypedFormGroup } from '@angular/forms'; import { UntypedFormGroup } from '@angular/forms';
import { AnalyticsService } from '@app/core/services/matomo/analytics-service'; import { AnalyticsService } from '@app/core/services/matomo/analytics-service';
import { DmpFilterComponent } from '../dmp-filter.component'; import { DmpFilterComponent } from '../dmp-filter.component';
import { ReferencesWithType } from '@app/core/query/description.lookup';
@Component({ @Component({
selector: 'dmp-filter-dialog-component', selector: 'dmp-filter-dialog-component',
@ -20,6 +21,7 @@ export class DmpFilterDialogComponent implements OnInit {
@Inject(MAT_DIALOG_DATA) public data: { @Inject(MAT_DIALOG_DATA) public data: {
isPublic: boolean, isPublic: boolean,
filterForm: UntypedFormGroup, filterForm: UntypedFormGroup,
referencesWithTypeItems: ReferencesWithType[];
}) { } }) { }
ngOnInit() { ngOnInit() {

View File

@ -60,18 +60,18 @@
<ng-container *ngFor="let referenceForm of filterFormGroup.get('references')?.controls; let i=index"> <ng-container *ngFor="let referenceForm of filterFormGroup.get('references')?.controls; let i=index">
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">
<mat-form-field class="w-100" *ngIf="referenceForm.get('referenceType')"> <mat-form-field class="w-100" *ngIf="referenceForm.get('referenceTypeId')">
<mat-label>{{'DESCRIPTION-LISTING.FILTERS.REFERENCE-TYPES.REFERENCE-TYPE' | translate}}</mat-label> <mat-label>{{'DESCRIPTION-LISTING.FILTERS.REFERENCE-TYPES.REFERENCE-TYPE' | translate}}</mat-label>
<app-single-auto-complete [formControl]="referenceForm.get('referenceType')" [configuration]="referenceTypeAutocompleteConfiguration"> <app-single-auto-complete [formControl]="referenceForm.get('referenceTypeId')" [configuration]="referenceTypeAutocompleteConfiguration">
</app-single-auto-complete> </app-single-auto-complete>
</mat-form-field> </mat-form-field>
</div> </div>
</div> </div>
<div class="row" *ngIf="referenceForm.get('referenceType')?.value && selectReferenceAutocompleteConfiguration(referenceForm.get('referenceType').value)"> <div class="row" *ngIf="referenceForm.get('referenceTypeId')?.value && selectReferenceAutocompleteConfiguration(referenceForm.get('referenceTypeId').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)"> <app-multiple-auto-complete [formControl]="referenceForm.get('referenceIds')" [configuration]="selectReferenceAutocompleteConfiguration(referenceForm.get('referenceTypeId').value)">
</app-multiple-auto-complete> </app-multiple-auto-complete>
</mat-form-field> </mat-form-field>
</div> </div>

View File

@ -1,5 +1,5 @@
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 { AbstractControl, 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';
import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model'; import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
@ -14,7 +14,13 @@ 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 { ReferenceService } from '@app/core/services/reference/reference.service'; import { ReferenceService } from '@app/core/services/reference/reference.service';
import { ReferenceLookup } from '@app/core/query/reference.lookup';
import { IsActive } from '@notification-service/core/enum/is-active.enum';
import { nameof } from 'ts-simple-nameof';
import { Reference } from '@app/core/model/reference/reference'; import { Reference } from '@app/core/model/reference/reference';
import { ReferenceType } from '@app/core/model/reference-type/reference-type';
import { QueryResult } from '@common/model/query-result';
import { ReferencesWithType } from '@app/core/query/description.lookup';
@Component({ @Component({
selector: 'app-dmp-filter-component', selector: 'app-dmp-filter-component',
@ -25,6 +31,7 @@ export class DmpFilterComponent extends BaseCriteriaComponent implements OnInit,
@Input() showGrant: boolean; @Input() showGrant: boolean;
@Input() isPublic: boolean; @Input() isPublic: boolean;
@Input() referencesWithTypeItems: ReferencesWithType[];
@Input() filterFormGroup: UntypedFormGroup; @Input() filterFormGroup: UntypedFormGroup;
@Output() filterChanged: EventEmitter<any> = new EventEmitter(); @Output() filterChanged: EventEmitter<any> = new EventEmitter();
@ -33,7 +40,6 @@ export class DmpFilterComponent extends BaseCriteriaComponent implements OnInit,
filteringGrantsAsync = false; filteringGrantsAsync = false;
sizeError = false; sizeError = false;
maxFileSize: number = 1048576; maxFileSize: number = 1048576;
filteringOrganisationsAsync = false;
descriptionTemplateAutoCompleteConfiguration: MultipleAutoCompleteConfiguration; descriptionTemplateAutoCompleteConfiguration: MultipleAutoCompleteConfiguration;
dmpBlueprintAutoCompleteConfiguration: MultipleAutoCompleteConfiguration; dmpBlueprintAutoCompleteConfiguration: MultipleAutoCompleteConfiguration;
@ -66,35 +72,29 @@ export class DmpFilterComponent extends BaseCriteriaComponent implements OnInit,
this.formGroup = this.filterFormGroup; this.formGroup = this.filterFormGroup;
const formArray = this.formGroup.get('references') as UntypedFormArray; this.referencesWithTypeItems.forEach((referencesWithType: ReferencesWithType) => {
formArray?.controls.forEach(control => { if (referencesWithType.referenceTypeId) {
this.addReferenceType(referencesWithType.referenceTypeId.toString(), referencesWithType.referenceIds.map(x => x.toString()));
let referenceTypeId: string = control.get('referenceType')?.value;
if (referenceTypeId && referenceTypeId != '') {
let excludedReferences = control.get('references')?.value ?? [];
let referenceAutocomplete = this.getReferenceAutocompleteConfiguration(Guid.parse(referenceTypeId), excludedReferences);
this.referenceAutocompleteConfiguration.set(referenceTypeId, referenceAutocomplete);
} }
else if (referencesWithType.referenceIds && referencesWithType.referenceIds?.length > 0) {
this.referenceService.query(this._referenceLookup(referencesWithType.referenceIds)).pipe(takeUntil(this._destroyed))
.subscribe((result: QueryResult<Reference>) => {
const references: Reference[] = result.items;
control.get('referenceType')?.valueChanges.pipe(takeUntil(this._destroyed)) const groupedReferencesByTypeIds = new Map<string, string[]>();
.subscribe(referenceType => { references.forEach(reference => {
this.referenceTypeAutocompleteConfiguration = this.getReferenceTypeAutocompleteConfiguration(); if (!groupedReferencesByTypeIds.has(reference.type.id.toString())) groupedReferencesByTypeIds.set(reference.type.id.toString(), []);
if (referenceTypeId && referenceTypeId != '') { groupedReferencesByTypeIds.get(reference.type.id.toString()).push(reference.id.toString());
let excludedReferences = control.get('references')?.value ?? [];
let referenceAutocomplete = this.getReferenceAutocompleteConfiguration(Guid.parse(referenceTypeId), excludedReferences);
this.referenceAutocompleteConfiguration.set(referenceTypeId, referenceAutocomplete);
}
control.get('references')?.reset()
}); });
control.get('references')?.valueChanges.pipe(takeUntil(this._destroyed)) groupedReferencesByTypeIds.forEach((referenceIds: string[], referenceId: string) => {
.subscribe(references => { this.addReferenceType(referenceId, referenceIds);
let referenceAutocomplete = this.getReferenceAutocompleteConfiguration(Guid.parse(referenceTypeId), references ?? []);
this.referenceAutocompleteConfiguration.set(referenceTypeId, referenceAutocomplete);
}); });
}); });
} }
});
}
} }
onCallbackError(error: any) { onCallbackError(error: any) {
@ -111,36 +111,23 @@ export class DmpFilterComponent extends BaseCriteriaComponent implements OnInit,
} }
} }
addReferenceType(): void { addReferenceType(referenceTypeId: string = null, referenceIds: string[] = null): void {
if (!this.formGroup.get('references')) this.formGroup.addControl('references', this.formBuilder.array([])); if (!this.formGroup.get('references')) this.formGroup.addControl('references', this.formBuilder.array([]));
const formArray = this.formGroup.get('references') as UntypedFormArray; const formArray = this.formGroup.get('references') as UntypedFormArray;
const referenceForm = this.formBuilder.group({ const referenceForm: UntypedFormGroup = this.formBuilder.group({
referenceType: null, referenceTypeId: referenceTypeId,
references: [] referenceIds: referenceIds ? [referenceIds] : null,
}); });
referenceForm?.get('referenceType')?.valueChanges.pipe(takeUntil(this._destroyed)) if (referenceTypeId && referenceTypeId != '' && referenceIds && referenceIds.length > 0) {
.subscribe((referenceTypeId: string) => { let referenceAutocomplete = this.getReferenceAutocompleteConfiguration(Guid.parse(referenceTypeId));
this.referenceTypeAutocompleteConfiguration = this.getReferenceTypeAutocompleteConfiguration();
referenceForm.get('references')?.reset();
if (referenceTypeId) {
let referenceAutocomplete = this.getReferenceAutocompleteConfiguration(Guid.parse(referenceTypeId), []);
this.referenceAutocompleteConfiguration.set(referenceTypeId, referenceAutocomplete); this.referenceAutocompleteConfiguration.set(referenceTypeId, referenceAutocomplete);
} }
});
referenceForm.get('references')?.valueChanges.pipe(takeUntil(this._destroyed)) this._registerReferenceTypeListener(referenceForm);
.subscribe(references => { this._registerReferencesListener(referenceForm);
let referenceTypeId = references?.filter(reference => reference?.type?.id != null)?.first?.type?.id ?? null;
if (!referenceTypeId) return;
let referenceAutocomplete = this.getReferenceAutocompleteConfiguration(referenceTypeId, references ?? []);
this.referenceAutocompleteConfiguration.set(referenceTypeId, referenceAutocomplete);
});
formArray.push(referenceForm); formArray.push(referenceForm);
} }
@ -164,8 +151,49 @@ export class DmpFilterComponent extends BaseCriteriaComponent implements OnInit,
return this.referenceTypeService.getSingleAutocompleteConfigurationForDmp(); return this.referenceTypeService.getSingleAutocompleteConfigurationForDmp();
} }
private getReferenceAutocompleteConfiguration(referenceTypeId: Guid, excludedIds: Reference[]): MultipleAutoCompleteConfiguration { private getReferenceAutocompleteConfiguration(referenceTypeId: Guid): MultipleAutoCompleteConfiguration {
let autocomplete = this.referenceService.getMultipleAutoCompleteQueryConfiguration([referenceTypeId]); let autocomplete = this.referenceService.getMultipleAutoCompleteQueryConfiguration([referenceTypeId]);
return autocomplete; return autocomplete;
}; };
private _referenceLookup(ids: Guid[]): ReferenceLookup {
const lookup: ReferenceLookup = new ReferenceLookup();
lookup.page = { size: 100, offset: 0 };
if (ids && ids.length > 0) { lookup.ids = ids; }
lookup.isActive = [IsActive.Active];
lookup.project = {
fields: [
nameof<Reference>(x => x.id),
nameof<Reference>(x => x.label),
[nameof<Reference>(x => x.type), nameof<ReferenceType>(x => x.id)].join('.'),
[nameof<Reference>(x => x.type), nameof<ReferenceType>(x => x.name)].join('.'),
]
};
lookup.order = { items: [nameof<Reference>(x => x.label)] };
return lookup;
}
private _registerReferenceTypeListener(control: AbstractControl) {
control.get('referenceTypeId')?.valueChanges.pipe(takeUntil(this._destroyed))
.subscribe((referenceTypeId: string) => {
this.referenceTypeAutocompleteConfiguration = this.getReferenceTypeAutocompleteConfiguration();
control.get('referenceIds')?.reset();
if (referenceTypeId && referenceTypeId != '') {
let referenceAutocomplete = this.getReferenceAutocompleteConfiguration(Guid.parse(referenceTypeId));
this.referenceAutocompleteConfiguration.set(referenceTypeId, referenceAutocomplete);
}
});
}
private _registerReferencesListener(control: AbstractControl) {
control.get('referenceIds')?.valueChanges.pipe(takeUntil(this._destroyed))
.subscribe(references => {
let referenceTypeId = control.get('referenceTypeId').value;
if (!referenceTypeId) return;
let referenceAutocomplete = this.getReferenceAutocompleteConfiguration(Guid.parse(referenceTypeId));
this.referenceAutocompleteConfiguration.set(referenceTypeId, referenceAutocomplete);
});
}
} }

View File

@ -0,0 +1,68 @@
import { Injectable } from "@angular/core";
import { DmpBlueprint } from "@app/core/model/dmp-blueprint/dmp-blueprint";
import { Dmp, DmpDescriptionTemplate, DmpUser } from "@app/core/model/dmp/dmp";
import { Reference } from "@app/core/model/reference/reference";
import { DmpBlueprintLookup } from "@app/core/query/dmp-blueprint.lookup";
import { DmpDescriptionTemplateLookup } from "@app/core/query/dmp-description-template.lookup";
import { DmpUserLookup } from "@app/core/query/dmp-user.lookup";
import { DmpReferenceLookup } from "@app/core/query/reference.lookup";
import { IsActive } from "@notification-service/core/enum/is-active.enum";
import { nameof } from "ts-simple-nameof";
@Injectable()
export class DmpFilterService {
public static initializeDmpDescriptionTemplateLookup(): DmpDescriptionTemplateLookup {
const lookup = new DmpDescriptionTemplateLookup();
lookup.metadata = { countAll: true };
lookup.isActive = [IsActive.Active];
lookup.project = {
fields: [
[nameof<Dmp>(x => x.dmpDescriptionTemplates), nameof<DmpDescriptionTemplate>(x => x.descriptionTemplateGroupId)].join('.'),
[nameof<Dmp>(x => x.dmpDescriptionTemplates), nameof<DmpDescriptionTemplate>(x => x.dmp), nameof<Dmp>(x => x.id)].join('.'),
]
};
return lookup;
}
public static initializeDmpBlueprintLookup(): DmpBlueprintLookup {
const lookup = new DmpBlueprintLookup();
lookup.metadata = { countAll: true };
lookup.isActive = [IsActive.Active];
lookup.project = {
fields: [
[nameof<Dmp>(x => x.blueprint), nameof<DmpBlueprint>(x => x.id)].join('.'),
]
};
return lookup;
}
public static initializeDmpUserLookup(): DmpUserLookup {
const lookup = new DmpUserLookup();
lookup.metadata = { countAll: true };
lookup.isActive = [IsActive.Active];
lookup.project = {
fields: [
[nameof<Dmp>(x => x.dmpUsers), nameof<DmpUser>(x => x.role)].join('.'),
]
};
return lookup;
}
public static initializeDmpReferenceLookup(): DmpReferenceLookup {
const lookup = new DmpReferenceLookup();
lookup.metadata = { countAll: true };
lookup.isActive = [IsActive.Active];
lookup.project = {
fields: [
[nameof<Dmp>(x => x.dmpReferences), nameof<Reference>(x => x.id)].join('.'),
]
};
return lookup;
}
}