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
[31093] Save query after switching to manual sort
Oliver Günther3ab46b65d7eb
diff --git a/frontend/src/app/components/wp-fast-table/handlers/state/drag-and-drop-transformer.ts b/frontend/src/app/components/wp-fast-table/handlers/state/drag-and-drop-transformer.tsindex 33b8ee72143..7f3b2b83784 100644--- a/frontend/src/app/components/wp-fast-table/handlers/state/drag-and-drop-transformer.ts+++ b/frontend/src/app/components/wp-fast-table/handlers/state/drag-and-drop-transformer.ts@@ -15,6 +15,8 @@ import {WorkPackageViewOrderService} from "core-app/modules/work_packages/routinimport {RenderedWorkPackage} from "core-app/modules/work_packages/render-info/rendered-work-package.type";import {BrowserDetector} from "core-app/modules/common/browser/browser-detector.service";import {WorkPackageCacheService} from "core-components/work-packages/work-package-cache.service";+import {WorkPackagesListService} from "core-components/wp-list/wp-list.service";+import {AuthorisationService} from "core-app/modules/common/model-auth/model-auth.service";export class DragAndDropTransformer {@@ -27,6 +29,7 @@ export class DragAndDropTransformer {private readonly wpTableOrder = this.injector.get(WorkPackageViewOrderService);private readonly browserDetector = this.injector.get(BrowserDetector);private readonly wpCacheService = this.injector.get(WorkPackageCacheService);+ private readonly wpListService = this.injector.get(WorkPackagesListService);private readonly dragActionRegistry = this.injector.get(TableDragActionsRegistryService);@@ -75,7 +78,12 @@ export class DragAndDropTransformer {await this.actionService.handleDrop(workPackage, el);this.updateRenderedOrder(newOrder);this.actionService.onNewOrder(newOrder);- this.wpTableSortBy.switchToManualSorting();++ // Save the query when switching to manual+ let query = this.querySpace.query.value;+ if (query && this.wpTableSortBy.switchToManualSorting(query)) {+ await this.wpListService.save(query);+ }} catch (e) {this.wpNotifications.handleRawError(e);diff --git a/frontend/src/app/components/wp-grid/wp-grid.component.ts b/frontend/src/app/components/wp-grid/wp-grid.component.tsindex bc4d4a84ccb..5c344a45d69 100644--- a/frontend/src/app/components/wp-grid/wp-grid.component.ts+++ b/frontend/src/app/components/wp-grid/wp-grid.component.ts@@ -35,6 +35,7 @@ import {HighlightingMode} from "core-components/wp-fast-table/builders/highlightimport {IsolatedQuerySpace} from "core-app/modules/work_packages/query-space/isolated-query-space";import {DragAndDropService} from "core-app/modules/common/drag-and-drop/drag-and-drop.service";import {WorkPackageCardDragAndDropService} from "core-components/wp-card-view/services/wp-card-drag-and-drop.service";+import {WorkPackagesListService} from "core-components/wp-list/wp-list.service";@Component({selector: 'wp-grid',@@ -63,6 +64,7 @@ export class WorkPackagesGridComponent {constructor(readonly wpTableHighlight:WorkPackageViewHighlightingService,readonly wpTableSortBy:WorkPackageViewSortByService,+ readonly wpList:WorkPackagesListService,readonly querySpace:IsolatedQuerySpace,readonly cdRef:ChangeDetectorRef) {}@@ -86,6 +88,9 @@ export class WorkPackagesGridComponent {}public switchToManualSorting() {- this.wpTableSortBy.switchToManualSorting();+ let query = this.querySpace.query.value;+ if (query && this.wpTableSortBy.switchToManualSorting(query)) {+ this.wpList.save(query);+ }}}diff --git a/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-sort-by.service.ts b/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-sort-by.service.tsindex eb91864cc00..dc5ad7eb12e 100644--- a/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-sort-by.service.ts+++ b/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-sort-by.service.ts@@ -37,6 +37,7 @@ import {Observable} from 'rxjs';import {QuerySortByResource} from 'core-app/modules/hal/resources/query-sort-by-resource';import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";import {QueryColumn} from "core-components/wp-query/query-column";+import {WorkPackagesListService} from "core-components/wp-list/wp-list.service";@Injectable()export class WorkPackageViewSortByService extends WorkPackageQueryStateService<QuerySortByResource[]> {@@ -120,11 +121,21 @@ export class WorkPackageViewSortByService extends WorkPackageQueryStateService<Qreturn this.isManuallySorted(this.current);}- public switchToManualSorting() {+ public switchToManualSorting(query:QueryResource):boolean {let manualSortObject = this.manualSortObject;if (manualSortObject && !this.isManualSortingMode) {- this.update([manualSortObject]);++ if (query && query.persisted) {+ // Save the query if it is persisted+ query.sortBy = [manualSortObject];+ return true;+ } else {+ // Query cannot be saved, just update the props for now+ this.update([manualSortObject]);+ }}++ return false;}public get current():QuerySortByResource[] {diff --git a/spec/features/work_packages/sorting/manual_sorting_spec.rb b/spec/features/work_packages/sorting/manual_sorting_spec.rbindex 0faa2586c2b..e2a75604c44 100644--- a/spec/features/work_packages/sorting/manual_sorting_spec.rb+++ b/spec/features/work_packages/sorting/manual_sorting_spec.rb@@ -228,6 +228,34 @@ describe 'Manual sorting of WP table', type: :feature, js: true doendend+ describe 'with a saved query that is NOT manually sorted' do+ let(:query) do+ FactoryBot.create(:query, user: user, project: project, show_hierarchies: false).tap do |q|+ q.sort_criteria = [[:id, 'asc']]+ q.save!+ end+ end++ it 'can drag and drop and will save the query' do+ wp_table.visit_query query+ wp_table.expect_work_package_order work_package_1, work_package_2, work_package_3, work_package_4++ wp_table.drag_and_drop_work_package from: 1, to: 3++ wp_table.expect_work_package_order work_package_1, work_package_3, work_package_2, work_package_4++ wp_table.expect_and_dismiss_notification message: 'Successful update.'++ retry_block do+ query.reload++ if query.sort_criteria != [['manual_sorting', 'asc']]+ raise "Expected sort_criteria to be updated to manual_sorting, was #{query.sort_criteria.inspect}"+ end+ end+ end+ end+describe 'flat mode' dobefore dowp_table.visit!