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

Search for work packages and show the results as cards (for now)

Henriette Darge024a45ac25a0
diff --git a/frontend/src/app/features/team-planner/team-planner/add-work-packages/quick-add-pane.component.html b/frontend/src/app/features/team-planner/team-planner/add-work-packages/quick-add-pane.component.html
index 284716ecb10..842120e3b10 100644
--- a/frontend/src/app/features/team-planner/team-planner/add-work-packages/quick-add-pane.component.html
+++ b/frontend/src/app/features/team-planner/team-planner/add-work-packages/quick-add-pane.component.html
@@ -1,19 +1,36 @@
-<op-autocompleter
- #select
- classes="quick-add-pane--search"
- [resource]="'work_packages'"
- [openDirectly]="true"
- [fetchDataDirectly]="true"
-></op-autocompleter>
+<input
+ class="op-quick-add-pane--search"
+ [placeholder]="text.placeholder"
+ (input)="searchWorkPackages($event.target.value)"
+/>
-<div
- *ngIf="isEmpty"
- class="op-quick-add-pane--empty-state"
+<ng-container
+ *ngIf="(isLoading | async) === false; else loadingTemplate"
+>
+ <ng-container
+ *ngIf="(isEmpty | async) === false; else emptyTemplate"
>
- <img [src]="image.empty_state" class="op-quick-add-pane--empty-state-image"/>
+ <div class="op-quick-add-pane--results">
+ <ng-container *ngFor="let wp of resultingWorkPackages">
+ <wp-single-card
+ [workPackage]="wp"
+ ></wp-single-card>
+ </ng-container></div>
+ </ng-container>
- <span
- [innerHTML]="text.empty_state"
- class="op-quick-add-pane--empty-state-text"
- ></span>
-</div>
+ <ng-template #emptyTemplate>
+ <div
+ class="op-quick-add-pane--empty-state"
+ >
+ <img [src]="image.empty_state" class="op-quick-add-pane--empty-state-image"/>
+
+ <span
+ [innerHTML]="text.empty_state"
+ class="op-quick-add-pane--empty-state-text"
+ ></span>
+ </div>
+ </ng-template>
+</ng-container>
+
+<ng-template #loadingTemplate>
+</ng-template>
diff --git a/frontend/src/app/features/team-planner/team-planner/add-work-packages/quick-add-pane.component.sass b/frontend/src/app/features/team-planner/team-planner/add-work-packages/quick-add-pane.component.sass
index ecd9346944e..a7c55aab335 100644
--- a/frontend/src/app/features/team-planner/team-planner/add-work-packages/quick-add-pane.component.sass
+++ b/frontend/src/app/features/team-planner/team-planner/add-work-packages/quick-add-pane.component.sass
@@ -1,10 +1,26 @@
+@import "src/assets/sass/helpers"
+
\:host
+ display: grid
+ grid-template-rows: 32px 1fr
+ grid-row-gap: 10px
background: #F3F3F3
padding: 8px
.op-quick-add-pane
+ &--search
+ width: 100%
+ line-height: 32px
+ height: 32px
+ padding: 0 12px 0 42px
+
+ &--results
+ overflow: auto
+ @include styled-scroll-bar
+
&--empty-state
display: grid
+ grid-template-rows: auto 1fr
grid-row-gap: 12px
&--empty-state-image
diff --git a/frontend/src/app/features/team-planner/team-planner/add-work-packages/quick-add-pane.component.ts b/frontend/src/app/features/team-planner/team-planner/add-work-packages/quick-add-pane.component.ts
index afbd16a80b3..c94745e2d0d 100644
--- a/frontend/src/app/features/team-planner/team-planner/add-work-packages/quick-add-pane.component.ts
+++ b/frontend/src/app/features/team-planner/team-planner/add-work-packages/quick-add-pane.component.ts
@@ -1,6 +1,26 @@
-import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
+import {
+ ChangeDetectionStrategy,
+ Component,
+ OnInit,
+} from '@angular/core';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { imagePath } from 'core-app/shared/helpers/images/path-helper';
+import {
+ BehaviorSubject,
+ of,
+} from 'rxjs';
+import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
+import { ApiV3FilterBuilder } from 'core-app/shared/helpers/api-v3/api-v3-filter-builder';
+import {
+ catchError,
+ debounceTime,
+ map,
+} from 'rxjs/operators';
+import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
+import { WorkPackageNotificationService } from 'core-app/features/work-packages/services/notifications/work-package-notification.service';
+import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';
+import { UrlParamsHelperService } from 'core-app/features/work-packages/components/wp-query/url-params-helper';
+import { IsolatedQuerySpace } from 'core-app/features/work-packages/directives/query-space/isolated-query-space';
@Component({
selector: 'op-quick-add-pane',
@@ -9,18 +29,87 @@ import { imagePath } from 'core-app/shared/helpers/images/path-helper';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class QuickAddPaneComponent implements OnInit {
- isEmpty = true;
+ isEmpty = new BehaviorSubject<boolean>(true);
+
+ isLoading = new BehaviorSubject<boolean>(false);
text = {
empty_state: this.I18n.t('js.team_planner.quick_add.empty_state'),
+ placeholder: this.I18n.t('js.team_planner.quick_add.search_placeholder'),
};
image = {
empty_state: imagePath('team-planner/quick-add-empty-state.svg'),
};
+ resultingWorkPackages:WorkPackageResource[] = [];
+
+ searchWorkPackages = (searchString:string):void => {
+ this.isLoading.next(true);
+
+ // Return when the search string is empty
+ if (searchString.length === 0) {
+ this.isLoading.next(false);
+ return;
+ }
+
+ const filters:ApiV3FilterBuilder = new ApiV3FilterBuilder();
+ const queryResults = this.querySpace.results.value;
+
+ filters.add('subjectOrId', '**', [searchString]);
+
+ if (queryResults && queryResults.elements.length > 0) {
+ filters.add('id', '!', queryResults.elements.map((wp:WorkPackageResource) => wp.id!));
+ }
+
+ // Add the existing filter, if any
+ const query = this.querySpace.query.value;
+ if (query?.filters) {
+ const currentFilters = this.urlParamsHelper.buildV3GetFilters(query.filters);
+
+ currentFilters.forEach((filter) => {
+ Object.keys(filter).forEach((name) => {
+ if (name !== 'assignee' && name !== 'datesInterval') {
+ filters.add(name, filter[name].operator, filter[name].values);
+ }
+ });
+ });
+ }
+
+ this
+ .apiV3Service
+ .withOptionalProject(this.currentProject.id)
+ .work_packages
+ .filtered(filters)
+ .get()
+ .pipe(
+ debounceTime(250),
+ map((collection) => collection.elements),
+ catchError((error:unknown) => {
+ this.notificationService.handleRawError(error);
+ return of([]);
+ }),
+ )
+ .subscribe((results) => {
+ this.resultingWorkPackages = results;
+
+ this.isEmpty.next(results.length === 0);
+ this.isLoading.next(false);
+ });
+ };
+
+ public autocompleterOptions = {
+ resource: 'work_packages',
+ getOptionsFn: this.searchWorkPackages,
+ };
+
constructor(
+ private readonly querySpace:IsolatedQuerySpace,
private I18n:I18nService,
+ private readonly apiV3Service:ApiV3Service,
+ private readonly notificationService:WorkPackageNotificationService,
+ private readonly currentProject:CurrentProjectService,
+ private readonly urlParamsHelper:UrlParamsHelperService,
) { }
ngOnInit():void {
diff --git a/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.sass b/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.sass
index 20f2be5b0ad..0b01cbd5034 100644
--- a/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.sass
+++ b/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.sass
@@ -13,10 +13,11 @@
grid-template-rows: 1fr auto
grid-column-gap: 10px
grid-template-areas: "quickAdd calendar" "quickAdd noData" "quickAdd addAssignee"
+ max-height: 100%
&--quick-add-pane
grid-area: quickAdd
- max-width: 350px
+ width: 350px
&--calendar
grid-area: calendar
diff --git a/modules/team_planner/config/locales/js-en.yml b/modules/team_planner/config/locales/js-en.yml
index 633b964be04..6d6633e561a 100644
--- a/modules/team_planner/config/locales/js-en.yml
+++ b/modules/team_planner/config/locales/js-en.yml
@@ -14,3 +14,4 @@ en:
quick_add:
empty_state: 'Use the search field to find work packages and drag them to the planner to assign it to someone and define start and end dates.'
+ search_placeholder: 'Search...'