Merge "Make it possible to link to a search/browse for stories"

This commit is contained in:
Jenkins 2016-12-22 19:17:39 +00:00 committed by Gerrit Code Review
commit 7494348519
4 changed files with 74 additions and 6 deletions

View File

@ -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();
};
/**

View File

@ -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.

View File

@ -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: '<div ui-view></div>'
})
.state('sb.story.list', {
url: '/list',
url: '/list?' + queryParams,
params: {
'status': 'active'
},
templateUrl: 'app/stories/template/list.html',
controller: 'StoryListController'
})

View File

@ -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">
</div>
<span class="form-control-feedback text-muted">