Skip to content

Commit

Permalink
Maintain saved search or collection state even when navigating away (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
rjmackay authored Aug 22, 2017
1 parent bb11c4a commit de5673f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 6 deletions.
4 changes: 1 addition & 3 deletions app/common/common-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: ''
Expand All @@ -30,5 +27,6 @@ module.exports = ['$routeProvider', '$locationProvider', function ($routeProvide
controller: require('./auth/password-reset-confirm.controller.js'),
template: ''
})
.otherwise('/')
;
}];
9 changes: 7 additions & 2 deletions app/common/directives/mode-bar/mode-bar.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -80,20 +81,24 @@ 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) {
$scope.baseUrl = 'savedsearches/' + savedsearch.id + '/';
}

function handleSavedSearchClose(ev, savedsearch) {
$scope.baseUrl = 'views/';
//$scope.baseUrl = 'views/';
}
}
};
Expand Down
14 changes: 14 additions & 0 deletions app/main/posts/posts-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
8 changes: 8 additions & 0 deletions app/main/posts/savedsearches/mode-context.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ <h1 class="mode-context-title">
<!--// END IF //-->
</div>
<!--// END IF //-->
<div class="form-field">
<a ng-href="/views/{{collection.view}}" type="button" class="button-link">
<svg class="iconic">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/img/iconic-sprite.svg#arrow-left"></use>
</svg>
<span class="button-label" translate="app.return_to_all_posts">Return to all posts</span>
</a>
</div>

<mode-context-form-filter></mode-context-form-filter>

Expand Down
7 changes: 6 additions & 1 deletion app/main/posts/views/post-filters.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ function PostFiltersService(_, FormEndpoint, TagEndpoint, $q) {
hasFilters: hasFilters,
getActiveFilters: getActiveFilters,
setMode: setMode,
getMode: getMode
getMode: getMode,
getModeId: getModeId
};

function activate() {
Expand Down Expand Up @@ -155,6 +156,10 @@ function PostFiltersService(_, FormEndpoint, TagEndpoint, $q) {
function getMode() {
return filterMode;
}

function getModeId() {
return entityId;
}
}

// clearSelected: function () {
Expand Down
5 changes: 5 additions & 0 deletions app/main/posts/views/post-views.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
}

0 comments on commit de5673f

Please sign in to comment.