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
Debounced filtering of potential board column candidates
Oliver Güntherfe7e59c706d0
diff --git a/frontend/src/app/components/api/api-v3/api-v3-filter-builder.ts b/frontend/src/app/components/api/api-v3/api-v3-filter-builder.tsindex 64b38cf6a96..e9ff8ad34ea 100644--- a/frontend/src/app/components/api/api-v3/api-v3-filter-builder.ts+++ b/frontend/src/app/components/api/api-v3/api-v3-filter-builder.ts@@ -27,10 +27,12 @@//++export type FilterOperator = '='|'!*'|'!'|'~'|'o'|'>t-'|'<>d'|'**'|'ow' ;+export const FalseValue = ['f'];+export const TrueValue = ['t'];export interface ApiV3FilterValue {operator:FilterOperator;- values:any;+ values:unknown[];}export interface ApiV3Filter {@@ -43,7 +45,15 @@ export class ApiV3FilterBuilder {private filterMap:ApiV3FilterObject = {};- public add(name:string, operator:FilterOperator, values:any):this {+ public add(name:string, operator:FilterOperator, values:unknown[]|boolean):this {+ if (values === true) {+ values = TrueValue;+ }++ if (values === false) {+ values = FalseValue;+ }+this.filterMap[name] = {operator: operator,values: valuesdiff --git a/frontend/src/app/helpers/rxjs/debounced-input-switchmap.ts b/frontend/src/app/helpers/rxjs/debounced-input-switchmap.tsindex 6b2294d0e16..a87559b585e 100644--- a/frontend/src/app/helpers/rxjs/debounced-input-switchmap.ts+++ b/frontend/src/app/helpers/rxjs/debounced-input-switchmap.ts@@ -3,7 +3,7 @@ import {HalResource} from "core-app/modules/hal/resources/hal-resource";import {catchError,debounceTime,- distinctUntilChanged,+ distinctUntilChanged, filter,switchMap,takeUntil,tap@@ -47,6 +47,7 @@ export class DebouncedRequestSwitchmap<T, R = HalResource> {this.output$ = concat(of([]),this.input$.pipe(+ filter(val => val !== undefined && val !== null),distinctUntilChanged(),debounceTime(debounceMs),tap((val:T) => {diff --git a/frontend/src/app/modules/boards/board/add-list-modal/add-list-modal.component.ts b/frontend/src/app/modules/boards/board/add-list-modal/add-list-modal.component.tsindex 3f7f52e9012..3df9c41ec03 100644--- a/frontend/src/app/modules/boards/board/add-list-modal/add-list-modal.component.ts+++ b/frontend/src/app/modules/boards/board/add-list-modal/add-list-modal.component.ts@@ -39,11 +39,21 @@ import {BoardActionService} from "core-app/modules/boards/board/board-actions/boimport {HalResource} from "core-app/modules/hal/resources/hal-resource";import {AngularTrackingHelpers} from "core-components/angular/tracking-functions";import {CreateAutocompleterComponent} from "core-app/modules/common/autocomplete/create-autocompleter.component";+import {of} from "rxjs";+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 {HalResourceNotificationService} from "core-app/modules/hal/services/hal-resource-notification.service";@Component({templateUrl: './add-list-modal.html'})export class AddListModalComponent extends OpModalComponent implements OnInit {+ /** Keep a switchmap for search term and loading state */+ public requests = new DebouncedRequestSwitchmap<string, ValueOption>(+ (searchTerm:string) => this.actionService.loadAvailable(this.board, this.active, searchTerm),+ errorNotificationHandler(this.halNotification)+ );+public showClose:boolean;public confirmed = false;@@ -57,9 +67,6 @@ export class AddListModalComponent extends OpModalComponent implements OnInit {/** Action service used by the board */public actionService:BoardActionService;- /** Remaining available values */- public availableValues:HalResource[] = [];-/** The selected attribute */public selectedAttribute:HalResource|undefined;@@ -71,8 +78,6 @@ export class AddListModalComponent extends OpModalComponent implements OnInit {/* Do not close on outside click (because the select option are appended to the body */public closeOnOutsideClick = false;- public valuesAvailable:boolean = true;-public warningText:string|undefined;public text:any = {@@ -100,6 +105,7 @@ export class AddListModalComponent extends OpModalComponent implements OnInit {@Inject(OpModalLocalsToken) public locals:OpModalLocalsMap,readonly cdRef:ChangeDetectorRef,readonly boardActions:BoardActionsRegistryService,+ readonly halNotification:HalResourceNotificationService,readonly state:StateService,readonly boardService:BoardService,readonly I18n:I18nService) {@@ -115,17 +121,9 @@ export class AddListModalComponent extends OpModalComponent implements OnInit {this.actionService = this.boardActions.get(this.board.actionAttribute!);this.actionService- .getAvailableValues(this.board, this.active)- .then(available => {- this.availableValues = available;- if (this.availableValues.length === 0) {- this.actionService- .warningTextWhenNoOptionsAvailable()- .then((text) => {- this.warningText = text;- this.valuesAvailable = false;- });- }+ .warningTextWhenNoOptionsAvailable()+ .then((text) => {+ this.warningText = text;});}@@ -147,7 +145,6 @@ export class AddListModalComponent extends OpModalComponent implements OnInit {}onNewActionCreated(newValue:HalResource) {- this.actionService.cache.clear("New attribute added.");this.selectedAttribute = newValue;this.create();}diff --git a/frontend/src/app/modules/boards/board/add-list-modal/add-list-modal.html b/frontend/src/app/modules/boards/board/add-list-modal/add-list-modal.htmlindex 2c38fd37862..d756a09c029 100644--- a/frontend/src/app/modules/boards/board/add-list-modal/add-list-modal.html+++ b/frontend/src/app/modules/boards/board/add-list-modal/add-list-modal.html@@ -19,7 +19,8 @@<div class="form--select-container"><label class="form--label" [textContent]="actionService.localizedName"></label><ndc-dynamic [ndcDynamicComponent]="autocompleterComponent()"- [ndcDynamicInputs]="{ availableValues: availableValues,+ [ndcDynamicInputs]="{ availableValues: requests.output$ | async,+ typeahead: requests.input$,appendTo: 'body',model: '',classes: 'new-list--action-select',@@ -30,7 +31,7 @@</div></div>- <div *ngIf="!valuesAvailable && warningText"+ <div *ngIf="!requests.hasResults && warningText"class="notification-box -warning"><div class="notification-box--content"><p [innerHTML]="warningText"></p>diff --git a/frontend/src/app/modules/boards/board/board-actions/assignee/assignee-action.service.ts b/frontend/src/app/modules/boards/board/board-actions/assignee/assignee-action.service.tsindex e93f215cc84..b24dc90249b 100644--- a/frontend/src/app/modules/boards/board/board-actions/assignee/assignee-action.service.ts+++ b/frontend/src/app/modules/boards/board/board-actions/assignee/assignee-action.service.ts@@ -1,14 +1,15 @@import {Injectable} from "@angular/core";import {BoardActionService} from "core-app/modules/boards/board/board-actions/board-action.service";-import {HalResource} from "core-app/modules/hal/resources/hal-resource";import {UserResource} from 'core-app/modules/hal/resources/user-resource';import {CollectionResource} from 'core-app/modules/hal/resources/collection-resource';import {AssigneeBoardHeaderComponent} from "core-app/modules/boards/board/board-actions/assignee/assignee-board-header.component";import {ProjectResource} from "core-app/modules/hal/resources/project-resource";-import {take} from "rxjs/operators";+import {StatusResource} from "core-app/modules/hal/resources/status-resource";+import {CachedBoardActionService} from "core-app/modules/boards/board/board-actions/cached-board-action.service";+import {HalResource} from "core-app/modules/hal/resources/hal-resource";@Injectable()-export class BoardAssigneeActionService extends BoardActionService {+export class BoardAssigneeActionService extends CachedBoardActionService {filterName = 'assignee';text = this.I18n.t('js.boards.board_type.action_by_attribute',@@ -49,7 +50,7 @@ export class BoardAssigneeActionService extends BoardActionService {});}- protected loadAvailable():Promise<HalResource[]> {+ protected loadUncached():Promise<HalResource[]> {return this.apiV3Service.projectsdiff --git a/frontend/src/app/modules/boards/board/board-actions/board-action.service.ts b/frontend/src/app/modules/boards/board/board-actions/board-action.service.tsindex e9d61026ec4..0c341eb694d 100644--- a/frontend/src/app/modules/boards/board/board-actions/board-action.service.ts+++ b/frontend/src/app/modules/boards/board/board-actions/board-action.service.ts@@ -12,21 +12,18 @@ import {HalResourceService} from "core-app/modules/hal/services/hal-resource.serimport {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";import {CurrentProjectService} from "core-components/projects/current-project.service";import {Injectable, Injector} from "@angular/core";-import {take} from "rxjs/operators";-import {input} from "reactivestates";+import {map} from "rxjs/operators";import {WorkPackageResource} from "core-app/modules/hal/resources/work-package-resource";import {IFieldSchema} from "core-app/modules/fields/field.base";import {WorkPackageChangeset} from "core-components/wp-edit/work-package-changeset";import {WorkPackageFilterValues} from "core-components/wp-edit-form/work-package-filter-values";import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";import {SchemaCacheService} from "core-components/schemas/schema-cache.service";+import {Observable} from "rxjs";@Injectable()export abstract class BoardActionService {- // Cache the available values for the duration of the board- readonly cache = input<HalResource[]>();-constructor(readonly injector:Injector,protected boardListsService:BoardListsService,protected I18n:I18nService,@@ -90,8 +87,7 @@ export abstract class BoardActionService {}return this- .withLoadedAvailable()- .then(collection => collection.find(resource => resource.href === href));+ .require(href);}/**@@ -126,12 +122,13 @@ export abstract class BoardActionService {** @param board The board we're looking at* @param active The active set of values (hrefs or plain values)+ * @param matching values matching the given name*/- getAvailableValues(board:Board, active:Set<string>):Promise<HalResource[]> {+ loadAvailable(board:Board, active:Set<string>, matching:string):Observable<HalResource[]> {return this- .withLoadedAvailable()- .then(results =>- results.filter(item => !active.has(item.id!))+ .loadValues(matching)+ .pipe(+ map(items => items.filter(item => !active.has(item.id!))));}@@ -218,17 +215,20 @@ export abstract class BoardActionService {filter.applyDefaultsFromFilters();}- protected withLoadedAvailable():Promise<HalResource[]> {- this.cache.putFromPromiseIfPristine(() => this.loadAvailable());-- return this.cache- .values$()- .pipe(take(1))- .toPromise();- }+ /**+ * Require the given resource to be loaded.+ *+ * @param href+ * @protected+ */+ protected abstract require(href:string):Promise<HalResource>;/**- * Load the available values for this action attribute+ * Load values optionally matching the given name+ *+ * @param matching+ * @protected*/- protected abstract loadAvailable():Promise<HalResource[]>;+ protected abstract loadValues(matching?:string):Observable<HalResource[]>;}+diff --git a/frontend/src/app/modules/boards/board/board-actions/cached-board-action.service.ts b/frontend/src/app/modules/boards/board/board-actions/cached-board-action.service.tsnew file mode 100644index 00000000000..7b104896fea--- /dev/null+++ b/frontend/src/app/modules/boards/board/board-actions/cached-board-action.service.ts@@ -0,0 +1,48 @@+import {Injectable} from "@angular/core";+import {BoardActionService} from "core-app/modules/boards/board/board-actions/board-action.service";+import {input} from "reactivestates";+import {HalResource} from "core-app/modules/hal/resources/hal-resource";+import {Observable} from "rxjs";+import {filter, map, take} from "rxjs/operators";++@Injectable()+export abstract class CachedBoardActionService extends BoardActionService {+ protected cache = input<HalResource[]>([]);++ protected loadValues(matching?:string):Observable<HalResource[]> {+ this+ .cache+ .putFromPromiseIfPristine(() => this.loadUncached());++ return this+ .cache+ .values$()+ .pipe(+ map(results => {+ if (matching) {+ return results.filter(resource => resource.name.includes(matching));+ } else {+ return results;+ }+ }),+ take(1)+ );+ }++ protected require(idOrHref:string):Promise<HalResource> {+ this+ .cache+ .putFromPromiseIfPristine(() => this.loadUncached());++ return this+ .cache+ .values$()+ .toPromise()+ .then(results => {+ return results.find(resource => resource.id === idOrHref || resource.href === idOrHref)!;+ });+ }++ protected abstract loadUncached():Promise<HalResource[]>;+}+diff --git a/frontend/src/app/modules/boards/board/board-actions/status/status-action.service.ts b/frontend/src/app/modules/boards/board/board-actions/status/status-action.service.tsindex 4ec33929721..1bb00685e09 100644--- a/frontend/src/app/modules/boards/board/board-actions/status/status-action.service.ts+++ b/frontend/src/app/modules/boards/board/board-actions/status/status-action.service.ts@@ -2,9 +2,10 @@ import {Injectable} from "@angular/core";import {Board} from "core-app/modules/boards/board/board";import {StatusResource} from "core-app/modules/hal/resources/status-resource";import {BoardActionService} from "core-app/modules/boards/board/board-actions/board-action.service";+import {CachedBoardActionService} from "core-app/modules/boards/board/board-actions/cached-board-action.service";@Injectable()-export class BoardStatusActionService extends BoardActionService {+export class BoardStatusActionService extends CachedBoardActionService {filterName = 'status';text = this.I18n.t('js.boards.board_type.action_by_attribute',@@ -20,7 +21,9 @@ export class BoardStatusActionService extends BoardActionService {}public addInitialColumnsForAction(board:Board):Promise<Board> {- return this.withLoadedAvailable()+ return this+ .loadValues()+ .toPromise().then((results) =>Promise.all<unknown>(results.map((status:StatusResource) => {@@ -40,7 +43,7 @@ export class BoardStatusActionService extends BoardActionService {return Promise.resolve(this.I18n.t('js.boards.add_list_modal.warning.status'));}- protected loadAvailable():Promise<StatusResource[]> {+ protected loadUncached():Promise<StatusResource[]> {return this.apiV3Service.statuses@@ -48,5 +51,4 @@ export class BoardStatusActionService extends BoardActionService {.toPromise().then(collection => collection.elements);}-}diff --git a/frontend/src/app/modules/boards/board/board-actions/subproject/subproject-action.service.ts b/frontend/src/app/modules/boards/board/board-actions/subproject/subproject-action.service.tsindex b914c56439b..da6623fb48d 100644--- a/frontend/src/app/modules/boards/board/board-actions/subproject/subproject-action.service.ts+++ b/frontend/src/app/modules/boards/board/board-actions/subproject/subproject-action.service.ts@@ -1,18 +1,17 @@import {Injectable} from "@angular/core";import {QueryResource} from "core-app/modules/hal/resources/query-resource";-import {BoardActionService} from "core-app/modules/boards/board/board-actions/board-action.service";import {HalResource} from "core-app/modules/hal/resources/hal-resource";import {buildApiV3Filter} from "core-components/api/api-v3/api-v3-filter-builder";import {UserResource} from 'core-app/modules/hal/resources/user-resource';import {CollectionResource} from 'core-app/modules/hal/resources/collection-resource';import {input} from "reactivestates";-import {take} from "rxjs/operators";import {WorkPackageChangeset} from "core-components/wp-edit/work-package-changeset";import {WorkPackageResource} from "core-app/modules/hal/resources/work-package-resource";import {SubprojectBoardHeaderComponent} from "core-app/modules/boards/board/board-actions/subproject/subproject-board-header.component";+import {CachedBoardActionService} from "core-app/modules/boards/board/board-actions/cached-board-action.service";@Injectable()-export class BoardSubprojectActionService extends BoardActionService {+export class BoardSubprojectActionService extends CachedBoardActionService {filterName = 'onlySubproject';text = this.I18n.t('js.boards.board_type.action_by_attribute',@@ -44,22 +43,15 @@ export class BoardSubprojectActionService extends BoardActionService {changeset.setValue('project', { href: href });}- protected loadAvailable():Promise<HalResource[]> {+ protected loadUncached():Promise<HalResource[]> {const currentProjectId = this.currentProject.id!;- this.subprojects.putFromPromiseIfPristine(() =>- this+ return this.apiV3Service.projects.filtered(buildApiV3Filter('ancestor', '=', [currentProjectId])).get().toPromise()- .then((collection:CollectionResource<UserResource>) => collection.elements)- );-- return this.subprojects- .values$()- .pipe(take(1))- .toPromise();+ .then((collection:CollectionResource<UserResource>) => collection.elements);}}diff --git a/frontend/src/app/modules/boards/board/board-actions/subtasks/board-subtasks-action.service.ts b/frontend/src/app/modules/boards/board/board-actions/subtasks/board-subtasks-action.service.tsnew file mode 100644index 00000000000..caecd455393--- /dev/null+++ b/frontend/src/app/modules/boards/board/board-actions/subtasks/board-subtasks-action.service.ts@@ -0,0 +1,49 @@+import {Injectable} from "@angular/core";+import {Board} from "core-app/modules/boards/board/board";+import {StatusResource} from "core-app/modules/hal/resources/status-resource";+import {BoardActionService} from "core-app/modules/boards/board/board-actions/board-action.service";+import {WorkPackageResource} from "core-app/modules/hal/resources/work-package-resource";+import {HalResource} from "core-app/modules/hal/resources/hal-resource";+import {Observable} from "rxjs";+import {map} from "rxjs/operators";+import {ApiV3FilterBuilder, buildApiV3Filter, FalseValue} from "core-components/api/api-v3/api-v3-filter-builder";++@Injectable()+export class BoardSubtasksActionService extends BoardActionService {+ filterName = 'parent';++ public get localizedName() {+ return this.I18n.t('js.boards.board_type.action_type.subtasks');+ }++ public canMove(workPackage:WorkPackageResource):boolean {+ return !!workPackage.changeParent;+ }++ protected loadValues(matching?:string):Observable<HalResource[]> {+ let filters = new ApiV3FilterBuilder();+ filters.add('is_milestone', '=', false);++ if (matching) {+ filters.add('subjectOrId', '**', [matching]);+ }++ return this+ .apiV3Service+ .work_packages+ .filtered(filters)+ .get()+ .pipe(+ map(collection => collection.elements)+ );+ }++ protected require(id:string):Promise<HalResource> {+ return this+ .apiV3Service+ .work_packages+ .id(id)+ .get()+ .toPromise();+ }+}diff --git a/frontend/src/app/modules/boards/board/board-actions/version/version-action.service.ts b/frontend/src/app/modules/boards/board/board-actions/version/version-action.service.tsindex da2c997e8b2..c8a0f888412 100644--- a/frontend/src/app/modules/boards/board/board-actions/version/version-action.service.ts+++ b/frontend/src/app/modules/boards/board/board-actions/version/version-action.service.ts@@ -12,9 +12,10 @@ import {HalResourceNotificationService} from "core-app/modules/hal/services/hal-import {VersionBoardHeaderComponent} from "core-app/modules/boards/board/board-actions/version/version-board-header.component";import {FormResource} from "core-app/modules/hal/resources/form-resource";import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {CachedBoardActionService} from "core-app/modules/boards/board/board-actions/cached-board-action.service";@Injectable()-export class BoardVersionActionService extends BoardActionService {+export class BoardVersionActionService extends CachedBoardActionService {@InjectField() state:StateService;@InjectField() halNotification:HalResourceNotificationService;@@ -50,7 +51,9 @@ export class BoardVersionActionService extends BoardActionService {}public addInitialColumnsForAction(board:Board):Promise<Board> {- return this.withLoadedAvailable()+ return this+ .loadValues()+ .toPromise().then((results) => {return Promise.all<unknown>(results.map((version:VersionResource) => {@@ -105,7 +108,7 @@ export class BoardVersionActionService extends BoardActionService {return value instanceof VersionResource && value.isOpen();}- protected loadAvailable():Promise<VersionResource[]> {+ protected loadUncached():Promise<HalResource[]> {if (this.currentProject.id === null) {return Promise.resolve([]);}diff --git a/frontend/src/app/modules/boards/board/board-partitioned-page/board-list-container.component.ts b/frontend/src/app/modules/boards/board/board-partitioned-page/board-list-container.component.tsindex cef15d4f243..a375f302891 100644--- a/frontend/src/app/modules/boards/board/board-partitioned-page/board-list-container.component.ts+++ b/frontend/src/app/modules/boards/board/board-partitioned-page/board-list-container.component.ts@@ -204,7 +204,7 @@ export class BoardListContainerComponent extends UntilDestroyedMixin implementsconst filter = _.find(options.filters, (filter) => !!filter[filterName]);if (filter) {- return filter[filterName].values[0];+ return filter[filterName].values[0] as any;}}).filter(value => !!value);diff --git a/frontend/src/app/modules/boards/boards-root/boards-root.component.ts b/frontend/src/app/modules/boards/boards-root/boards-root.component.tsindex 9ca28072bbe..6fab1d38692 100644--- a/frontend/src/app/modules/boards/boards-root/boards-root.component.ts+++ b/frontend/src/app/modules/boards/boards-root/boards-root.component.ts@@ -6,6 +6,7 @@ import {BoardVersionActionService} from "core-app/modules/boards/board/board-actimport {QueryUpdatedService} from "core-app/modules/boards/board/query-updated/query-updated.service";import {BoardAssigneeActionService} from "core-app/modules/boards/board/board-actions/assignee/assignee-action.service";import {BoardSubprojectActionService} from "core-app/modules/boards/board/board-actions/subproject/subproject-action.service";+import {BoardSubtasksActionService} from "core-app/modules/boards/board/board-actions/subtasks/board-subtasks-action.service";@Component({selector: 'boards-entry',@@ -16,6 +17,7 @@ import {BoardSubprojectActionService} from "core-app/modules/boards/board/board-BoardVersionActionService,BoardAssigneeActionService,BoardSubprojectActionService,+ BoardSubtasksActionService,QueryUpdatedService,]})@@ -25,14 +27,11 @@ export class BoardsRootComponent {// Register action servicesconst registry = injector.get(BoardActionsRegistryService);- const statusAction = injector.get(BoardStatusActionService);- const versionAction = injector.get(BoardVersionActionService);- const assigneeAction = injector.get(BoardAssigneeActionService);- const subprojectAction = injector.get(BoardSubprojectActionService);- registry.add('status', statusAction);- registry.add('assignee', assigneeAction);- registry.add('version', versionAction);- registry.add('subproject', subprojectAction);+ registry.add('status', injector.get(BoardStatusActionService));+ registry.add('assignee', injector.get(BoardAssigneeActionService));+ registry.add('version', injector.get(BoardVersionActionService));+ registry.add('subproject', injector.get(BoardSubprojectActionService));+ registry.add('subtasks', injector.get(BoardSubtasksActionService));}}diff --git a/frontend/src/app/modules/common/autocomplete/create-autocompleter.component.html b/frontend/src/app/modules/common/autocomplete/create-autocompleter.component.htmlindex fbeae05a7cf..a3592ac61f4 100644--- a/frontend/src/app/modules/common/autocomplete/create-autocompleter.component.html+++ b/frontend/src/app/modules/common/autocomplete/create-autocompleter.component.html@@ -9,6 +9,7 @@[disabled]="disabled"[typeahead]="typeahead"[clearOnBackspace]="false"+ [clearSearchOnAdd]="false"[appendTo]="appendTo"[hideSelected]="hideSelected"[id]="id"diff --git a/modules/boards/config/locales/js-en.yml b/modules/boards/config/locales/js-en.ymlindex 6357391b8ac..ed8f2b0a642 100644--- a/modules/boards/config/locales/js-en.yml+++ b/modules/boards/config/locales/js-en.yml@@ -50,6 +50,7 @@ en:status: statusversion: versionsubproject: subproject+ subtasks: childrenselect_attribute: "Action attribute"add_list_modal: