OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[33163] Add work package filter for child work packages(implementing the component in another way) (#8826)
Behrokh Satarnejadf0669247a5d8
diff --git a/frontend/src/app/components/filters/filter-searchable-multiselect-value/filter-searchable-multiselect-value.component.html b/frontend/src/app/components/filters/filter-searchable-multiselect-value/filter-searchable-multiselect-value.component.htmlnew file mode 100644index 00000000000..214509e5e79--- /dev/null+++ b/frontend/src/app/components/filters/filter-searchable-multiselect-value/filter-searchable-multiselect-value.component.html@@ -0,0 +1,25 @@+<div class="inline-label ng-select-container"+ id="div-values-{{filter.id}}">++ <ng-select #ngSelectInstance+ [ngModel]="filter.values"+ (change)="setValues($event)"+ (add)="repositionDropdown()"+ (remove)="repositionDropdown()"+ (open)="repositionDropdown()"+ [compareWith]="compareByHrefOrString"+ [clearSearchOnAdd]="true"+ [placeholder]="text.placeholder"+ [ngClass]="{'-required-highlighting' : isEmpty}"+ class="advanced-filters--ng-select -multi-select"+ [id]="'values-' + filter.id"+ [items]="availableOptions"+ [multiple]="true"+ [closeOnSelect]="false"+ [hideSelected]="true"+ appendTo="body"+ bindLabel="name"+ [typeahead]="requests.input$"+ [virtualScroll]="true">+ </ng-select>+</div>diff --git a/frontend/src/app/components/filters/filter-searchable-multiselect-value/filter-searchable-multiselect-value.component.ts b/frontend/src/app/components/filters/filter-searchable-multiselect-value/filter-searchable-multiselect-value.component.tsnew file mode 100644index 00000000000..920ff934407--- /dev/null+++ b/frontend/src/app/components/filters/filter-searchable-multiselect-value/filter-searchable-multiselect-value.component.ts@@ -0,0 +1,143 @@++import {HalResource} from 'core-app/modules/hal/resources/hal-resource';+import {QueryFilterInstanceResource} from 'core-app/modules/hal/resources/query-filter-instance-resource';+import {AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core';+import {I18nService} from 'core-app/modules/common/i18n/i18n.service';+import {AngularTrackingHelpers} from 'core-components/angular/tracking-functions';+import {HalResourceService} from 'core-app/modules/hal/services/hal-resource.service';+import {HalResourceSortingService} from 'core-app/modules/hal/services/hal-resource-sorting.service';+import {NgSelectComponent} from '@ng-select/ng-select';+import {APIV3Service} from 'core-app/modules/apiv3/api-v3.service';+import { DebouncedRequestSwitchmap, errorNotificationHandler } from 'core-app/helpers/rxjs/debounced-input-switchmap';+import { ValueOption } from 'core-app/modules/fields/edit/field-types/select-edit-field.component';+import { Observable } from 'rxjs';+import { HalResourceNotificationService } from 'core-app/modules/hal/services/hal-resource-notification.service';+import { CurrentProjectService } from 'core-app/components/projects/current-project.service';+import { ApiV3FilterBuilder, FilterOperator } from 'core-app/components/api/api-v3/api-v3-filter-builder';+import { map } from 'rxjs/operators';+import { APIv3ResourceCollection } from 'core-app/modules/apiv3/paths/apiv3-resource';+import { UserResource } from 'core-app/modules/hal/resources/user-resource';+import { APIv3UserPaths } from 'core-app/modules/apiv3/endpoints/users/apiv3-user-paths';+import { APIV3WorkPackagePaths } from 'core-app/modules/apiv3/endpoints/work_packages/api-v3-work-package-paths';+import { WorkPackageResource } from 'core-app/modules/hal/resources/work-package-resource';+import { UntilDestroyedMixin } from 'core-app/helpers/angular/until-destroyed.mixin';+export interface FilterConditions {name:string; operator:FilterOperator; values:unknown[]|boolean; }++@Component({+ selector: 'filter-searchable-multiselect-value',+ changeDetection: ChangeDetectionStrategy.OnPush,+ templateUrl:'./filter-searchable-multiselect-value.component.html'+})+++export class FilterSearchableMultiselectValueComponent extends UntilDestroyedMixin implements OnInit, AfterViewInit {+ @Input() public filter:QueryFilterInstanceResource;+ @Input() public filterConditions?:FilterConditions[];+ @Input() public filterResource:'work_packages' | 'users';+ @Input() public filterSearchKey?:string;+ @Input() public shouldFocus:boolean = false;+ @Output() public filterChanged = new EventEmitter<QueryFilterInstanceResource>();++ private _isEmpty:boolean;+ public _availableOptions:HalResource[] = [];+ public compareByHrefOrString = AngularTrackingHelpers.compareByHrefOrString;+ public active:Set<string>;+ public requests = new DebouncedRequestSwitchmap<string, ValueOption>(+ (searchTerm:string) => this.loadAvailable(searchTerm),+ errorNotificationHandler(this.halNotification),+ true+ );+ readonly text = {+ placeholder: this.I18n.t('js.placeholders.selection'),+ };++ public get value() {+ return this.filter.values;+ }+ public get availableOptions() {+ return this._availableOptions;+ }++ public set availableOptions(val:HalResource[]) {+ this._availableOptions = this.halSorting.sort(val);+ }++ public get isEmpty():boolean {+ return this._isEmpty = this.value.length === 0;+ }++ @ViewChild('ngSelectInstance', { static: true }) ngSelectInstance:NgSelectComponent;++ constructor(readonly halResourceService:HalResourceService,+ readonly halSorting:HalResourceSortingService,+ readonly apiV3Service:APIV3Service,+ readonly cdRef:ChangeDetectorRef,+ readonly I18n:I18nService,+ protected currentProject:CurrentProjectService,+ readonly halNotification:HalResourceNotificationService) {+ super();+ }++ ngOnInit() {+ this.initialization();+ // Request an empty value to load warning early on+ this.requests.input$.next('');+ }++ ngAfterViewInit():void {+ if (this.ngSelectInstance && this.shouldFocus) {+ this.ngSelectInstance.focus();+ }+ }++ initialization() {+ this+ .requests+ .output$.pipe(+ this.untilDestroyed()+ )+ .subscribe((values:HalResource[]) => {+ this.availableOptions = values;+ this.cdRef.detectChanges();+ });+ }++ public loadAvailable(matching:string):Observable<HalResource[]> {+ const filters:ApiV3FilterBuilder = this.createFilters(this.filterConditions ?? [], matching);++ const filteredData = (this.apiV3Service[this.filterResource] as+ APIv3ResourceCollection<UserResource|WorkPackageResource, APIv3UserPaths|APIV3WorkPackagePaths>)+ .filtered(filters).get()+ .pipe(map(collection => collection.elements));++ return filteredData;+ }++ protected createFilters(filterConditions:FilterConditions[], matching:string) {+ const filters = new ApiV3FilterBuilder();++ for (const condition of filterConditions) {+ filters.add(condition.name, condition.operator, condition.values);+ }+ if (matching) {+ filters.add(this.filterSearchKey ?? '', '**', [matching]);+ }+ return filters;+ }++ public setValues(val:any) {+ this.filter.values = val.length > 0 ? (Array.isArray(val) ? val : [val]) : [] as HalResource[];+ this.filterChanged.emit(this.filter);+ this.requests.input$.next('');+ this.cdRef.detectChanges();+ }++ public repositionDropdown() {+ if (this.ngSelectInstance) {+ const component = (this.ngSelectInstance) as any;+ if (component && component.dropdownPanel) {+ component.dropdownPanel._updatePosition();+ }+ }+ }+}diff --git a/frontend/src/app/components/filters/query-filter/query-filter.component.html b/frontend/src/app/components/filters/query-filter/query-filter.component.htmlindex 962a39c08fd..ba0e92163cf 100644--- a/frontend/src/app/components/filters/query-filter/query-filter.component.html+++ b/frontend/src/app/components/filters/query-filter/query-filter.component.html@@ -34,9 +34,7 @@(filterChanged)="onFilterUpdated($event)"[shouldFocus]="shouldFocus"[filter]="filter"></filter-boolean-value>-</div>-<!-- Values --><ng-container *ngIf="showValuesInput && valueType"><div class="advanced-filters--filter-value" [ngSwitch]="valueType">@@ -75,6 +73,13 @@[shouldFocus]="shouldFocus"[filter]="filter"></filter-string-value>+ <filter-searchable-multiselect-value *ngSwitchCase="'[]WorkPackage'"+ (filterChanged)="onFilterUpdated($event)"+ [shouldFocus]="shouldFocus"+ [filterConditions]="parentFilter.filters"+ [filterResource]="parentFilter.resource"+ [filterSearchKey]="parentFilter.searchKey"+ [filter]="filter"></filter-searchable-multiselect-value><filter-toggled-multiselect-value *ngSwitchDefault(filterChanged)="onFilterUpdated($event)"diff --git a/frontend/src/app/components/filters/query-filter/query-filter.component.ts b/frontend/src/app/components/filters/query-filter/query-filter.component.tsindex a32f101c57a..f3cafe6290b 100644--- a/frontend/src/app/components/filters/query-filter/query-filter.component.ts+++ b/frontend/src/app/components/filters/query-filter/query-filter.component.ts@@ -34,6 +34,7 @@ import {QueryFilterInstanceResource} from "core-app/modules/hal/resources/query-import {BannersService} from "core-app/modules/common/enterprise/banners.service";import {WorkPackageViewFiltersService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-filters.service";import {SchemaCacheService} from "core-components/schemas/schema-cache.service";+import { CurrentProjectService } from 'core-app/components/projects/current-project.service';@Component({selector: '[query-filter]',@@ -63,6 +64,7 @@ export class QueryFilterComponent implements OnInit {constructor(readonly wpTableFilters:WorkPackageViewFiltersService,readonly schemaCache:SchemaCacheService,readonly I18n:I18nService,+ readonly currentProject:CurrentProjectService,readonly bannerService:BannersService) {}@@ -72,6 +74,13 @@ export class QueryFilterComponent implements OnInit {this.filterChanged.emit(this.filter);}+ public parentFilter = {+ filters:[{name:'is_milestone', operator:'=', values:false},+ {name:'project', operator:'=', values:[this.currentProject.id]}],+ resource:'work_packages',+ searchKey:'subjectOrId'+ };+public removeThisFilter() {this.deactivateFilter.emit(this.filter);}diff --git a/frontend/src/app/components/filters/query-filters/query-filters.component.html b/frontend/src/app/components/filters/query-filters/query-filters.component.htmlindex 8950478b77d..65f953cc6e9 100644--- a/frontend/src/app/components/filters/query-filters/query-filters.component.html+++ b/frontend/src/app/components/filters/query-filters/query-filters.component.html@@ -26,14 +26,13 @@<li class="advanced-filters--spacer"></li><ng-container *ngFor="let filter of filters; trackBy: trackByName ; let index = index">- <li *ngIf="isFilterAvailable(filter.id)"+ <li *ngIf="isFilterAvailable(filter)"id="filter_{{filter.id}}"query-filter[shouldFocus]="index == focusElementIndex"[filter]="filter"(deactivateFilter)="deactivateFilter($event)"(filterChanged)="filtersChanged.emit(filters)"- [hidden]="isHiddenFilter(filter)"class="advanced-filters--filter"></li></ng-container>diff --git a/frontend/src/app/components/filters/query-filters/query-filters.component.ts b/frontend/src/app/components/filters/query-filters/query-filters.component.tsindex fab2f3ab95c..02c607a1ce6 100644--- a/frontend/src/app/components/filters/query-filters/query-filters.component.ts+++ b/frontend/src/app/components/filters/query-filters/query-filters.component.ts@@ -106,10 +106,6 @@ export class QueryFiltersComponent extends UntilDestroyedMixin implements OnInitthis.wpFiltersService.toggleVisibility();}- public isHiddenFilter(filter:QueryFilterResource) {- return _.includes(this.wpTableFilters.hidden, filter.id);- }-public deactivateFilter(removedFilter:QueryFilterInstanceResource) {let index = this.filters.indexOf(removedFilter);_.remove(this.filters, f => f.id === removedFilter.id);@@ -122,7 +118,7 @@ export class QueryFiltersComponent extends UntilDestroyedMixin implements OnInitpublic get isSecondSpacerVisible():boolean {const hasSearch = !!_.find(this.filters, (f) => f.id === 'search');- const hasAvailableFilter = !!_.find(this.filters, (f) => f.id !== 'search' && this.isFilterAvailable(f.id));+ const hasAvailableFilter = !!this.filters.find((f) => f.id !== 'search' && this.isFilterAvailable(f));return hasSearch && hasAvailableFilter;}@@ -151,8 +147,9 @@ export class QueryFiltersComponent extends UntilDestroyedMixin implements OnInitreturn this.filters[index];}- public isFilterAvailable(id:string):boolean {- return (this.wpTableFilters.availableFilters.some(filter => filter.id === id));+ public isFilterAvailable(filter:QueryFilterResource):boolean {+ return (this.wpTableFilters.availableFilters.some(availableFilter => availableFilter.id === filter.id) &&+ !(this.wpTableFilters.hidden.includes(filter.id) || filter.isTemplated()));}public onOpen() {diff --git a/frontend/src/app/modules/hal/resources/query-filter-instance-resource.ts b/frontend/src/app/modules/hal/resources/query-filter-instance-resource.tsindex 11889fbcdc3..0116f11217e 100644--- a/frontend/src/app/modules/hal/resources/query-filter-instance-resource.ts+++ b/frontend/src/app/modules/hal/resources/query-filter-instance-resource.ts@@ -91,4 +91,13 @@ export class QueryFilterInstanceResource extends HalResource {public findOperator(operatorSymbol:string):QueryOperatorResource|undefined {return _.find(this.schemaCache.of(this).availableOperators, (operator:QueryOperatorResource) => operator.id === operatorSymbol) as QueryOperatorResource|undefined;}++ public isTemplated() {+ let flag = false;+ (this.values as any[]).find((value:any) => {+ const href:string = value?.href || value || '';+ flag = href.includes('{id}');+ });+ return flag;+ }}diff --git a/frontend/src/app/modules/work_packages/openproject-work-packages.module.ts b/frontend/src/app/modules/work_packages/openproject-work-packages.module.tsindex 9488ebd7b29..360eabc0957 100644--- a/frontend/src/app/modules/work_packages/openproject-work-packages.module.ts+++ b/frontend/src/app/modules/work_packages/openproject-work-packages.module.ts@@ -94,6 +94,7 @@ import {FilterDateTimesValueComponent} from 'core-components/filters/filter-dateimport {FilterIntegerValueComponent} from 'core-components/filters/filter-integer-value/filter-integer-value.component';import {FilterStringValueComponent} from 'core-components/filters/filter-string-value/filter-string-value.component';import {FilterToggledMultiselectValueComponent} from 'core-components/filters/filter-toggled-multiselect-value/filter-toggled-multiselect-value.component';+import {FilterSearchableMultiselectValueComponent} from 'core-components/filters/filter-searchable-multiselect-value/filter-searchable-multiselect-value.component';import {WorkPackageDetailsViewButtonComponent} from 'core-components/wp-buttons/wp-details-view-button/wp-details-view-button.component';import {WorkPackageFoldToggleButtonComponent} from 'core-components/wp-buttons/wp-fold-toggle-button/wp-fold-toggle-button.component';import {WpTableConfigurationModalComponent} from 'core-components/wp-table/configuration-modal/wp-table-configuration.modal';@@ -271,6 +272,7 @@ import {WorkPackageGroupToggleDropdownMenuDirective} from "core-components/op-coFilterIntegerValueComponent,FilterStringValueComponent,FilterToggledMultiselectValueComponent,+ FilterSearchableMultiselectValueComponent,WorkPackageFilterContainerComponent,WorkPackageFilterButtonComponent,diff --git a/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-filters.service.ts b/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-filters.service.tsindex 39c6414f684..29cf64772f9 100644--- a/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-filters.service.ts+++ b/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-filters.service.ts@@ -44,7 +44,6 @@ import {mapTo, take} from "rxjs/operators";export class WorkPackageViewFiltersService extends WorkPackageQueryStateService<QueryFilterInstanceResource[]> {public hidden:string[] = ['id',- 'parent','datesInterval','precedes','follows',diff --git a/spec/features/work_packages/table/queries/filter_spec.rb b/spec/features/work_packages/table/queries/filter_spec.rbindex f5e2a5a747f..d11e2820c8a 100644--- a/spec/features/work_packages/table/queries/filter_spec.rb+++ b/spec/features/work_packages/table/queries/filter_spec.rb@@ -510,4 +510,28 @@ describe 'filter work packages', js: true dofilters.expect_filter_order('Version', [version2.name, version1.name])endend++ describe 'add parent WP filter' do+ let(:wp_parent) { FactoryBot.create :work_package, project: project, subject: 'project' }+ let(:wp_child1) { FactoryBot.create :work_package, project: project, subject: 'child 1', parent: wp_parent }+ let(:wp_child2) { FactoryBot.create :work_package, project: project, subject: 'child 2', parent: wp_parent }+ let(:wp_default) { FactoryBot.create :work_package, project: project, subject: 'default' }++ it do+ wp_parent+ wp_child1+ wp_child2+ wp_default+ wp_table.visit!+ loading_indicator_saveguard+ filters.expect_loaded+ filters.open+ filters.add_filter_by 'Parent', 'is', [wp_parent.subject]+ loading_indicator_saveguard++ # It should show the children of the selected parent+ wp_table.expect_work_package_listed wp_child1, wp_child2+ wp_table.ensure_work_package_not_listed! wp_default+ end+endend