dmp reference-filter refactor
This commit is contained in:
parent
6efa045412
commit
403190c786
|
@ -47,8 +47,10 @@ export interface DescriptionFilter {
|
|||
}
|
||||
|
||||
export class ReferencesWithType {
|
||||
referenceType: Guid;
|
||||
references: Guid[];
|
||||
referenceType?: Guid;
|
||||
referenceTypeId?: Guid;
|
||||
referenceIds?: Guid[];
|
||||
references?: Guid[];
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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 { MatPaginator } from '@angular/material/paginator';
|
||||
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 { QueryParamsService } from '@app/core/services/utilities/query-params.service';
|
||||
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 { DmpReferenceLookup } from '@app/core/query/reference.lookup';
|
||||
import { DmpFilterService } from './filtering/services/dmp-filter.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-dmp-listing-component',
|
||||
|
@ -109,7 +106,6 @@ export class DmpListingComponent extends BaseListingComponent<BaseDmp, DmpLookup
|
|||
private authService: AuthService,
|
||||
private guidedTourService: GuidedTourService,
|
||||
private analyticsService: AnalyticsService,
|
||||
private formBuilder: FormBuilder,
|
||||
) {
|
||||
super(router, route, uiNotificationService, httpErrorHandlingService, queryParamsService);
|
||||
}
|
||||
|
@ -128,9 +124,14 @@ export class DmpListingComponent extends BaseListingComponent<BaseDmp, DmpLookup
|
|||
const queryParams = this.route.snapshot.queryParams;
|
||||
|
||||
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);
|
||||
} 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) {
|
||||
|
||||
|
@ -269,7 +270,8 @@ export class DmpListingComponent extends BaseListingComponent<BaseDmp, DmpLookup
|
|||
panelClass: 'dialog-side-panel',
|
||||
data: {
|
||||
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
|
||||
let descriptionTemplates = formGroup.get("descriptionTemplates")?.value ?? null;
|
||||
if (descriptionTemplates && descriptionTemplates?.length > 0) {
|
||||
lookup.dmpDescriptionTemplateSubQuery = this.initializeDmpDescriptionTemplateLookup();
|
||||
lookup.dmpDescriptionTemplateSubQuery = DmpFilterService.initializeDmpDescriptionTemplateLookup();
|
||||
lookup.dmpDescriptionTemplateSubQuery.descriptionTemplateGroupIds = descriptionTemplates;
|
||||
} else lookup.dmpDescriptionTemplateSubQuery = null;
|
||||
|
||||
|
@ -358,23 +360,23 @@ export class DmpListingComponent extends BaseListingComponent<BaseDmp, DmpLookup
|
|||
|
||||
let dmpBlueprints = formGroup.get("dmpBlueprints")?.value ?? null;
|
||||
if (dmpBlueprints && dmpBlueprints?.length > 0) {
|
||||
lookup.dmpBlueprintSubQuery = this.initializeDmpBlueprintLookup();
|
||||
lookup.dmpBlueprintSubQuery = DmpFilterService.initializeDmpBlueprintLookup();
|
||||
lookup.dmpBlueprintSubQuery.ids = dmpBlueprints;
|
||||
} else lookup.dmpBlueprintSubQuery = null;
|
||||
|
||||
// Dmps
|
||||
let roles = formGroup.get("role")?.value !== null ? [formGroup.get("role")?.value] : null;
|
||||
if (roles && roles?.length > 0) {
|
||||
lookup.dmpUserSubQuery = this.initializeDmpUserLookup();
|
||||
lookup.dmpUserSubQuery = DmpFilterService.initializeDmpUserLookup();
|
||||
lookup.dmpUserSubQuery.userRoles = roles;
|
||||
} else lookup.dmpUserSubQuery = null;
|
||||
|
||||
let references: Guid[] = formGroup.get("references")?.value
|
||||
?.filter((reference: ReferencesWithType) => reference.referenceType != null && reference.references?.length > 0)
|
||||
?.flatMap((referencesWithType: ReferencesWithType) => referencesWithType.references) as Guid[];
|
||||
?.filter((reference: ReferencesWithType) => reference.referenceTypeId != null && reference.referenceIds?.length > 0)
|
||||
?.flatMap((referencesWithType: ReferencesWithType) => referencesWithType.referenceIds) as Guid[];
|
||||
|
||||
if (references && references?.length > 0) {
|
||||
lookup.dmpReferenceSubQuery = this.initializeDmpReferenceLookup();
|
||||
lookup.dmpReferenceSubQuery = DmpFilterService.initializeDmpReferenceLookup();
|
||||
lookup.dmpReferenceSubQuery.referenceIds = references;
|
||||
} else lookup.dmpReferenceSubQuery = null;
|
||||
|
||||
|
@ -383,26 +385,15 @@ export class DmpListingComponent extends BaseListingComponent<BaseDmp, DmpLookup
|
|||
}
|
||||
|
||||
_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 {
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
private _buildFormFromLookup(lookup: DmpLookup): UntypedFormGroup {
|
||||
return (new UntypedFormBuilder()).group({
|
||||
status: [lookup.statuses?.length > 0 ? lookup.statuses[0] : null],
|
||||
descriptionTemplates: lookup.dmpDescriptionTemplateSubQuery?.descriptionTemplateGroupIds ? [lookup.dmpDescriptionTemplateSubQuery?.descriptionTemplateGroupIds] : [],
|
||||
dmpBlueprints: lookup.dmpBlueprintSubQuery?.ids ? [lookup.dmpBlueprintSubQuery?.ids]: [],
|
||||
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.descriptionTemplateGroupId)].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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import { DmpInvitationDialogModule } from '../invitation/dialog/dmp-invitation-d
|
|||
import { DmpFilterDialogComponent } from './filtering/dmp-filter-dialog/dmp-filter-dialog.component';
|
||||
import { DmpFilterComponent } from './filtering/dmp-filter.component';
|
||||
import { AutoCompleteModule } from '@app/library/auto-complete/auto-complete.module';
|
||||
import { DmpFilterService } from './filtering/services/dmp-filter.service';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
|
@ -31,6 +32,7 @@ import { AutoCompleteModule } from '@app/library/auto-complete/auto-complete.mod
|
|||
],
|
||||
exports: [
|
||||
DmpListingItemComponent
|
||||
]
|
||||
],
|
||||
providers: [ DmpFilterService ]
|
||||
})
|
||||
export class DmpListingModule { }
|
||||
|
|
|
@ -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>
|
||||
<app-dmp-filter-component
|
||||
[filterFormGroup]="data.filterForm"
|
||||
[referencesWithTypeItems]="data.referencesWithTypeItems"
|
||||
[isPublic]="data.isPublic"
|
||||
(filterChanged)="onFilterChanged($event)"
|
||||
></app-dmp-filter-component>
|
||||
|
|
|
@ -3,6 +3,7 @@ import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
|||
import { UntypedFormGroup } from '@angular/forms';
|
||||
import { AnalyticsService } from '@app/core/services/matomo/analytics-service';
|
||||
import { DmpFilterComponent } from '../dmp-filter.component';
|
||||
import { ReferencesWithType } from '@app/core/query/description.lookup';
|
||||
|
||||
@Component({
|
||||
selector: 'dmp-filter-dialog-component',
|
||||
|
@ -20,6 +21,7 @@ export class DmpFilterDialogComponent implements OnInit {
|
|||
@Inject(MAT_DIALOG_DATA) public data: {
|
||||
isPublic: boolean,
|
||||
filterForm: UntypedFormGroup,
|
||||
referencesWithTypeItems: ReferencesWithType[];
|
||||
}) { }
|
||||
|
||||
ngOnInit() {
|
||||
|
|
|
@ -60,18 +60,18 @@
|
|||
<ng-container *ngFor="let referenceForm of filterFormGroup.get('references')?.controls; let i=index">
|
||||
<div class="row">
|
||||
<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>
|
||||
<app-single-auto-complete [formControl]="referenceForm.get('referenceType')" [configuration]="referenceTypeAutocompleteConfiguration">
|
||||
<app-single-auto-complete [formControl]="referenceForm.get('referenceTypeId')" [configuration]="referenceTypeAutocompleteConfiguration">
|
||||
</app-single-auto-complete>
|
||||
</mat-form-field>
|
||||
</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">
|
||||
<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)">
|
||||
<app-multiple-auto-complete [formControl]="referenceForm.get('referenceIds')" [configuration]="selectReferenceAutocompleteConfiguration(referenceForm.get('referenceTypeId').value)">
|
||||
</app-multiple-auto-complete>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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 { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model';
|
||||
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 { takeUntil } from 'rxjs';
|
||||
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 { 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({
|
||||
selector: 'app-dmp-filter-component',
|
||||
|
@ -25,6 +31,7 @@ export class DmpFilterComponent extends BaseCriteriaComponent implements OnInit,
|
|||
|
||||
@Input() showGrant: boolean;
|
||||
@Input() isPublic: boolean;
|
||||
@Input() referencesWithTypeItems: ReferencesWithType[];
|
||||
@Input() filterFormGroup: UntypedFormGroup;
|
||||
@Output() filterChanged: EventEmitter<any> = new EventEmitter();
|
||||
|
||||
|
@ -33,7 +40,6 @@ export class DmpFilterComponent extends BaseCriteriaComponent implements OnInit,
|
|||
filteringGrantsAsync = false;
|
||||
sizeError = false;
|
||||
maxFileSize: number = 1048576;
|
||||
filteringOrganisationsAsync = false;
|
||||
|
||||
descriptionTemplateAutoCompleteConfiguration: MultipleAutoCompleteConfiguration;
|
||||
dmpBlueprintAutoCompleteConfiguration: MultipleAutoCompleteConfiguration;
|
||||
|
@ -66,33 +72,27 @@ export class DmpFilterComponent extends BaseCriteriaComponent implements OnInit,
|
|||
|
||||
this.formGroup = this.filterFormGroup;
|
||||
|
||||
const formArray = this.formGroup.get('references') as UntypedFormArray;
|
||||
formArray?.controls.forEach(control => {
|
||||
|
||||
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);
|
||||
this.referencesWithTypeItems.forEach((referencesWithType: ReferencesWithType) => {
|
||||
if (referencesWithType.referenceTypeId) {
|
||||
this.addReferenceType(referencesWithType.referenceTypeId.toString(), referencesWithType.referenceIds.map(x => x.toString()));
|
||||
}
|
||||
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))
|
||||
.subscribe(referenceType => {
|
||||
this.referenceTypeAutocompleteConfiguration = this.getReferenceTypeAutocompleteConfiguration();
|
||||
const groupedReferencesByTypeIds = new Map<string, string[]>();
|
||||
references.forEach(reference => {
|
||||
if (!groupedReferencesByTypeIds.has(reference.type.id.toString())) groupedReferencesByTypeIds.set(reference.type.id.toString(), []);
|
||||
|
||||
if (referenceTypeId && referenceTypeId != '') {
|
||||
let excludedReferences = control.get('references')?.value ?? [];
|
||||
let referenceAutocomplete = this.getReferenceAutocompleteConfiguration(Guid.parse(referenceTypeId), excludedReferences);
|
||||
this.referenceAutocompleteConfiguration.set(referenceTypeId, referenceAutocomplete);
|
||||
}
|
||||
control.get('references')?.reset()
|
||||
});
|
||||
groupedReferencesByTypeIds.get(reference.type.id.toString()).push(reference.id.toString());
|
||||
});
|
||||
|
||||
control.get('references')?.valueChanges.pipe(takeUntil(this._destroyed))
|
||||
.subscribe(references => {
|
||||
let referenceAutocomplete = this.getReferenceAutocompleteConfiguration(Guid.parse(referenceTypeId), references ?? []);
|
||||
this.referenceAutocompleteConfiguration.set(referenceTypeId, referenceAutocomplete);
|
||||
groupedReferencesByTypeIds.forEach((referenceIds: string[], referenceId: string) => {
|
||||
this.addReferenceType(referenceId, referenceIds);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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([]));
|
||||
|
||||
const formArray = this.formGroup.get('references') as UntypedFormArray;
|
||||
|
||||
const referenceForm = this.formBuilder.group({
|
||||
referenceType: null,
|
||||
references: []
|
||||
const referenceForm: UntypedFormGroup = this.formBuilder.group({
|
||||
referenceTypeId: referenceTypeId,
|
||||
referenceIds: referenceIds ? [referenceIds] : null,
|
||||
});
|
||||
|
||||
referenceForm?.get('referenceType')?.valueChanges.pipe(takeUntil(this._destroyed))
|
||||
.subscribe((referenceTypeId: string) => {
|
||||
this.referenceTypeAutocompleteConfiguration = this.getReferenceTypeAutocompleteConfiguration();
|
||||
referenceForm.get('references')?.reset();
|
||||
|
||||
if (referenceTypeId) {
|
||||
let referenceAutocomplete = this.getReferenceAutocompleteConfiguration(Guid.parse(referenceTypeId), []);
|
||||
this.referenceAutocompleteConfiguration.set(referenceTypeId, referenceAutocomplete);
|
||||
}
|
||||
});
|
||||
|
||||
referenceForm.get('references')?.valueChanges.pipe(takeUntil(this._destroyed))
|
||||
.subscribe(references => {
|
||||
|
||||
let referenceTypeId = references?.filter(reference => reference?.type?.id != null)?.first?.type?.id ?? null;
|
||||
if (!referenceTypeId) return;
|
||||
|
||||
let referenceAutocomplete = this.getReferenceAutocompleteConfiguration(referenceTypeId, references ?? []);
|
||||
if (referenceTypeId && referenceTypeId != '' && referenceIds && referenceIds.length > 0) {
|
||||
let referenceAutocomplete = this.getReferenceAutocompleteConfiguration(Guid.parse(referenceTypeId));
|
||||
this.referenceAutocompleteConfiguration.set(referenceTypeId, referenceAutocomplete);
|
||||
});
|
||||
}
|
||||
|
||||
this._registerReferenceTypeListener(referenceForm);
|
||||
this._registerReferencesListener(referenceForm);
|
||||
|
||||
formArray.push(referenceForm);
|
||||
}
|
||||
|
@ -164,8 +151,49 @@ export class DmpFilterComponent extends BaseCriteriaComponent implements OnInit,
|
|||
return this.referenceTypeService.getSingleAutocompleteConfigurationForDmp();
|
||||
}
|
||||
|
||||
private getReferenceAutocompleteConfiguration(referenceTypeId: Guid, excludedIds: Reference[]): MultipleAutoCompleteConfiguration {
|
||||
private getReferenceAutocompleteConfiguration(referenceTypeId: Guid): MultipleAutoCompleteConfiguration {
|
||||
let autocomplete = this.referenceService.getMultipleAutoCompleteQueryConfiguration([referenceTypeId]);
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue