-
- - +

{{'DESCRIPTION-LISTING.TEXT-INFO' | translate}} {{'DESCRIPTION-LISTING.LINK-PUBLIC-DESCRIPTIONS' | translate}} {{'DESCRIPTION-LISTING.TEXT-INFO-REST' | translate}}

{{'DESCRIPTION-LISTING.TEXT-INFO-PAR' | translate}} @@ -16,13 +14,13 @@

-
+
-
+
-
-
-
+
+
@@ -84,11 +82,11 @@
-
+
-
+
{{'DESCRIPTION-LISTING.EMPTY-LIST' | translate}}
diff --git a/dmp-frontend/src/app/ui/description/listing/description-listing.component.ts b/dmp-frontend/src/app/ui/description/listing/description-listing.component.ts index b02e90b3f..97757c523 100644 --- a/dmp-frontend/src/app/ui/description/listing/description-listing.component.ts +++ b/dmp-frontend/src/app/ui/description/listing/description-listing.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit, ViewChild } from '@angular/core'; -import { FormBuilder, UntypedFormArray, UntypedFormBuilder, UntypedFormControl, UntypedFormGroup, Validators } from '@angular/forms'; +import { FormBuilder, UntypedFormBuilder, UntypedFormControl, UntypedFormGroup, Validators } from '@angular/forms'; import { MatDialog } from '@angular/material/dialog'; import { MatPaginator } from '@angular/material/paginator'; import { MatSort } from '@angular/material/sort'; @@ -8,7 +8,7 @@ import { IsActive } from '@app/core/common/enum/is-active.enum'; import { AppPermission } from '@app/core/common/enum/permission.enum'; import { RecentActivityOrder } from '@app/core/common/enum/recent-activity-order'; import { DescriptionTemplate } from '@app/core/model/description-template/description-template'; -import { BaseDescription, Description, DescriptionReference, DescriptionTag } from '@app/core/model/description/description'; +import { BaseDescription, Description } from '@app/core/model/description/description'; import { DmpBlueprint, DmpBlueprintDefinition, DmpBlueprintDefinitionSection } from '@app/core/model/dmp-blueprint/dmp-blueprint'; import { Dmp, DmpDescriptionTemplate, DmpUser } from '@app/core/model/dmp/dmp'; import { DmpReference } from '@app/core/model/dmp/dmp-reference'; @@ -36,12 +36,7 @@ import { Observable } from 'rxjs'; import { QueryParamsService } from '@app/core/services/utilities/query-params.service'; import { UiNotificationService } from '@app/core/services/notification/ui-notification-service'; import { Guid } from '@common/types/guid'; -import { DescriptionReferenceLookup } from '@app/core/query/reference.lookup'; -import { DescriptionTagLookup } from '@app/core/query/tag.lookup'; -import { Tag } from '@app/core/model/tag/tag'; -import { DmpLookup } from '@app/core/query/dmp.lookup'; -import { DescriptionTemplateLookup } from '@app/core/query/description-template.lookup'; -import { DmpUserLookup } from '@app/core/query/dmp-user.lookup'; +import { DescriptionFilterService } from './filtering/description-filter.service'; @Component({ selector: 'app-description-listing-component', @@ -61,12 +56,11 @@ export class DescriptionListingComponent extends BaseListingComponent 0; + } + get hasFilters(): boolean { + return (this.lookup.like != null && this.lookup.like != '') || this.lookup.statuses != null || + this.lookup.dmpSubQuery != null || this.lookup.descriptionTemplateSubQuery != null || + this.lookup.descriptionTagSubQuery != null || this.lookup.descriptionReferenceSubQuery != null; + } constructor( + protected router: Router, + protected route: ActivatedRoute, + protected uiNotificationService: UiNotificationService, + protected httpErrorHandlingService: HttpErrorHandlingService, + protected queryParamsService: QueryParamsService, public routerUtils: RouterUtilsService, private descriptionService: DescriptionService, public dialog: MatDialog, @@ -107,11 +114,6 @@ export class DescriptionListingComponent extends BaseListingComponent { const queryParams = this.route.snapshot.queryParams; - if (!this.lookup) this.lookup = queryParams['lookup'] ? this._parseLookupFromParams(queryParams) : this.initializeLookup(); + if (!this.lookup && queryParams['lookup']) { + this.lookup = this._parseLookupFromParams(queryParams); + this.referenceFilters = [{ + referenceTypeId: null, + referenceIds: this.lookup?.descriptionReferenceSubQuery?.referenceIds ?? [], + }]; + this.filtersCount = this._countFilters(this.lookup); + } + 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) { @@ -161,7 +172,7 @@ export class DescriptionListingComponent extends BaseListingComponent(x => x.label)) : this.toDescSortField(nameof(x => x.updatedAt)); @@ -193,74 +203,8 @@ export class DescriptionListingComponent extends BaseListingComponent(x => x.reference), nameof(x => x.id)].join('.'), - ] - }; - return lookup; - } - - protected initializeTagLookup(): DescriptionTagLookup { - const lookup = new DescriptionTagLookup(); - lookup.metadata = { countAll: true }; - lookup.isActive = [IsActive.Active]; - lookup.project = { - fields: [ - [nameof(x => x.tag), nameof(x => x.id)].join('.'), - ] - }; - - return lookup; - } - - protected initializeDmpLookup(): DmpLookup { - const lookup = new DmpLookup(); - lookup.metadata = { countAll: true }; - lookup.isActive = [IsActive.Active]; - lookup.project = { - fields: [ - [nameof(x => x.dmp), nameof(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(x => x.dmpUsers), nameof(x => x.role)].join('.'), - ] - }; - - return lookup; - } - - protected initializeDescriptionTemplateLookup(): DescriptionTemplateLookup { - const lookup = new DescriptionTemplateLookup(); - lookup.metadata = { countAll: true }; - lookup.isActive = [IsActive.Active]; - lookup.project = { - fields: [ - [nameof(x => x.descriptionTemplate), nameof(x => x.id)].join('.'), - ] - }; - - return lookup; - } - - protected setupColumns() { - } + protected setupColumns() { } public dashboardTour: GuidedTour = { tourId: 'dmp-description-tour', @@ -320,6 +264,7 @@ export class DescriptionListingComponent extends BaseListingComponent 0) { - lookup.descriptionTemplateSubQuery = this.initializeDescriptionTemplateLookup(); + lookup.descriptionTemplateSubQuery = DescriptionFilterService.initializeDescriptionTemplateLookup(); lookup.descriptionTemplateSubQuery.ids = descriptionTemplates; } else lookup.descriptionTemplateSubQuery = null; @@ -446,12 +391,12 @@ export class DescriptionListingComponent extends BaseListingComponent 0; let roles = formGroup.get("role")?.value !== null ? [formGroup.get("role")?.value] : null; let addRoles = roles && roles?.length > 0; if (addDmps || addRoles) { - lookup.dmpSubQuery = this.initializeDmpLookup(); + lookup.dmpSubQuery = DescriptionFilterService.initializeDmpLookup(); if (addDmps) lookup.dmpSubQuery.ids = dmps?.length > 0 ? dmps : null; if (addRoles) { - lookup.dmpSubQuery.dmpUserSubQuery = this.initializeDmpUserLookup(); + lookup.dmpSubQuery.dmpUserSubQuery = DescriptionFilterService.initializeDmpUserLookup(); lookup.dmpSubQuery.dmpUserSubQuery.userRoles = roles; } } else lookup.dmpSubQuery = null; @@ -459,17 +404,17 @@ export class DescriptionListingComponent extends BaseListingComponent 0) { - lookup.descriptionTagSubQuery = this.initializeTagLookup(); + lookup.descriptionTagSubQuery = DescriptionFilterService.initializeTagLookup(); lookup.descriptionTagSubQuery.tagIds = tags; } else lookup.descriptionTagSubQuery = null; // 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[]; + ?.filter((reference: ReferencesWithType) => reference.referenceTypeId != null && reference.referenceIds?.length > 0) + ?.flatMap((referencesWithType: ReferencesWithType) => referencesWithType.referenceIds) as Guid[]; if (references && references?.length > 0) { - lookup.descriptionReferenceSubQuery = this.initializeReferenceLookup(); + lookup.descriptionReferenceSubQuery = DescriptionFilterService.initializeReferenceLookup(); lookup.descriptionReferenceSubQuery.referenceIds = references; } else lookup.descriptionReferenceSubQuery = null; @@ -477,30 +422,33 @@ export class DescriptionListingComponent extends BaseListingComponent reference.referenceType != null && reference.references?.length > 0) ?? null; + return formGroup?.get("references")?.value?.filter(( referencesWithType: ReferencesWithType ) => referencesWithType.referenceTypeId != null && referencesWithType.referenceIds?.length > 0) ?? null; } _buildFormFromLookup(lookup: DescriptionLookup, 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); - }); - return (new UntypedFormBuilder()).group({ status: [lookup.statuses?.length > 0 ? lookup.statuses[0] : null], role: lookup.dmpSubQuery?.dmpUserSubQuery?.userRoles ? lookup.dmpSubQuery?.dmpUserSubQuery?.userRoles[0] : [], descriptionTemplates: lookup.descriptionTemplateSubQuery?.ids ? [lookup.descriptionTemplateSubQuery?.ids] : [], associatedDmpIds: lookup.dmpSubQuery?.ids ? [lookup.dmpSubQuery?.ids] : [], tags: lookup.descriptionTagSubQuery?.tagIds ? [lookup.descriptionTagSubQuery?.tagIds] : [], - references: formArray }); } + + private _countFilters(lookup: DescriptionLookup): number { + let count = 0; + + if (lookup.statuses) count += lookup.statuses.length; + if (lookup.descriptionTemplateSubQuery) count += lookup.descriptionTemplateSubQuery.ids?.length; + if (lookup.descriptionTagSubQuery) count += lookup.descriptionTagSubQuery.tagIds?.length; + if (lookup.dmpSubQuery) { + if (lookup.dmpSubQuery.ids) count += lookup.dmpSubQuery.ids?.length; + if (lookup.dmpSubQuery.dmpUserSubQuery) count += lookup.dmpSubQuery.dmpUserSubQuery.userRoles?.length; + } + if (lookup.descriptionReferenceSubQuery) count += lookup.descriptionReferenceSubQuery.referenceIds?.length; + + return count; + } private get _lookupFields(): string[] { return [ diff --git a/dmp-frontend/src/app/ui/description/listing/description-listing.module.ts b/dmp-frontend/src/app/ui/description/listing/description-listing.module.ts index 125a4f868..de260cf3f 100644 --- a/dmp-frontend/src/app/ui/description/listing/description-listing.module.ts +++ b/dmp-frontend/src/app/ui/description/listing/description-listing.module.ts @@ -10,6 +10,7 @@ import { StartNewDescriptionDialogModule } from '../start-new-description-dialog import { DescriptionFilterDialogComponent } from './filtering/description-filter-dialogue/description-filter-dialog.component'; import { DescriptionFilterComponent } from './filtering/description-filter.component'; import { AutoCompleteModule } from '@app/library/auto-complete/auto-complete.module'; +import { DescriptionFilterService } from './filtering/description-filter.service'; @NgModule({ imports: [ @@ -28,7 +29,10 @@ import { AutoCompleteModule } from '@app/library/auto-complete/auto-complete.mod DescriptionFilterComponent, ], exports: [ - DescriptionListingItemComponent + DescriptionListingItemComponent, + ], + providers: [ + DescriptionFilterService, ] }) export class DescriptionListingModule { } diff --git a/dmp-frontend/src/app/ui/description/listing/filtering/description-filter-dialogue/description-filter-dialog.component.html b/dmp-frontend/src/app/ui/description/listing/filtering/description-filter-dialogue/description-filter-dialog.component.html index 39e50ef77..bfa8ae0e5 100644 --- a/dmp-frontend/src/app/ui/description/listing/filtering/description-filter-dialogue/description-filter-dialog.component.html +++ b/dmp-frontend/src/app/ui/description/listing/filtering/description-filter-dialogue/description-filter-dialog.component.html @@ -2,6 +2,7 @@ clear diff --git a/dmp-frontend/src/app/ui/description/listing/filtering/description-filter-dialogue/description-filter-dialog.component.ts b/dmp-frontend/src/app/ui/description/listing/filtering/description-filter-dialogue/description-filter-dialog.component.ts index 478400d31..a0685c30f 100644 --- a/dmp-frontend/src/app/ui/description/listing/filtering/description-filter-dialogue/description-filter-dialog.component.ts +++ b/dmp-frontend/src/app/ui/description/listing/filtering/description-filter-dialogue/description-filter-dialog.component.ts @@ -3,6 +3,7 @@ import { UntypedFormGroup } from '@angular/forms'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { AnalyticsService } from '@app/core/services/matomo/analytics-service'; import { DescriptionFilterComponent } from '../description-filter.component'; +import { ReferencesWithType } from '@app/core/query/description.lookup'; @Component({ selector: 'description-filter-dialog-component', @@ -20,9 +21,9 @@ export class DescriptionFilterDialogComponent implements OnInit { @Inject(MAT_DIALOG_DATA) public data: { isPublic: boolean, filterForm: UntypedFormGroup, + referencesWithTypeItems: ReferencesWithType[], } - ) { - } + ) { } ngOnInit() { this.analyticsService.trackPageView(AnalyticsService.DescriptionFilterDialog); diff --git a/dmp-frontend/src/app/ui/description/listing/filtering/description-filter.component.html b/dmp-frontend/src/app/ui/description/listing/filtering/description-filter.component.html index e77c9a903..384b41b4d 100644 --- a/dmp-frontend/src/app/ui/description/listing/filtering/description-filter.component.html +++ b/dmp-frontend/src/app/ui/description/listing/filtering/description-filter.component.html @@ -83,24 +83,23 @@
- + {{'DESCRIPTION-LISTING.FILTERS.REFERENCE-TYPES.REFERENCE-TYPE' | translate}} - +
-
+
{{'DESCRIPTION-LISTING.FILTERS.REFERENCE-TYPES.REFERENCE' | translate}} - +
- diff --git a/dmp-frontend/src/app/ui/description/listing/filtering/description-filter.component.ts b/dmp-frontend/src/app/ui/description/listing/filtering/description-filter.component.ts index 374b93047..6c2e44340 100644 --- a/dmp-frontend/src/app/ui/description/listing/filtering/description-filter.component.ts +++ b/dmp-frontend/src/app/ui/description/listing/filtering/description-filter.component.ts @@ -1,10 +1,12 @@ import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core'; -import { FormBuilder, UntypedFormArray, UntypedFormGroup } from '@angular/forms'; +import { AbstractControl, FormBuilder, UntypedFormArray, UntypedFormGroup } from '@angular/forms'; import { DescriptionStatus } from '@app/core/common/enum/description-status'; import { DmpUserRole } from '@app/core/common/enum/dmp-user-role'; import { ReferenceType } from '@app/core/model/reference-type/reference-type'; import { Reference } from '@app/core/model/reference/reference'; +import { ReferencesWithType } from '@app/core/query/description.lookup'; +import { ReferenceLookup } from '@app/core/query/reference.lookup'; import { AuthService } from '@app/core/services/auth/auth.service'; import { DescriptionTemplateService } from '@app/core/services/description-template/description-template.service'; import { DmpService } from '@app/core/services/dmp/dmp.service'; @@ -16,8 +18,11 @@ import { MultipleAutoCompleteConfiguration } from '@app/library/auto-complete/mu import { SingleAutoCompleteConfiguration } from '@app/library/auto-complete/single/single-auto-complete-configuration'; import { BaseCriteriaComponent } from '@app/ui/misc/criteria/base-criteria.component'; import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model'; +import { QueryResult } from '@common/model/query-result'; import { Guid } from '@common/types/guid'; +import { IsActive } from '@notification-service/core/enum/is-active.enum'; import { takeUntil } from 'rxjs/operators'; +import { nameof } from 'ts-simple-nameof'; @Component({ selector: 'app-description-filter-component', @@ -28,6 +33,7 @@ export class DescriptionFilterComponent extends BaseCriteriaComponent implements @Input() status; @Input() isPublic: boolean; + @Input() referencesWithTypeItems: ReferencesWithType[]; @Input() filterFormGroup: UntypedFormGroup; @Output() filterChanged: EventEmitter = new EventEmitter(); @@ -37,7 +43,6 @@ export class DescriptionFilterComponent extends BaseCriteriaComponent implements statuses = DescriptionStatus; dmpRole = DmpUserRole; options: UntypedFormGroup; - selectedReferenceTypes: Guid[]; descriptionTemplateAutoCompleteConfiguration: MultipleAutoCompleteConfiguration; dmpAutoCompleteConfiguration: MultipleAutoCompleteConfiguration; @@ -65,78 +70,58 @@ export class DescriptionFilterComponent extends BaseCriteriaComponent implements ngOnChanges(changes: SimpleChanges): void { if (changes['filterFormGroup']) { - this.descriptionTemplateAutoCompleteConfiguration = this.descriptionTemplateService.multipleAutocompleteConfiguration; + this.descriptionTemplateAutoCompleteConfiguration = this.descriptionTemplateService.buildMultipleAutocompleteConfiguration(); this.dmpAutoCompleteConfiguration = this.dmpService.multipleAutocompleteConfiguration; this.tagAutoCompleteConfiguration = this.tagService.multipleAutocompleteConfiguration; - this.selectedReferenceTypes = this._buildSelectedReferenceTypes(this.filterFormGroup); - this.referenceTypeAutocompleteConfiguration = this.getReferenceTypeAutocompleteConfiguration(this.selectedReferenceTypes); + this.referenceTypeAutocompleteConfiguration = this.getReferenceTypeAutocompleteConfiguration(); this.referenceAutocompleteConfiguration = new Map(); this.formGroup = this.filterFormGroup; - const formArray = this.formGroup.get('references') as UntypedFormArray; - formArray?.controls.forEach(control => { + + this.referencesWithTypeItems.forEach((referencesWithType: ReferencesWithType) => { - 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); + 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) => { + const references: Reference[] = result.items; - control.get('referenceType')?.valueChanges.pipe(takeUntil(this._destroyed)) - .subscribe(referenceType => { - this.selectedReferenceTypes = this._buildSelectedReferenceTypes(this.formGroup); - this.referenceTypeAutocompleteConfiguration = this.getReferenceTypeAutocompleteConfiguration(this.selectedReferenceTypes); + const groupedReferencesByTypeIds = new Map(); + 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() - }); - - control.get('references')?.valueChanges.pipe(takeUntil(this._destroyed)) - .subscribe(references => { - let referenceAutocomplete = this.getReferenceAutocompleteConfiguration(Guid.parse(referenceTypeId), references ?? []); - this.referenceAutocompleteConfiguration.set(referenceTypeId, referenceAutocomplete); + groupedReferencesByTypeIds.get(reference.type.id.toString()).push(reference.id.toString()); }); + + groupedReferencesByTypeIds.forEach((referenceIds: string[], referenceId: string) => { + this.addReferenceType(referenceId, referenceIds); + }); + }); + } }); } } - 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: [] + referenceTypeId: referenceTypeId, + referenceIds: referenceIds ? [referenceIds] : null, }); - 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); - }); + 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); } @@ -160,28 +145,57 @@ export class DescriptionFilterComponent extends BaseCriteriaComponent implements return this.authentication.currentAccountIsAuthenticated(); } - getReferenceTypeAutocompleteConfiguration(selectedReferenceTypes: Guid[]): SingleAutoCompleteConfiguration { - return this.referenceTypeService.getSingleAutocompleteConfiguration(selectedReferenceTypes); + getReferenceTypeAutocompleteConfiguration(): SingleAutoCompleteConfiguration { + return this.referenceTypeService.getSingleAutocompleteConfiguration(); }; selectReferenceAutocompleteConfiguration(referenceTypeId: string): MultipleAutoCompleteConfiguration { return this.referenceAutocompleteConfiguration.get(referenceTypeId); }; - getReferenceAutocompleteConfiguration(referenceTypeId: Guid, excludedIds: Reference[]): MultipleAutoCompleteConfiguration { + getReferenceAutocompleteConfiguration(referenceTypeId: Guid): MultipleAutoCompleteConfiguration { let autocomplete = this.referenceService.getMultipleAutoCompleteQueryConfiguration([referenceTypeId]); return autocomplete; }; - 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)); - }); + 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(x => x.id), + nameof(x => x.label), + [nameof(x => x.type), nameof(x => x.id)].join('.'), + [nameof(x => x.type), nameof(x => x.name)].join('.'), + ] + }; + lookup.order = { items: [nameof(x => x.label)] }; + return lookup; + } - return selectedReferenceTypes; + 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); + }); } } diff --git a/dmp-frontend/src/app/ui/description/listing/filtering/description-filter.service.ts b/dmp-frontend/src/app/ui/description/listing/filtering/description-filter.service.ts new file mode 100644 index 000000000..888157d1e --- /dev/null +++ b/dmp-frontend/src/app/ui/description/listing/filtering/description-filter.service.ts @@ -0,0 +1,82 @@ +import { Injectable } from "@angular/core"; +import { DescriptionTemplate } from "@app/core/model/description-template/description-template"; +import { Description, DescriptionReference, DescriptionTag } from "@app/core/model/description/description"; +import { Dmp, DmpUser } from "@app/core/model/dmp/dmp"; +import { Reference } from "@app/core/model/reference/reference"; +import { Tag } from "@app/core/model/tag/tag"; +import { DescriptionTemplateLookup } from "@app/core/query/description-template.lookup"; +import { DmpUserLookup } from "@app/core/query/dmp-user.lookup"; +import { DmpLookup } from "@app/core/query/dmp.lookup"; +import { DescriptionReferenceLookup } from "@app/core/query/reference.lookup"; +import { DescriptionTagLookup } from "@app/core/query/tag.lookup"; +import { IsActive } from "@notification-service/core/enum/is-active.enum"; +import { nameof } from "ts-simple-nameof"; + +@Injectable() +export class DescriptionFilterService { + + public static initializeReferenceLookup(): DescriptionReferenceLookup { + const lookup = new DescriptionReferenceLookup(); + lookup.metadata = { countAll: true }; + lookup.isActive = [IsActive.Active]; + lookup.project = { + fields: [ + [nameof(x => x.reference), nameof(x => x.id)].join('.'), + ] + }; + + return lookup; + } + + public static initializeTagLookup(): DescriptionTagLookup { + const lookup = new DescriptionTagLookup(); + lookup.metadata = { countAll: true }; + lookup.isActive = [IsActive.Active]; + lookup.project = { + fields: [ + [nameof(x => x.tag), nameof(x => x.id)].join('.'), + ] + }; + + return lookup; + } + + public static initializeDmpLookup(): DmpLookup { + const lookup = new DmpLookup(); + lookup.metadata = { countAll: true }; + lookup.isActive = [IsActive.Active]; + lookup.project = { + fields: [ + [nameof(x => x.dmp), nameof(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(x => x.dmpUsers), nameof(x => x.role)].join('.'), + ] + }; + + return lookup; + } + + public static initializeDescriptionTemplateLookup(): DescriptionTemplateLookup { + const lookup = new DescriptionTemplateLookup(); + lookup.metadata = { countAll: true }; + lookup.isActive = [IsActive.Active]; + lookup.project = { + fields: [ + [nameof(x => x.descriptionTemplate), nameof(x => x.id)].join('.'), + ] + }; + + return lookup; + } +} \ No newline at end of file diff --git a/dmp-frontend/src/app/ui/dmp/listing/dmp-listing.component.ts b/dmp-frontend/src/app/ui/dmp/listing/dmp-listing.component.ts index 037d9c75b..061a25fdb 100644 --- a/dmp-frontend/src/app/ui/dmp/listing/dmp-listing.component.ts +++ b/dmp-frontend/src/app/ui/dmp/listing/dmp-listing.component.ts @@ -82,11 +82,9 @@ export class DmpListingComponent extends BaseListingComponent 0; } - get hasFilters(): boolean { return (this.lookup.like != null && this.lookup.like != '') || this.lookup.statuses != null || this.lookup.dmpReferenceSubQuery != null || this.lookup.dmpDescriptionTemplateSubQuery != null || diff --git a/dmp-frontend/src/app/ui/dmp/listing/filtering/dmp-filter-dialog/dmp-filter-dialog.component.ts b/dmp-frontend/src/app/ui/dmp/listing/filtering/dmp-filter-dialog/dmp-filter-dialog.component.ts index 9d40b243f..161138566 100644 --- a/dmp-frontend/src/app/ui/dmp/listing/filtering/dmp-filter-dialog/dmp-filter-dialog.component.ts +++ b/dmp-frontend/src/app/ui/dmp/listing/filtering/dmp-filter-dialog/dmp-filter-dialog.component.ts @@ -21,7 +21,7 @@ export class DmpFilterDialogComponent implements OnInit { @Inject(MAT_DIALOG_DATA) public data: { isPublic: boolean, filterForm: UntypedFormGroup, - referencesWithTypeItems: ReferencesWithType[]; + referencesWithTypeItems: ReferencesWithType[], }) { } ngOnInit() { diff --git a/dmp-frontend/src/app/ui/dmp/listing/filtering/dmp-filter.component.ts b/dmp-frontend/src/app/ui/dmp/listing/filtering/dmp-filter.component.ts index 29214b12d..3b97dd40d 100644 --- a/dmp-frontend/src/app/ui/dmp/listing/filtering/dmp-filter.component.ts +++ b/dmp-frontend/src/app/ui/dmp/listing/filtering/dmp-filter.component.ts @@ -29,7 +29,6 @@ import { ReferencesWithType } from '@app/core/query/description.lookup'; }) export class DmpFilterComponent extends BaseCriteriaComponent implements OnInit, OnChanges { - @Input() showGrant: boolean; @Input() isPublic: boolean; @Input() referencesWithTypeItems: ReferencesWithType[]; @Input() filterFormGroup: UntypedFormGroup; @@ -143,12 +142,11 @@ export class DmpFilterComponent extends BaseCriteriaComponent implements OnInit, } selectReferenceAutocompleteConfiguration(referenceTypeId: string): MultipleAutoCompleteConfiguration { - let foo = this.referenceAutocompleteConfiguration.get(referenceTypeId); return this.referenceAutocompleteConfiguration.get(referenceTypeId); }; private getReferenceTypeAutocompleteConfiguration() { - return this.referenceTypeService.getSingleAutocompleteConfigurationForDmp(); + return this.referenceTypeService.getSingleAutocompleteConfiguration(); } private getReferenceAutocompleteConfiguration(referenceTypeId: Guid): MultipleAutoCompleteConfiguration {