Skip to content

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

Fix project autocompleter for filters

Benjamin Bädorf8caf2ea85a27
diff --git a/frontend/src/app/features/work-packages/components/filters/filter-project/filter-project.component.html b/frontend/src/app/features/work-packages/components/filters/filter-project/filter-project.component.html
new file mode 100644
index 00000000000..b9d531b6a40
--- /dev/null
+++ b/frontend/src/app/features/work-packages/components/filters/filter-project/filter-project.component.html
@@ -0,0 +1,13 @@
+<div
+ class="inline-label ng-select-container"
+ id="div-values-{{filter.id}}"
+>
+ <op-project-autocompleter
+ [value]="filter.values"
+ [focusDirectly]="shouldFocus"
+ [multiple]="true"
+ [id]="'values-' + filter.id"
+ class="advanced-filters--ng-select -multi-select"
+ (change)="onChange($event)"
+ ></op-project-autocompleter>
+</div>
diff --git a/frontend/src/app/features/work-packages/components/filters/filter-project/filter-project.component.ts b/frontend/src/app/features/work-packages/components/filters/filter-project/filter-project.component.ts
new file mode 100644
index 00000000000..7430b06787a
--- /dev/null
+++ b/frontend/src/app/features/work-packages/components/filters/filter-project/filter-project.component.ts
@@ -0,0 +1,79 @@
+// -- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) 2012-2022 the OpenProject GmbH
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License version 3.
+//
+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+// Copyright (C) 2006-2013 Jean-Philippe Lang
+// Copyright (C) 2010-2013 the ChiliProject Team
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See COPYRIGHT and LICENSE files for more details.
+//++
+
+import { Component, Input, Output } from '@angular/core';
+import { I18nService } from 'core-app/core/i18n/i18n.service';
+import { HalResource } from 'core-app/features/hal/resources/hal-resource';
+import { DebouncedEventEmitter } from 'core-app/shared/helpers/rxjs/debounced-event-emitter';
+import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
+import { componentDestroyed } from '@w11k/ngx-componentdestroyed';
+import { QueryFilterInstanceResource } from 'core-app/features/hal/resources/query-filter-instance-resource';
+import { IProjectAutocompleteItem } from 'core-app/shared/components/autocompleter/project-autocompleter/project-autocomplete-item';
+import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
+
+@Component({
+ selector: 'op-filter-project',
+ templateUrl: './filter-project.component.html',
+})
+export class FilterProjectComponent extends UntilDestroyedMixin {
+ @Input() public shouldFocus = false;
+
+ @Input() public filter:QueryFilterInstanceResource;
+
+ @Output() public filterChanged = new DebouncedEventEmitter<QueryFilterInstanceResource>(componentDestroyed(this));
+
+ constructor(
+ readonly I18n:I18nService,
+ readonly apiV3Service:ApiV3Service,
+ ) {
+ super();
+ }
+
+ async onChange(val:HalResource[]|IProjectAutocompleteItem[]) {
+ if (val === this.filter.values || val === undefined) {
+ return;
+ }
+
+ if (!val) {
+ this.filter.values.length = 0;
+ this.filterChanged.emit(this.filter);
+ return;
+ }
+
+ // The project autocompleter does not return HalResources, but most filters want them.
+ // Here we change from one to the other
+ const projects = await this.apiV3Service.projects.list({
+ filters: [
+ [ 'id', '=', val.map((p:any) => p.id)],
+ ],
+ }).toPromise();
+
+ this.filter.values = projects.elements;
+ this.filterChanged.emit(this.filter);
+ }
+}
diff --git a/frontend/src/app/features/work-packages/components/filters/query-filter/query-filter.component.html b/frontend/src/app/features/work-packages/components/filters/query-filter/query-filter.component.html
index f9bdc9a52f2..31588e5a392 100644
--- a/frontend/src/app/features/work-packages/components/filters/query-filter/query-filter.component.html
+++ b/frontend/src/app/features/work-packages/components/filters/query-filter/query-filter.component.html
@@ -97,9 +97,12 @@
[filter]="filter"
></op-filter-string-value>
- <op-project-autocompleter
+ <op-filter-project
*ngSwitchCase="'[]Project'"
- ></op-project-autocompleter>
+ (filterChanged)="onFilterUpdated($event)"
+ [shouldFocus]="shouldFocus"
+ [filter]="filter"
+ ></op-filter-project>
<ng-container *ngSwitchDefault>
<op-filter-toggled-multiselect-value
diff --git a/frontend/src/app/features/work-packages/openproject-work-packages.module.ts b/frontend/src/app/features/work-packages/openproject-work-packages.module.ts
index 96273503a9d..dc2bd8339ec 100644
--- a/frontend/src/app/features/work-packages/openproject-work-packages.module.ts
+++ b/frontend/src/app/features/work-packages/openproject-work-packages.module.ts
@@ -162,6 +162,7 @@ import { FilterSearchableMultiselectValueComponent } from 'core-app/features/wor
import { QueryFilterComponent } from 'core-app/features/work-packages/components/filters/query-filter/query-filter.component';
import { FilterDatesValueComponent } from 'core-app/features/work-packages/components/filters/filter-dates-value/filter-dates-value.component';
import { FilterStringValueComponent } from 'core-app/features/work-packages/components/filters/filter-string-value/filter-string-value.component';
+import { FilterProjectComponent } from 'core-app/features/work-packages/components/filters/filter-project/filter-project.component';
import { FilterDateValueComponent } from 'core-app/features/work-packages/components/filters/filter-date-value/filter-date-value.component';
import { FilterDateTimeValueComponent } from 'core-app/features/work-packages/components/filters/filter-date-time-value/filter-date-time-value.component';
import { FilterToggledMultiselectValueComponent } from 'core-app/features/work-packages/components/filters/filter-toggled-multiselect-value/filter-toggled-multiselect-value.component';
@@ -286,6 +287,7 @@ import isNewResource from 'core-app/features/hal/helpers/is-new-resource';
FilterDateTimesValueComponent,
FilterIntegerValueComponent,
FilterStringValueComponent,
+ FilterProjectComponent,
FilterToggledMultiselectValueComponent,
FilterSearchableMultiselectValueComponent,
diff --git a/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.html b/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.html
index d47fdf944bc..fd6c8885abf 100644
--- a/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.html
+++ b/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.html
@@ -1,7 +1,12 @@
<op-autocompleter
- [getOptionsFn]="getAvailableProjects.bind(this)"
[model]="value"
+
+ [getOptionsFn]="getAvailableProjects.bind(this)"
[trackByFn]="projectTracker"
+
+ [multiple]="multiple"
+ [focusDirectly]="focusDirectly"
+
appendTo="body"
(change)="writeValue($event)"
diff --git a/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.ts b/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.ts
index 0567bb94158..b658551bf07 100644
--- a/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.ts
+++ b/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.ts
@@ -90,7 +90,7 @@ export class ProjectAutocompleterComponent implements OnInit, ControlValueAccess
@Input() public name = '';
- @Input() public allowEmpty = false;
+ @Input() public focusDirectly = false;
@Input() public multiple = false;