added dmp reference filter
This commit is contained in:
parent
b7cc78ef4f
commit
b9a62a8abe
backend/core/src/main/java/org/opencdmp/query/lookup
dmp-frontend/src/app
core/query
ui
description/listing
dmp/listing
|
@ -34,6 +34,7 @@ public class DmpLookup extends Lookup {
|
|||
private DmpDescriptionTemplateLookup dmpDescriptionTemplateSubQuery;
|
||||
private DmpUserLookup dmpUserSubQuery;
|
||||
private DmpBlueprintLookup dmpBlueprintSubQuery;
|
||||
private DmpReferenceLookup dmpReferenceSubQuery;
|
||||
|
||||
public String getLike() {
|
||||
return this.like;
|
||||
|
@ -127,6 +128,11 @@ public class DmpLookup extends Lookup {
|
|||
|
||||
public void setDmpBlueprintLookup(DmpBlueprintLookup dmpBlueprintSubQuery) { this.dmpBlueprintSubQuery = dmpBlueprintSubQuery; }
|
||||
|
||||
|
||||
public DmpReferenceLookup getDmpReferenceSubQuery() { return this.dmpReferenceSubQuery; }
|
||||
|
||||
public void setDmpReferenceLookup(DmpReferenceLookup dmpReferenceSubQuery) { this.dmpReferenceSubQuery = dmpReferenceSubQuery; }
|
||||
|
||||
public DmpQuery enrich(QueryFactory queryFactory) {
|
||||
DmpQuery query = queryFactory.query(DmpQuery.class);
|
||||
if (this.like != null) query.like(this.like);
|
||||
|
@ -141,6 +147,7 @@ public class DmpLookup extends Lookup {
|
|||
if (this.dmpDescriptionTemplateSubQuery != null) query.dmpDescriptionTemplateSubQuery(this.dmpDescriptionTemplateSubQuery.enrich(queryFactory));
|
||||
if (this.dmpUserSubQuery != null) query.dmpUserSubQuery(this.dmpUserSubQuery.enrich(queryFactory));
|
||||
if (this.dmpBlueprintSubQuery != null) query.dmpBlueprintSubQuery(this.dmpBlueprintSubQuery.enrich(queryFactory));
|
||||
if (this.dmpReferenceSubQuery != null) query.dmpReferenceSubQuery(this.dmpReferenceSubQuery.enrich(queryFactory));
|
||||
|
||||
this.enrichCommon(query);
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ import { Guid } from '@common/types/guid';
|
|||
import { IsActive } from '../common/enum/is-active.enum';
|
||||
import { DescriptionStatus } from '../common/enum/description-status';
|
||||
import { DmpLookup } from './dmp.lookup';
|
||||
import { DmpUserRole } from '../common/enum/dmp-user-role';
|
||||
import { ReferenceType } from '../model/reference-type/reference-type';
|
||||
import { DescriptionReferenceLookup } from './reference.lookup';
|
||||
import { DescriptionTagLookup } from './tag.lookup';
|
||||
|
@ -25,8 +24,6 @@ export class DescriptionLookup extends Lookup implements DescriptionFilter {
|
|||
descriptionTagSubQuery: DescriptionTagLookup;
|
||||
descriptionReferenceSubQuery: DescriptionReferenceLookup;
|
||||
|
||||
showAllVersions: boolean; //TODO ??
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
@ -42,7 +39,6 @@ export interface DescriptionFilter {
|
|||
finalizedBefore: Date;
|
||||
isActive: IsActive[];
|
||||
statuses: DescriptionStatus[];
|
||||
showAllVersions: boolean;
|
||||
|
||||
dmpSubQuery: DmpLookup;
|
||||
descriptionTemplateSubQuery: DescriptionTemplateLookup;
|
||||
|
|
|
@ -5,9 +5,9 @@ import { DmpStatus } from '../common/enum/dmp-status';
|
|||
import { DmpVersionStatus } from '../common/enum/dmp-version-status';
|
||||
import { IsActive } from '../common/enum/is-active.enum';
|
||||
import { DmpDescriptionTemplateLookup } from './dmp-description-template.lookup';
|
||||
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
|
||||
import { DmpUserLookup } from './dmp-user.lookup';
|
||||
import { DmpBlueprintLookup } from './dmp-blueprint.lookup';
|
||||
import { DmpReferenceLookup } from './reference.lookup';
|
||||
|
||||
export class DmpLookup extends Lookup implements DmpFilter {
|
||||
ids: Guid[];
|
||||
|
@ -23,26 +23,11 @@ export class DmpLookup extends Lookup implements DmpFilter {
|
|||
dmpUserSubQuery: DmpUserLookup;
|
||||
dmpBlueprintSubQuery: DmpBlueprintLookup;
|
||||
dmpDescriptionTemplateSubQuery: DmpDescriptionTemplateLookup;
|
||||
dmpReferenceSubQuery: DmpReferenceLookup
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
from(formGroup: UntypedFormGroup): void {
|
||||
this.statuses = formGroup.get('status')?.value ? [formGroup.get('status')?.value] : null;
|
||||
// this.roleInDmp = formGroup.get('role')?.value ? [formGroup.get('role')?.value] : null;
|
||||
// this.dmpBlueprintIds = formGroup.get('dmpBlueprintIds')?.value ? formGroup.get('dmpBlueprintIds')?.value : null;
|
||||
// this.descriptionTemplateIds = formGroup.get('descriptionTemplateIds')?.value ? formGroup.get('descriptionTemplateIds')?.value : null;
|
||||
}
|
||||
|
||||
buildForm(): UntypedFormGroup {
|
||||
return (new UntypedFormBuilder()).group({
|
||||
status: [this.statuses ? this.statuses[0] : null],
|
||||
// role: [this.roleInDmp ? this.roleInDmp[0] : null],
|
||||
// dmpBlueprintIds: [this.dmpBlueprintIds],
|
||||
// descriptionTemplateIds: [this.descriptionTemplateIds],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export interface DmpFilter {
|
||||
|
|
|
@ -25,6 +25,16 @@ export class DescriptionReferenceLookup extends Lookup {
|
|||
super();
|
||||
}
|
||||
}
|
||||
export class DmpReferenceLookup extends Lookup {
|
||||
referenceIds: Guid[];
|
||||
excludedIds: Guid[];
|
||||
like: string;
|
||||
isActive: IsActive[];
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
export interface ReferenceFilter {
|
||||
ids: Guid[];
|
||||
|
|
|
@ -434,7 +434,6 @@ export class DescriptionListingComponent extends BaseListingComponent<BaseDescri
|
|||
if (!formGroup) return;
|
||||
|
||||
lookup.statuses = formGroup.get("status")?.value !== null ? [formGroup.get("status")?.value] : null;
|
||||
lookup.showAllVersions = formGroup.get("showAllVersions")?.value ?? false;
|
||||
|
||||
// Description Templates
|
||||
let descriptionTemplates = formGroup.get("descriptionTemplates")?.value ?? null;
|
||||
|
@ -496,7 +495,6 @@ export class DescriptionListingComponent extends BaseListingComponent<BaseDescri
|
|||
return (new UntypedFormBuilder()).group({
|
||||
status: [lookup.statuses?.length > 0 ? lookup.statuses[0] : null],
|
||||
role: lookup.dmpSubQuery?.dmpUserSubQuery?.userRoles ? lookup.dmpSubQuery?.dmpUserSubQuery?.userRoles[0] : [],
|
||||
showAllVersions: [lookup.showAllVersions ?? false],
|
||||
descriptionTemplates: lookup.descriptionTemplateSubQuery?.ids ? [lookup.descriptionTemplateSubQuery?.ids] : [],
|
||||
associatedDmpIds: lookup.dmpSubQuery?.ids ? [lookup.dmpSubQuery?.ids] : [],
|
||||
tags: lookup.descriptionTagSubQuery?.tagIds ? [lookup.descriptionTagSubQuery?.tagIds] : [],
|
||||
|
|
|
@ -65,10 +65,10 @@ export class DescriptionFilterComponent extends BaseCriteriaComponent implements
|
|||
ngOnChanges(changes: SimpleChanges): void {
|
||||
if (changes['filterFormGroup']) {
|
||||
|
||||
this.selectedReferenceTypes = this._buildSelectedReferenceTypes(this.filterFormGroup);
|
||||
this.descriptionTemplateAutoCompleteConfiguration = this.descriptionTemplateService.multipleAutocompleteConfiguration;
|
||||
this.dmpAutoCompleteConfiguration = this.dmpService.multipleAutocompleteConfiguration;
|
||||
this.tagAutoCompleteConfiguration = this.tagService.multipleAutocompleteConfiguration;
|
||||
this.selectedReferenceTypes = this._buildSelectedReferenceTypes(this.filterFormGroup);
|
||||
this.referenceTypeAutocompleteConfiguration = this.getReferenceTypeAutocompleteConfiguration(this.selectedReferenceTypes);
|
||||
this.referenceAutocompleteConfiguration = new Map<string, MultipleAutoCompleteConfiguration>();
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
{{ lookup | json }}
|
||||
|
||||
<div class="main-content listing-main-container h-100">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
|
|
|
@ -34,10 +34,11 @@ 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 { DescriptionTemplateLookup } from '@app/core/query/description-template.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';
|
||||
|
||||
@Component({
|
||||
selector: 'app-dmp-listing-component',
|
||||
|
@ -58,6 +59,7 @@ export class DmpListingComponent extends BaseListingComponent<BaseDmp, DmpLookup
|
|||
hasListingItems = null;
|
||||
protected ITEMS_PER_PAGE = 5;
|
||||
pageSize: number = 5;
|
||||
referenceFilters: ReferencesWithType[];
|
||||
public formGroup = new UntypedFormBuilder().group({
|
||||
like: new UntypedFormControl(),
|
||||
order: new UntypedFormControl()
|
||||
|
@ -127,11 +129,6 @@ export class DmpListingComponent extends BaseListingComponent<BaseDmp, DmpLookup
|
|||
}
|
||||
|
||||
this.onPageLoad({ offset: this.lookup.page.offset / this.lookup.page.size } as PageLoadEvent);
|
||||
// this.groupId = params['groupId'];
|
||||
// if (this.groupId != null && Guid.isGuid(this.groupId)) {
|
||||
// this.lookup.groupIds = [Guid.parse(this.groupId)];
|
||||
// }
|
||||
// this.refresh(this.lookup);
|
||||
});
|
||||
|
||||
this.formGroup.get('like').valueChanges
|
||||
|
@ -241,48 +238,12 @@ export class DmpListingComponent extends BaseListingComponent<BaseDmp, DmpLookup
|
|||
this.filterChanged(this.lookup);
|
||||
}
|
||||
|
||||
// private refresh(lookup: DmpLookup) {
|
||||
// if (this.isPublic) {
|
||||
// this.dmpService.publicQuery(lookup).pipe(takeUntil(this._destroyed))
|
||||
// .subscribe(result => {
|
||||
// if (!result) { return []; }
|
||||
// this.totalCount = result.count;
|
||||
// if (lookup?.page?.offset === 0) this.listingItems = [];
|
||||
// this.listingItems.push(...result.items);
|
||||
// this.hasListingItems = true;
|
||||
// },
|
||||
// error => this.httpErrorHandlingService.handleBackedRequestError(error));
|
||||
|
||||
// } else {
|
||||
// this.dmpService.query(lookup).pipe(takeUntil(this._destroyed))
|
||||
// .subscribe(result => {
|
||||
// if (!result) { return []; }
|
||||
// this.totalCount = result.count;
|
||||
// if (lookup?.page?.offset === 0) this.listingItems = [];
|
||||
// result.items.forEach(x => {
|
||||
// if (x.descriptions) {
|
||||
// if (x.status == DmpStatus.Finalized) {
|
||||
// x.descriptions = x.descriptions.filter(x => x.isActive === IsActive.Active && x.status === DescriptionStatus.Finalized);
|
||||
// } else {
|
||||
// x.descriptions = x.descriptions.filter(x => x.isActive === IsActive.Active && x.status !== DescriptionStatus.Canceled);
|
||||
// }
|
||||
// }
|
||||
// x.dmpUsers = x.dmpUsers.filter(x => x.isActive === IsActive.Active);
|
||||
// this.listingItems.push(x);
|
||||
// })
|
||||
// this.hasListingItems = true;
|
||||
// },
|
||||
// error => this.httpErrorHandlingService.handleBackedRequestError(error));
|
||||
// }
|
||||
// }
|
||||
|
||||
controlModified(): void {
|
||||
this.lookup.like = this.formGroup.get("like").value;
|
||||
this.lookup.page = { size: this.pageSize, offset: 0 };
|
||||
this.filterChanged(this.lookup, true);
|
||||
}
|
||||
|
||||
|
||||
openShareDialog(rowId: any, rowName: any) {
|
||||
//TODO: add this
|
||||
}
|
||||
|
@ -297,8 +258,7 @@ export class DmpListingComponent extends BaseListingComponent<BaseDmp, DmpLookup
|
|||
panelClass: 'dialog-side-panel',
|
||||
data: {
|
||||
isPublic: this.isPublic ?? true,
|
||||
filterForm: this._buildFormFromLookup(this.lookup, null),
|
||||
// filterForm: this._buildFormFromLookup(this.lookup, this.referenceFilters),
|
||||
filterForm: this._buildFormFromLookup(this.lookup, this.referenceFilters),
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -310,7 +270,7 @@ export class DmpListingComponent extends BaseListingComponent<BaseDmp, DmpLookup
|
|||
}
|
||||
|
||||
updateDataFn(filterForm: UntypedFormGroup): void {
|
||||
// this.referenceFilters = this._patchReferenceFiltersFromForm(filterForm);
|
||||
this.referenceFilters = this._patchReferenceFiltersFromForm(filterForm);
|
||||
this.lookup = this._patchLookupFromForm(this.lookup, filterForm);
|
||||
this.filterChanged(this.lookup)
|
||||
}
|
||||
|
@ -384,7 +344,6 @@ export class DmpListingComponent extends BaseListingComponent<BaseDmp, DmpLookup
|
|||
|
||||
// Blueprints
|
||||
|
||||
// let dmpBlueprints: lookup.dmpBlueprintSubQuery?.ids ? [lookup.dmpBlueprintSubQuery?.ids]: [],
|
||||
let dmpBlueprints = formGroup.get("dmpBlueprints")?.value ?? null;
|
||||
if (dmpBlueprints && dmpBlueprints?.length > 0) {
|
||||
lookup.dmpBlueprintSubQuery = this.initializeDmpBlueprintLookup();
|
||||
|
@ -398,46 +357,39 @@ export class DmpListingComponent extends BaseListingComponent<BaseDmp, DmpLookup
|
|||
lookup.dmpUserSubQuery.userRoles = roles;
|
||||
} else lookup.dmpUserSubQuery = null;
|
||||
|
||||
// // Tags
|
||||
// let tags = formGroup.get("tags")?.value ?? null;
|
||||
// if (tags && tags?.length > 0) {
|
||||
// lookup.descriptionTagSubQuery = this.initializeTagLookup();
|
||||
// lookup.descriptionTagSubQuery.tagIds = tags;
|
||||
// } else lookup.descriptionTagSubQuery = 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[];
|
||||
|
||||
// // References
|
||||
// let references: Guid[] = formGroup.get("references")?.value
|
||||
// ?.filter((reference: ReferencesWithType) => reference.referenceType != null && reference.references?.length > 0)
|
||||
// ?.flatMap((referencesWithType: ReferencesWithType) => referencesWithType.references) as Guid[];
|
||||
|
||||
// if (references && references?.length > 0) {
|
||||
// lookup.descriptionReferenceSubQuery = this.initializeReferenceLookup();
|
||||
// lookup.descriptionReferenceSubQuery.referenceIds = references;
|
||||
// } else lookup.descriptionReferenceSubQuery = null;
|
||||
if (references && references?.length > 0) {
|
||||
lookup.dmpReferenceSubQuery = this.initializeDmpReferenceLookup();
|
||||
lookup.dmpReferenceSubQuery.referenceIds = references;
|
||||
} else lookup.dmpReferenceSubQuery = null;
|
||||
|
||||
|
||||
return lookup;
|
||||
}
|
||||
|
||||
_patchReferenceFiltersFromForm(formGroup: UntypedFormGroup): ReferencesWithType[] {
|
||||
return formGroup?.get("references")?.value?.filter(reference => reference.referenceType != null && reference.references?.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);
|
||||
// });
|
||||
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({
|
||||
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,
|
||||
// showAllVersions: [lookup.showAllVersions ?? false],
|
||||
// descriptionTemplates: lookup.descriptionTemplateSubQuery?.ids ? [lookup.descriptionTemplateSubQuery?.ids] : [],
|
||||
// associatedDmpIds: lookup.dmpSubQuery?.ids ? [lookup.dmpSubQuery?.ids] : [],
|
||||
// tags: lookup.descriptionTagSubQuery?.tagIds ? [lookup.descriptionTagSubQuery?.tagIds] : [],
|
||||
references: formArray
|
||||
});
|
||||
}
|
||||
|
@ -538,4 +490,17 @@ export class DmpListingComponent extends BaseListingComponent<BaseDmp, DmpLookup
|
|||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
<h6 class="criteria-title">{{'DMP-LISTING.FILTERS.NAME'| translate}}</h6>
|
||||
</div>
|
||||
</div>
|
||||
<!-- <h6 class="filters-title">{{'CRITERIA.FILTERS'| translate}}</h6> -->
|
||||
<div class="row" style="justify-content: center;" *ngIf="formGroup">
|
||||
<!-- Visibility Filter-->
|
||||
<div *ngIf="!isPublic" class="col-10">
|
||||
|
@ -19,19 +18,6 @@
|
|||
</div>
|
||||
<!-- End of Visibility Filter-->
|
||||
|
||||
<!-- Grant Status -->
|
||||
<!-- TODO -->
|
||||
<!-- <div class="col-10" *ngIf="isPublic">
|
||||
<h6 class="category-title">{{ 'FACET-SEARCH.GRANT-STATUS.TITLE' | translate }}</h6>
|
||||
<mat-radio-group [formControl]="formGroup.get('grantStatus')">
|
||||
<mat-radio-button value="null" [checked]="!formGroup.get('grantStatus').value">{{ 'FACET-SEARCH.GRANT-STATUS.OPTIONS.ANY' | translate }}</mat-radio-button>
|
||||
<mat-radio-button value="0">{{ 'FACET-SEARCH.GRANT-STATUS.OPTIONS.ACTIVE' | translate }}</mat-radio-button>
|
||||
<mat-radio-button value="1">{{ 'FACET-SEARCH.GRANT-STATUS.OPTIONS.INACTIVE' | translate }}</mat-radio-button>
|
||||
</mat-radio-group>
|
||||
<hr>
|
||||
</div> -->
|
||||
<!-- End of Grant Status -->
|
||||
|
||||
<!-- Related Dataset Templates Filter -->
|
||||
<div class="col-10">
|
||||
<h6 class="category-title">{{ 'DMP-LISTING.FILTERS.RELATED-DESCRIPTION-TEMPLATES.NAME' | translate}}</h6>
|
||||
|
@ -68,19 +54,47 @@
|
|||
</div>
|
||||
<!-- End of Role Filter -->
|
||||
|
||||
<!-- Related Organization Filter -->
|
||||
<!-- TODO -->
|
||||
<!-- <div *ngIf="showGrant" class="col-10">
|
||||
<h6 class="category-title">{{ 'DMP-RELATED-ORGANIZATION.RELATED-ORGANIZATION' | translate }}</h6>
|
||||
<mat-form-field>
|
||||
<mat-label>{{'DMP-RELATED-ORGANIZATION.SELECT-ORGANIZATIONS' | translate}}</mat-label>
|
||||
<app-multiple-auto-complete [formControl]="formGroup.get('organisations')"
|
||||
[configuration]="organisationAutoCompleteConfiguration">
|
||||
</app-multiple-auto-complete>
|
||||
</mat-form-field>
|
||||
</div> -->
|
||||
<!-- End of Related Organization Filter -->
|
||||
<!-- Reference Types -->
|
||||
<div class="col-10 mb-1">
|
||||
<h6 class="category-title">{{'DESCRIPTION-LISTING.FILTERS.REFERENCE-TYPES.NAME' | translate }}</h6>
|
||||
<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-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>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row" *ngIf="referenceForm.get('referenceType')?.value && selectReferenceAutocompleteConfiguration(referenceForm.get('referenceType').value.id)">
|
||||
<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>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button mat-icon-button class="col-auto" (click)="deleteRow(i)" type="button">
|
||||
<mat-icon>delete</mat-icon>
|
||||
</button>
|
||||
</ng-container>
|
||||
|
||||
<div class="col-10">
|
||||
<div class="row align-items-center">
|
||||
<button mat-icon-button color="primary" [disabled]="false" (click)="addReferenceType()">
|
||||
<mat-icon>add_circle</mat-icon>
|
||||
</button>
|
||||
<span>
|
||||
<span class="mt-1">{{'DESCRIPTION-LISTING.ACTIONS.ADD-REFERENCE-TYPE' | translate}}</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- End of Reference Types -->
|
||||
|
||||
<div class="col-auto ml-auto mb-4">
|
||||
<button class="normal-btn-sm" (click)="controlModified()">
|
||||
{{'DMP-LISTING.FILTERS.APPLY-FILTERS' | translate}}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
import { Component, Input, OnInit, Output, EventEmitter, OnChanges, SimpleChanges } from '@angular/core';
|
||||
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
|
||||
import { 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';
|
||||
|
@ -10,6 +10,13 @@ import { DmpBlueprintService } from '@app/core/services/dmp/dmp-blueprint.servic
|
|||
import { DmpStatus } from '@app/core/common/enum/dmp-status';
|
||||
import { DescriptionTemplateService } from '@app/core/services/description-template/description-template.service';
|
||||
import { DmpUserRole } from '@app/core/common/enum/dmp-user-role';
|
||||
import { SingleAutoCompleteConfiguration } from '@app/library/auto-complete/single/single-auto-complete-configuration';
|
||||
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';
|
||||
|
||||
@Component({
|
||||
selector: 'app-dmp-filter-component',
|
||||
|
@ -29,12 +36,12 @@ export class DmpFilterComponent extends BaseCriteriaComponent implements OnInit,
|
|||
sizeError = false;
|
||||
maxFileSize: number = 1048576;
|
||||
filteringOrganisationsAsync = false;
|
||||
selectedReferenceTypes: Guid[];
|
||||
|
||||
descriptionTemplateAutoCompleteConfiguration: MultipleAutoCompleteConfiguration;
|
||||
dmpBlueprintAutoCompleteConfiguration: MultipleAutoCompleteConfiguration;
|
||||
// get dmpBlueprintAutoCompleteConfiguration(): MultipleAutoCompleteConfiguration {
|
||||
// return this.dmpBlueprintService.multipleAutocompleteConfiguration;
|
||||
// };
|
||||
referenceTypeAutocompleteConfiguration: SingleAutoCompleteConfiguration;
|
||||
referenceAutocompleteConfiguration: Map<string, MultipleAutoCompleteConfiguration>;
|
||||
|
||||
constructor(
|
||||
public language: TranslateService,
|
||||
|
@ -42,6 +49,8 @@ export class DmpFilterComponent extends BaseCriteriaComponent implements OnInit,
|
|||
private authentication: AuthService,
|
||||
private descriptionTemplateService: DescriptionTemplateService,
|
||||
private dmpBlueprintService: DmpBlueprintService,
|
||||
private referenceTypeService: ReferenceTypeService,
|
||||
private referenceService: ReferenceService,
|
||||
) {
|
||||
super(new ValidationErrorModel());
|
||||
}
|
||||
|
@ -52,24 +61,44 @@ export class DmpFilterComponent extends BaseCriteriaComponent implements OnInit,
|
|||
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
if (changes['filterFormGroup']) {
|
||||
this.formGroup = this.filterFormGroup;
|
||||
|
||||
this.descriptionTemplateAutoCompleteConfiguration = this.descriptionTemplateService.descriptionTempalteGroupMultipleAutocompleteConfiguration;
|
||||
this.dmpBlueprintAutoCompleteConfiguration = this.dmpBlueprintService.multipleAutocompleteConfiguration;
|
||||
this.selectedReferenceTypes = this._buildSelectedReferenceTypes(this.filterFormGroup);
|
||||
this.referenceTypeAutocompleteConfiguration = this.getReferenceTypeAutocompleteConfiguration(this.selectedReferenceTypes);
|
||||
this.referenceAutocompleteConfiguration = new Map<string, MultipleAutoCompleteConfiguration>();
|
||||
|
||||
this.formGroup = this.filterFormGroup;
|
||||
|
||||
// this.formGroup.get('role')?.valueChanges
|
||||
// .pipe(takeUntil(this._destroyed))
|
||||
// .subscribe(x => this.controlModified());
|
||||
// this.formGroup.get('status')?.valueChanges
|
||||
// .pipe(takeUntil(this._destroyed))
|
||||
// .subscribe(x => this.controlModified());
|
||||
// this.formGroup.get('descriptionTemplateIds')?.valueChanges
|
||||
// .pipe(takeUntil(this._destroyed))
|
||||
// .subscribe(x => this.controlModified());
|
||||
// this.formGroup.get('dmpBlueprintIds')?.valueChanges
|
||||
// .pipe(takeUntil(this._destroyed))
|
||||
// .subscribe(x => this.controlModified());
|
||||
const formArray = this.formGroup.get('references') as UntypedFormArray;
|
||||
formArray?.controls.forEach(control => {
|
||||
|
||||
let referenceTypeId: string = control.get('referenceType')?.value?.id;
|
||||
if (referenceTypeId && referenceTypeId != '') {
|
||||
let excludedReferences = control.get('references')?.value ?? [];
|
||||
let referenceAutocomplete = this.getReferenceAutocompleteConfiguration(Guid.parse(referenceTypeId), excludedReferences);
|
||||
this.referenceAutocompleteConfiguration.set(referenceTypeId, referenceAutocomplete);
|
||||
}
|
||||
|
||||
control.get('referenceType')?.valueChanges.pipe(takeUntil(this._destroyed))
|
||||
.subscribe(referenceType => {
|
||||
this.selectedReferenceTypes = this._buildSelectedReferenceTypes(this.formGroup);
|
||||
this.referenceTypeAutocompleteConfiguration = this.getReferenceTypeAutocompleteConfiguration(this.selectedReferenceTypes);
|
||||
|
||||
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()
|
||||
});
|
||||
|
||||
control.get('references')?.valueChanges.pipe(takeUntil(this._destroyed))
|
||||
.subscribe(references => {
|
||||
let referenceAutocomplete = this.getReferenceAutocompleteConfiguration(Guid.parse(referenceTypeId), references ?? []);
|
||||
this.referenceAutocompleteConfiguration.set(referenceTypeId, referenceAutocomplete);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,7 +116,73 @@ export class DmpFilterComponent extends BaseCriteriaComponent implements OnInit,
|
|||
}
|
||||
}
|
||||
|
||||
addReferenceType(): 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: []
|
||||
});
|
||||
|
||||
referenceForm?.get('referenceType')?.valueChanges.pipe(takeUntil(this._destroyed))
|
||||
.subscribe((reference: ReferenceType) => {
|
||||
this.selectedReferenceTypes = this._buildSelectedReferenceTypes(this.formGroup);
|
||||
this.referenceTypeAutocompleteConfiguration = this.getReferenceTypeAutocompleteConfiguration(this.selectedReferenceTypes);
|
||||
referenceForm.get('references')?.reset();
|
||||
|
||||
if (reference?.id) {
|
||||
let referenceAutocomplete = this.getReferenceAutocompleteConfiguration(reference.id, []);
|
||||
this.referenceAutocompleteConfiguration.set(reference?.id?.toString(), 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 ?? []);
|
||||
this.referenceAutocompleteConfiguration.set(referenceTypeId, referenceAutocomplete);
|
||||
});
|
||||
|
||||
formArray.push(referenceForm);
|
||||
}
|
||||
|
||||
deleteRow(index: number): void {
|
||||
const formArray = this.formGroup.get('references') as UntypedFormArray;
|
||||
|
||||
formArray.removeAt(index);
|
||||
}
|
||||
|
||||
isAuthenticated(): boolean {
|
||||
return this.authentication.currentAccountIsAuthenticated();
|
||||
}
|
||||
|
||||
selectReferenceAutocompleteConfiguration(referenceTypeId: string): MultipleAutoCompleteConfiguration {
|
||||
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 getReferenceAutocompleteConfiguration(referenceTypeId: Guid, excludedIds: Reference[]): MultipleAutoCompleteConfiguration {
|
||||
let autocomplete = this.referenceService.getMultipleAutoCompleteQueryConfiguration([referenceTypeId]);
|
||||
return autocomplete;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue