From 32c702e3d44c7eea5af08064415ba63c4bd20f21 Mon Sep 17 00:00:00 2001 From: Adam Coldrick Date: Tue, 25 Oct 2016 21:29:05 +0000 Subject: [PATCH] Make it possible to link to a search/browse for stories This commit makes it so that the story list view adds the currently selected filter parameters to the URL. It also makes the starting criteria be set based on the query string of the URL, which allows one to share a link to a search/browse. Change-Id: I83661de0ae2a3b773abc3bf74e6627d8d601e34d --- .../controller/search_criteria_controller.js | 16 +++++- .../controller/story_list_controller.js | 55 +++++++++++++++++-- src/app/stories/module.js | 8 ++- src/app/stories/template/list.html | 1 + 4 files changed, 74 insertions(+), 6 deletions(-) diff --git a/src/app/search/controller/search_criteria_controller.js b/src/app/search/controller/search_criteria_controller.js index 074373ca..b23ad92c 100644 --- a/src/app/search/controller/search_criteria_controller.js +++ b/src/app/search/controller/search_criteria_controller.js @@ -21,7 +21,7 @@ * may be property filters (title = foo) or resource filters (story_id = 22). */ angular.module('sb.search').controller('SearchCriteriaController', - function ($log, $q, $scope, Criteria) { + function ($log, $q, $scope, $location, $injector, Criteria) { 'use strict'; /** @@ -55,6 +55,18 @@ angular.module('sb.search').controller('SearchCriteriaController', $scope.init(); }); + $scope.rewriteQueryString = function() { + var params = {}; + angular.forEach(resourceTypes, function(resourceName) { + var resource = $injector.get(resourceName); + angular.forEach($scope.criteria, function() { + var criteriaMap = resource.criteriaMap($scope.criteria); + angular.extend(params, criteriaMap); + }); + }); + $location.search(params); + }; + /** * When a criteria is added, make sure we remove all previous criteria * that have the same type. @@ -72,6 +84,7 @@ angular.module('sb.search').controller('SearchCriteriaController', $scope.criteria.splice(i, 1); } } + $scope.rewriteQueryString(); }; /** @@ -82,6 +95,7 @@ angular.module('sb.search').controller('SearchCriteriaController', if (idx > -1) { $scope.criteria.splice(idx, 1); } + $scope.rewriteQueryString(); }; /** diff --git a/src/app/stories/controller/story_list_controller.js b/src/app/stories/controller/story_list_controller.js index c8c947b0..cd7a8ba5 100644 --- a/src/app/stories/controller/story_list_controller.js +++ b/src/app/stories/controller/story_list_controller.js @@ -19,16 +19,63 @@ */ angular.module('sb.story').controller('StoryListController', function ($scope, $state, Criteria, NewStoryService, - SubscriptionList, CurrentUser) { + SubscriptionList, CurrentUser, $stateParams, $filter, $q, + Tags, User, Project, ProjectGroup) { 'use strict'; // search results must be of type "story" $scope.resourceTypes = ['Story']; // Search result criteria default must be "active" - $scope.defaultCriteria = [ - Criteria.create('StoryStatus', 'active', 'Active') - ]; + $scope.defaultCriteria = []; + + if ($stateParams.q) { + $scope.defaultCriteria.push( + Criteria.create('Text', $stateParams.q) + ); + } + if ($stateParams.status) { + $scope.defaultCriteria.push( + Criteria.create('StoryStatus', $stateParams.status, + $filter('capitalize')($stateParams.status)) + ); + } + if ($stateParams.tags) { + $scope.defaultCriteria.push( + Criteria.create('Tags', $stateParams.tags, $stateParams.tags) + ); + } + if ($stateParams.assignee_id) { + User.get({'id': $stateParams.assignee_id}).$promise + .then(function(result) { + $scope.defaultCriteria.push( + Criteria.create('User', $stateParams.assignee_id, + result.full_name) + ); + } + ); + } + if ($stateParams.project_id) { + Project.get({'id': $stateParams.project_id}).$promise + .then(function(result) { + $scope.defaultCriteria.push( + Criteria.create('Project', $stateParams.project_id, + result.name) + ); + } + ); + } + if ($stateParams.project_group_id) { + ProjectGroup.get({'id': $stateParams.project_group_id}).$promise + .then(function(result) { + $scope.defaultCriteria.push( + Criteria.create('ProjectGroup', + $stateParams.project_group_id, + result.title) + ); + } + ); + } /** * Creates a new story. diff --git a/src/app/stories/module.js b/src/app/stories/module.js index 00895369..b7a7d045 100644 --- a/src/app/stories/module.js +++ b/src/app/stories/module.js @@ -27,6 +27,9 @@ angular.module('sb.story', ['ui.router', 'sb.services', 'sb.util', // URL Defaults. $urlRouterProvider.when('/story', '/story/list'); + var queryParams = 'q&status&tags&project_group_id&' + + 'project_id&assignee_id'; + // Set our page routes. $stateProvider .state('sb.story', { @@ -35,7 +38,10 @@ angular.module('sb.story', ['ui.router', 'sb.services', 'sb.util', template: '
' }) .state('sb.story.list', { - url: '/list', + url: '/list?' + queryParams, + params: { + 'status': 'active' + }, templateUrl: 'app/stories/template/list.html', controller: 'StoryListController' }) diff --git a/src/app/stories/template/list.html b/src/app/stories/template/list.html index 6c18d965..9b3ca82d 100644 --- a/src/app/stories/template/list.html +++ b/src/app/stories/template/list.html @@ -46,6 +46,7 @@ tag-complete-tag-template-url="'app/search/template/criteria_tag_item.html'" tag-complete-loading="loadingCriteria = isLoading" tag-complete-on-select="addCriteria(tag)" + tag-remove-callback="rewriteQueryString()" placeholder="Search Stories">