From de5673fdd9ad2ed994d04e028109ab52e75e12b0 Mon Sep 17 00:00:00 2001 From: Robbie Mackay Date: Tue, 22 Aug 2017 13:06:59 +1200 Subject: [PATCH] Maintain saved search or collection state even when navigating away (#720) * Maintain saved search or collection state even when navigating away * Make / route redirect based on current mode, not always go to all posts Refs ushahidi/platform#1960 --- app/common/common-routes.js | 4 +--- .../directives/mode-bar/mode-bar.directive.js | 9 +++++++-- app/main/posts/posts-routes.js | 14 ++++++++++++++ app/main/posts/savedsearches/mode-context.html | 8 ++++++++ app/main/posts/views/post-filters.service.js | 7 ++++++- app/main/posts/views/post-views.controller.js | 5 +++++ 6 files changed, 41 insertions(+), 6 deletions(-) diff --git a/app/common/common-routes.js b/app/common/common-routes.js index c885f346a9..0aa0a6f994 100644 --- a/app/common/common-routes.js +++ b/app/common/common-routes.js @@ -3,9 +3,6 @@ module.exports = ['$routeProvider', '$locationProvider', function ($routeProvide $locationProvider.html5Mode(true); $routeProvider - .when('/', { - redirectTo: '/views/map' - }) .when('/login', { controller: require('./auth/login.controller.js'), template: '' @@ -30,5 +27,6 @@ module.exports = ['$routeProvider', '$locationProvider', function ($routeProvide controller: require('./auth/password-reset-confirm.controller.js'), template: '' }) + .otherwise('/') ; }]; diff --git a/app/common/directives/mode-bar/mode-bar.directive.js b/app/common/directives/mode-bar/mode-bar.directive.js index a2bf0336ae..f20f403a37 100644 --- a/app/common/directives/mode-bar/mode-bar.directive.js +++ b/app/common/directives/mode-bar/mode-bar.directive.js @@ -47,6 +47,7 @@ function ( $rootScope.$on('event:collection:close', handleCollectionClose); $rootScope.$on('event:savedsearch:show', handleSavedSearchShow); $rootScope.$on('event:savedsearch:close', handleSavedSearchClose); + $rootScope.$on('event:allposts:show', handleAllShow); Features.loadFeatures().then(function () { $scope.isActivityAvailable = Features.isViewEnabled('activity'); @@ -80,12 +81,16 @@ function ( $scope.activeMode = mode; } + function handleAllShow(ev, collection) { + $scope.baseUrl = 'views/'; + } + function handleCollectionShow(ev, collection) { $scope.baseUrl = 'collections/' + collection.id + '/'; } function handleCollectionClose(ev, savedsearch) { - $scope.baseUrl = 'views/'; + //$scope.baseUrl = 'views/'; } function handleSavedSearchShow(ev, savedsearch) { @@ -93,7 +98,7 @@ function ( } function handleSavedSearchClose(ev, savedsearch) { - $scope.baseUrl = 'views/'; + //$scope.baseUrl = 'views/'; } } }; diff --git a/app/main/posts/posts-routes.js b/app/main/posts/posts-routes.js index 9fe13b5f76..0c3d2d561e 100644 --- a/app/main/posts/posts-routes.js +++ b/app/main/posts/posts-routes.js @@ -5,6 +5,20 @@ function ( ) { $routeProvider + .when('/', { + resolveRedirectTo: ['PostFilters', (PostFilters) => { + let mode = PostFilters.getMode(); + let entityId = PostFilters.getModeId(); + + if (mode === 'collection') { + return '/collections/' + entityId; + } else if (mode === 'savedsearch') { + return '/savedsearches/' + entityId; + } else { + return '/views/map'; + } + }] + }) .when('/views/:view?', { controller: require('./views/post-views.controller.js'), template: require('./views/main.html') diff --git a/app/main/posts/savedsearches/mode-context.html b/app/main/posts/savedsearches/mode-context.html index dc5bb9b732..4ddae89a39 100644 --- a/app/main/posts/savedsearches/mode-context.html +++ b/app/main/posts/savedsearches/mode-context.html @@ -109,6 +109,14 @@

+ diff --git a/app/main/posts/views/post-filters.service.js b/app/main/posts/views/post-filters.service.js index 8b864bc8db..65ab38895b 100644 --- a/app/main/posts/views/post-filters.service.js +++ b/app/main/posts/views/post-filters.service.js @@ -22,7 +22,8 @@ function PostFiltersService(_, FormEndpoint, TagEndpoint, $q) { hasFilters: hasFilters, getActiveFilters: getActiveFilters, setMode: setMode, - getMode: getMode + getMode: getMode, + getModeId: getModeId }; function activate() { @@ -155,6 +156,10 @@ function PostFiltersService(_, FormEndpoint, TagEndpoint, $q) { function getMode() { return filterMode; } + + function getModeId() { + return entityId; + } } // clearSelected: function () { diff --git a/app/main/posts/views/post-views.controller.js b/app/main/posts/views/post-views.controller.js index 657e0b2c73..a2a1873173 100644 --- a/app/main/posts/views/post-views.controller.js +++ b/app/main/posts/views/post-views.controller.js @@ -13,4 +13,9 @@ function PostViewsController($scope, $translate, $routeParams, PostFilters) { PostFilters.setMode('all'); $scope.filters = PostFilters.getFilters(); + + $scope.$emit('event:allposts:show'); + $scope.$on('$destroy', function () { + $scope.$emit('event:allposts:close'); + }); }