From f58b18aaacecb3e6bc5cc95f96ee7ae84af8e8a0 Mon Sep 17 00:00:00 2001 From: Till Breuer Date: Thu, 10 Jul 2014 18:17:57 +0200 Subject: [PATCH] Remember latest tab when toggling the details pane --- app/assets/javascripts/angular/routing.js | 16 +++++++++++++++- .../work-package-details-controller.js | 7 ++++++- .../controllers/work-packages-list-controller.js | 8 +++++++- .../work-package-details-controller-test.js | 1 + .../work-packages-list-controller-test.js | 3 ++- public/templates/work_packages.list.html | 2 +- 6 files changed, 32 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/angular/routing.js b/app/assets/javascripts/angular/routing.js index 9865919e91..0c2484ad0d 100644 --- a/app/assets/javascripts/angular/routing.js +++ b/app/assets/javascripts/angular/routing.js @@ -38,7 +38,21 @@ angular.module('openproject') url: '{projectPath:.*}/work_packages?query_id', abstract: true, templateUrl: "/templates/work_packages.html", - controller: 'WorkPackagesController' + controller: 'WorkPackagesController', + resolve: { + latestTab: function($state) { + var stateName = 'work-packages.list.details.overview'; // the default tab + + return { + getStateName: function() { + return stateName; + }, + registerState: function() { + stateName = $state.current.name; + } + }; + } + } }) .state('work-packages.list', { url: "", diff --git a/app/assets/javascripts/angular/work_packages/controllers/work-package-details-controller.js b/app/assets/javascripts/angular/work_packages/controllers/work-package-details-controller.js index fea78e235f..314ee3f047 100644 --- a/app/assets/javascripts/angular/work_packages/controllers/work-package-details-controller.js +++ b/app/assets/javascripts/angular/work_packages/controllers/work-package-details-controller.js @@ -37,6 +37,7 @@ angular.module('openproject.workPackages.controllers') .controller('WorkPackageDetailsController', [ '$scope', + 'latestTab', 'workPackage', 'I18n', 'DEFAULT_WORK_PACKAGE_PROPERTIES', @@ -46,7 +47,11 @@ angular.module('openproject.workPackages.controllers') 'UserService', '$q', 'ConfigurationService', - function($scope, workPackage, I18n, DEFAULT_WORK_PACKAGE_PROPERTIES, USER_TYPE, WorkPackagesHelper, PathHelper, UserService, $q, ConfigurationService) { + function($scope, latestTab, workPackage, I18n, DEFAULT_WORK_PACKAGE_PROPERTIES, USER_TYPE, WorkPackagesHelper, PathHelper, UserService, $q, ConfigurationService) { + + $scope.$on('$stateChangeSuccess', function(event, toState){ + latestTab.registerState(toState.name); + }); // initialization $scope.I18n = I18n; diff --git a/app/assets/javascripts/angular/work_packages/controllers/work-packages-list-controller.js b/app/assets/javascripts/angular/work_packages/controllers/work-packages-list-controller.js index 374bec169b..5066ee742f 100644 --- a/app/assets/javascripts/angular/work_packages/controllers/work-packages-list-controller.js +++ b/app/assets/javascripts/angular/work_packages/controllers/work-packages-list-controller.js @@ -35,6 +35,7 @@ angular.module('openproject.workPackages.controllers') '$location', '$stateParams', '$state', + 'latestTab', 'I18n', 'WorkPackagesTableService', 'WorkPackageService', @@ -46,7 +47,7 @@ angular.module('openproject.workPackages.controllers') 'HALAPIResource', 'INITIALLY_SELECTED_COLUMNS', 'OPERATORS_AND_LABELS_BY_FILTER_TYPE', - function($scope, $rootScope, $q, $location, $stateParams, $state, + function($scope, $rootScope, $q, $location, $stateParams, $state, latestTab, I18n, WorkPackagesTableService, WorkPackageService, ProjectService, QueryService, PaginationService, AuthorisationService, WorkPackageLoadingHelper, HALAPIResource, INITIALLY_SELECTED_COLUMNS, @@ -206,4 +207,9 @@ angular.module('openproject.workPackages.controllers') $scope.$watch(QueryService.getQueryName, function(queryName){ $scope.selectedTitle = queryName || I18n.t('js.toolbar.unselected_title'); }); + + $scope.openLatestTab = function() { + $state.go(latestTab.getStateName(), { workPackageId: $scope.preselectedWorkPackageId }); + }; + }]); diff --git a/karma/tests/controllers/work-package-details-controller-test.js b/karma/tests/controllers/work-package-details-controller-test.js index 63c3a5d703..a8f7cd73b1 100644 --- a/karma/tests/controllers/work-package-details-controller-test.js +++ b/karma/tests/controllers/work-package-details-controller-test.js @@ -60,6 +60,7 @@ describe('WorkPackageDetailsController', function() { ctrl = $controller("WorkPackageDetailsController", { $scope: scope, $stateParams: { workPackageId: workPackageId }, + latestTab: {}, I18n: I18n, ConfigurationService: { commentsSortedInDescendingOrder: function() { diff --git a/karma/tests/controllers/work-packages-list-controller-test.js b/karma/tests/controllers/work-packages-list-controller-test.js index 9772996144..91f5e309db 100644 --- a/karma/tests/controllers/work-packages-list-controller-test.js +++ b/karma/tests/controllers/work-packages-list-controller-test.js @@ -137,7 +137,8 @@ describe('WorkPackagesListController', function() { PaginationService: testPaginationService, WorkPackageService: testWorkPackageService, $stateParams: testParams, - $state: testState + $state: testState, + latestTab: {} }); }; diff --git a/public/templates/work_packages.list.html b/public/templates/work_packages.list.html index 7909d71d3d..507e6ed0de 100644 --- a/public/templates/work_packages.list.html +++ b/public/templates/work_packages.list.html @@ -35,7 +35,7 @@