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
Make selection and focus service a view service to separate states
Oliver Günther1732938a4db6
diff --git a/frontend/src/app/components/modals/wp-destroy-modal/wp-destroy.modal.ts b/frontend/src/app/components/modals/wp-destroy-modal/wp-destroy.modal.tsindex c71442f9d9f..1e5ee56da21 100644--- a/frontend/src/app/components/modals/wp-destroy-modal/wp-destroy.modal.ts+++ b/frontend/src/app/components/modals/wp-destroy-modal/wp-destroy.modal.ts@@ -134,7 +134,7 @@ export class WpDestroyModal extends OpModalComponent implements OnInit {.then(() => {this.busy = false;this.closeMe($event);- this.wpTableFocus.clear();+ this.wpTableFocus.clear('Clearing after destroying work packages');// Go back to a previous list state if we're in a split or full viewif (this.$state.current.data.baseRoute) {diff --git a/frontend/src/app/components/wp-card-view/wp-single-card/wp-single-card.component.ts b/frontend/src/app/components/wp-card-view/wp-single-card/wp-single-card.component.tsindex 9481ad52a98..a1c9c0ddcf4 100644--- a/frontend/src/app/components/wp-card-view/wp-single-card/wp-single-card.component.ts+++ b/frontend/src/app/components/wp-card-view/wp-single-card/wp-single-card.component.ts@@ -58,7 +58,7 @@ export class WorkPackageSingleCardComponent extends UntilDestroyedMixin implemenngOnInit():void {// Update selection state- this.wpTableSelection.selection$()+ this.wpTableSelection.live$().pipe(this.untilDestroyed())diff --git a/frontend/src/app/components/wp-fast-table/handlers/state/selection-transformer.ts b/frontend/src/app/components/wp-fast-table/handlers/state/selection-transformer.tsindex bf47994a18d..09378b1679d 100644--- a/frontend/src/app/components/wp-fast-table/handlers/state/selection-transformer.ts+++ b/frontend/src/app/components/wp-fast-table/handlers/state/selection-transformer.ts@@ -41,7 +41,7 @@ export class SelectionTransformer {// Update selection state- this.wpTableSelection.selection$()+ this.wpTableSelection.live$().pipe(takeUntil(this.querySpace.stopAllSubscriptions))diff --git a/frontend/src/app/modules/boards/board/board-list/board-list-cross-selection.service.ts b/frontend/src/app/modules/boards/board/board-list/board-list-cross-selection.service.tsindex b1695dcb162..79a3192634f 100644--- a/frontend/src/app/modules/boards/board/board-list/board-list-cross-selection.service.ts+++ b/frontend/src/app/modules/boards/board/board-list/board-list-cross-selection.service.ts@@ -6,7 +6,7 @@ export interface BoardSelection {withinQuery:string;/** The focused selected work package */- focusedWorkPackage:string;+ focusedWorkPackage:string|null;/** Array of selected work packages */allSelected:string[];diff --git a/frontend/src/app/modules/boards/board/board-list/board-list.component.ts b/frontend/src/app/modules/boards/board/board-list/board-list.component.tsindex a644b425583..1ccfaeae5a9 100644--- a/frontend/src/app/modules/boards/board/board-list/board-list.component.ts+++ b/frontend/src/app/modules/boards/board/board-list/board-list.component.ts@@ -54,7 +54,6 @@ import {WorkPackageViewFocusService} from "core-app/modules/work_packages/routinimport {WorkPackageViewSelectionService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-selection.service";import {BoardListCrossSelectionService} from "core-app/modules/boards/board/board-list/board-list-cross-selection.service";import {debounceTime} from "rxjs/operators";-import {combineLatest} from "rxjs";export interface DisabledButtonPlaceholder {text:string;@@ -161,7 +160,7 @@ export class BoardListComponent extends AbstractWidgetComponent implements OnIni// Set initial selection if split view openif (this.state.includes(this.state.current.data.baseRoute + '.details')) {let wpId = this.state.params.workPackageId;- this.wpViewSelectionService.setMultiSelection([wpId]);+ this.wpViewSelectionService.initializeSelection([wpId]);}// Update permission on model updates@@ -174,26 +173,21 @@ export class BoardListComponent extends AbstractWidgetComponent implements OnIni}});- let lastSelection:string[];-// If this query space changes its focused or selected// work packages, update the board cross selection- combineLatest([- this.wpViewFocusService.state.values$(),- this.wpViewSelectionService.selection$()- ]).pipe(- debounceTime(100),- this.untilDestroyed()- ).subscribe(([focusedState, selectionState]) => {+ this.wpViewSelectionService+ .updates$()+ .pipe(+ debounceTime(100),+ this.untilDestroyed()+ ).subscribe((selectionState) => {let selected = Object.keys(_.pickBy(selectionState.selected, (selected, _) => selected === true));- if (_.isEqual(selected, lastSelection)) {- return;- }+ const focused = this.wpViewFocusService.focusedWorkPackage;this.boardListCrossSelectionService.updateSelection({withinQuery: this.queryId,- focusedWorkPackage: focusedState.workPackageId,+ focusedWorkPackage: focused,allSelected: selected});});@@ -205,8 +199,7 @@ export class BoardListComponent extends AbstractWidgetComponent implements OnInithis.untilDestroyed()).subscribe(selection => {- lastSelection = selection.allSelected;- this.wpViewSelectionService.setMultiSelection(selection.allSelected);+ this.wpViewSelectionService.initializeSelection(selection.allSelected);});// Update query on filter changediff --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 933bc68ae42..86816ebeeb3 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@@ -102,6 +102,7 @@ export class BoardListContainerComponent extends UntilDestroyedMixin implements.selections().pipe(this.untilDestroyed(),+ filter((state) => state.focusedWorkPackage !== null),filter(() => this.state.includes(this.state.current.data.baseRoute + '.details'))).subscribe(selection => {// Update split screendiff --git a/frontend/src/app/modules/work_packages/query-space/isolated-query-space.ts b/frontend/src/app/modules/work_packages/query-space/isolated-query-space.tsindex 2407402b863..fc471a6b792 100644--- a/frontend/src/app/modules/work_packages/query-space/isolated-query-space.ts+++ b/frontend/src/app/modules/work_packages/query-space/isolated-query-space.ts@@ -5,7 +5,6 @@ import {map} from 'rxjs/operators';import {QueryResource} from 'core-app/modules/hal/resources/query-resource';import {GroupObject, WorkPackageCollectionResource} from 'core-app/modules/hal/resources/wp-collection-resource';import {QueryFormResource} from "core-app/modules/hal/resources/query-form-resource";-import {WPFocusState} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-focus.service";import {QueryColumn} from "core-components/wp-query/query-column";import {RenderedWorkPackage} from "core-app/modules/work_packages/render-info/rendered-work-package.type";@@ -48,9 +47,6 @@ export class IsolatedQuerySpace extends StatesGroup {map(rows => rows.map(row => row.workPackageId!.toString()))));- // Current focused work package (e.g, row preselected for details button)- focusedWorkPackage:InputState<WPFocusState> = input<WPFocusState>();-// Subject used to unregister all listeners of states above.stopAllSubscriptions = new Subject();diff --git a/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-base.service.ts b/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-base.service.tsindex afcef03a100..c4289ce4820 100644--- a/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-base.service.ts+++ b/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-base.service.ts@@ -33,7 +33,7 @@ import {merge, Observable} from 'rxjs';import {QueryResource} from 'core-app/modules/hal/resources/query-resource';import {QuerySchemaResource} from 'core-app/modules/hal/resources/query-schema-resource';import {WorkPackageCollectionResource} from 'core-app/modules/hal/resources/wp-collection-resource';-import { Injectable } from "@angular/core";+import {Injectable} from "@angular/core";@Injectable()export abstract class WorkPackageViewBaseService<T> {@@ -109,6 +109,17 @@ export abstract class WorkPackageViewBaseService<T> {.values$();}+ /**+ * Get only the local update changes+ *+ * @param unsubscribe+ */+ public changes$():Observable<unknown> {+ return this+ .updatesState+ .changes$();+ }+public onReady() {return this.pristineStatediff --git a/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-focus.service.ts b/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-focus.service.tsindex 8fc2e64e9a4..e7fb052ade1 100644--- a/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-focus.service.ts+++ b/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-focus.service.ts@@ -28,10 +28,12 @@import {Injectable} from '@angular/core';import {IsolatedQuerySpace} from "core-app/modules/work_packages/query-space/isolated-query-space";-import {InputState} from 'reactivestates';import {Observable} from 'rxjs';import {distinctUntilChanged, map} from 'rxjs/operators';import {WorkPackageViewSelectionService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-selection.service";+import {WorkPackageViewBaseService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-base.service";+import {QueryResource} from "core-app/modules/hal/resources/query-resource";+import {WorkPackageCollectionResource} from "core-app/modules/hal/resources/wp-collection-resource";export interface WPFocusState {workPackageId:string;@@ -39,13 +41,11 @@ export interface WPFocusState {}@Injectable()-export class WorkPackageViewFocusService {-- public state:InputState<WPFocusState>;+export class WorkPackageViewFocusService extends WorkPackageViewBaseService<WPFocusState> {constructor(public querySpace:IsolatedQuerySpace,public wpTableSelection:WorkPackageViewSelectionService) {- this.state = querySpace.focusedWorkPackage;+ super(querySpace);}public isFocused(workPackageId:string) {@@ -53,17 +53,17 @@ export class WorkPackageViewFocusService {}public ifShouldFocus(callback:(workPackageId:string) => void) {- const value = this.state.value;+ const value = this.current;if (value && value.focusAfterRender) {callback(value.workPackageId);value.focusAfterRender = false;- this.state.putValue(value, 'Setting focus to false after callback.');+ this.update(value);}}- public get focusedWorkPackage():string | null {- const value = this.state.value;+ public get focusedWorkPackage():string|null {+ const value = this.current;if (value) {return value.workPackageId;@@ -78,12 +78,8 @@ export class WorkPackageViewFocusService {return null;}- public clear() {- this.state.clear();- }-public whenChanged():Observable<string> {- return this.state.values$()+ return this.live$().pipe(map((val:WPFocusState) => val.workPackageId),distinctUntilChanged()@@ -95,6 +91,10 @@ export class WorkPackageViewFocusService {if (this.wpTableSelection.isEmpty) {this.wpTableSelection.setRowState(workPackageId, true);}- this.state.putValue({workPackageId: workPackageId, focusAfterRender: setFocusAfterRender});+ this.update({ workPackageId: workPackageId, focusAfterRender: setFocusAfterRender });+ }++ valueFromQuery(query:QueryResource, results:WorkPackageCollectionResource):WPFocusState|undefined {+ return undefined;}}diff --git a/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-selection.service.ts b/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-selection.service.tsindex 468a7b1bef2..c4f5ef3177c 100644--- a/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-selection.service.ts+++ b/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-selection.service.ts@@ -1,4 +1,3 @@-import {input} from 'reactivestates';import {IsolatedQuerySpace} from "core-app/modules/work_packages/query-space/isolated-query-space";import {WorkPackageCacheService} from 'core-components/work-packages/work-package-cache.service';import {Injectable, OnDestroy} from '@angular/core';@@ -6,6 +5,9 @@ import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-rimport {States} from 'core-components/states.service';import {OPContextMenuService} from "core-components/op-context-menu/op-context-menu.service";import {RenderedWorkPackage} from "core-app/modules/work_packages/render-info/rendered-work-package.type";+import {WorkPackageViewBaseService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-base.service";+import {QueryResource} from "core-app/modules/hal/resources/query-resource";+import {WorkPackageCollectionResource} from "core-app/modules/hal/resources/wp-collection-resource";export interface WorkPackageViewSelectionState {// Map of selected rows@@ -16,14 +18,13 @@ export interface WorkPackageViewSelectionState {}@Injectable()-export class WorkPackageViewSelectionService implements OnDestroy {-- private selectionState = input<WorkPackageViewSelectionState>();+export class WorkPackageViewSelectionService extends WorkPackageViewBaseService<WorkPackageViewSelectionState> implements OnDestroy {public constructor(readonly querySpace:IsolatedQuerySpace,readonly states:States,readonly wpCacheService:WorkPackageCacheService,readonly opContextMenu:OPContextMenuService) {+ super(querySpace);this.reset();}@@ -32,8 +33,20 @@ export class WorkPackageViewSelectionService implements OnDestroy {Mousetrap.unbind(['command+a', 'ctrl+a']);}- public isSelected(workPackageId:string) {- return this.currentState.selected[workPackageId];+ public initializeSelection(selectedWorkPackageIds:string[]) {+ let state:WorkPackageViewSelectionState = {+ selected: {},+ activeRowIndex: null+ };++ selectedWorkPackageIds.forEach(id => state.selected[id] = true);++ this.updatesState.clear();+ this.pristineState.putValue(state);+ }++ public isSelected(workPackageId:string):boolean {+ return !!this.current?.selected[workPackageId];}/**@@ -48,7 +61,7 @@ export class WorkPackageViewSelectionService implements OnDestroy {}});- this.selectionState.putValue(state);+ this.update(state);}/**@@ -62,7 +75,7 @@ export class WorkPackageViewSelectionService implements OnDestroy {public getSelectedWorkPackageIds():string[] {let selected:string[] = [];- _.each(this.currentState.selected, (isSelected:boolean, wpId:string) => {+ _.each(this.current?.selected, (isSelected:boolean, wpId:string) => {if (isSelected) {selected.push(wpId);}@@ -75,22 +88,7 @@ export class WorkPackageViewSelectionService implements OnDestroy {* Reset the selection state to an empty selection*/public reset() {- this.selectionState.putValue(this._emptyState);- }-- /**- * Observe selection state- */- public selection$() {- return this.selectionState.values$();- }-- /**- * Get current selection state.- * @returns {WorkPackageViewSelectionState}- */- public get currentState():WorkPackageViewSelectionState {- return this.selectionState.value as WorkPackageViewSelectionState;+ this.update(this._emptyState);}public get isEmpty() {@@ -101,7 +99,7 @@ export class WorkPackageViewSelectionService implements OnDestroy {* Return the number of selected rows.*/public get selectionCount():number {- return _.size(this.currentState.selected);+ return _.size(this.current?.selected);}/**@@ -109,7 +107,7 @@ export class WorkPackageViewSelectionService implements OnDestroy {* @param workPackageId*/public toggleRow(workPackageId:string) {- let isSelected = this.currentState.selected[workPackageId];+ let isSelected = this.current?.selected[workPackageId];this.setRowState(workPackageId, !isSelected);}@@ -119,30 +117,20 @@ export class WorkPackageViewSelectionService implements OnDestroy {* @param newState*/public setRowState(workPackageId:string, newState:boolean) {- let state = this.currentState;+ let state = this.current || this._emptyState;state.selected[workPackageId] = newState;- this.selectionState.putValue(state);+ this.update(state);}/*** Override current selection with the given work package id.*/public setSelection(wpId:string, position:number) {- this.setMultiSelection([wpId], position);- }+ const current = this._emptyState;+ current.selected[wpId] = true;+ current.activeRowIndex = position;- /**- * Select a number of work packages- */- public setMultiSelection(selectedWorkPackageIds:string[], activeRowIndex:number|null = null) {- let state:WorkPackageViewSelectionState = {- selected: {},- activeRowIndex: activeRowIndex- };-- selectedWorkPackageIds.forEach(id => state.selected[id] = true);-- this.selectionState.putValue(state);+ this.update(current);}/**@@ -151,7 +139,7 @@ export class WorkPackageViewSelectionService implements OnDestroy {* (aka shift click expansion)*/public setMultiSelectionFrom(rows:RenderedWorkPackage[], wpId:string, position:number) {- let state = this.currentState;+ let state = this.current || this._emptyState;// If there are no other selections, it does not matter what the index isif (this.selectionCount === 0 || state.activeRowIndex === null) {@@ -168,7 +156,7 @@ export class WorkPackageViewSelectionService implements OnDestroy {});}- this.selectionState.putValue(state);+ this.update(state);}public registerSelectAllListener(renderedElements:() => RenderedWorkPackage[]) {@@ -199,4 +187,9 @@ export class WorkPackageViewSelectionService implements OnDestroy {activeRowIndex: null};}++ valueFromQuery(query:QueryResource, results:WorkPackageCollectionResource):WorkPackageViewSelectionState|undefined {+ return undefined;+ }}+