Merge "Fix race when browsing stories by certain fields"

This commit is contained in:
Zuul 2018-05-17 23:12:33 +00:00 committed by Gerrit Code Review
commit e7b10dbb39
6 changed files with 48 additions and 31 deletions

View File

@ -25,11 +25,8 @@ angular.module('sb.project_group').controller('ProjectGroupListController',
// search results must be of type "ProjectGroup" // search results must be of type "ProjectGroup"
$scope.resourceTypes = ['ProjectGroup']; $scope.resourceTypes = ['ProjectGroup'];
// Projects have no default criteria
$scope.defaultCriteria = [];
var params = $location.search(); var params = $location.search();
SearchHelper.parseParameters(params, $scope.defaultCriteria); $scope.defaultCriteria = SearchHelper.parseParameters(params);
/** /**
* Create a new project-group. * Create a new project-group.

View File

@ -30,11 +30,8 @@ angular.module('sb.projects').controller('ProjectListController',
// search results must be of type "project" // search results must be of type "project"
$scope.resourceTypes = ['Project']; $scope.resourceTypes = ['Project'];
// Projects have no default criteria
$scope.defaultCriteria = [];
var params = $location.search(); var params = $location.search();
SearchHelper.parseParameters(params, $scope.defaultCriteria); $scope.defaultCriteria = SearchHelper.parseParameters(params);
/** /**
* Launches the add-project modal. * Launches the add-project modal.

View File

@ -26,7 +26,8 @@ angular.module('sb.search').controller('SearchController',
* *
* @type {Array} * @type {Array}
*/ */
$scope.defaultCriteria = []; var params = $location.search();
$scope.defaultCriteria = SearchHelper.parseParameters(params);
/** /**
* List of resource types which this view will be searching on. * List of resource types which this view will be searching on.
@ -35,11 +36,5 @@ angular.module('sb.search').controller('SearchController',
*/ */
$scope.resourceTypes = ['TaskStatus', 'Story', 'Project', 'User', $scope.resourceTypes = ['TaskStatus', 'Story', 'Project', 'User',
'Task', 'ProjectGroup', 'Board', 'Worklist']; 'Task', 'ProjectGroup', 'Board', 'Worklist'];
/**
* If a 'q' exists in the state params, go ahead and add it.
*/
var params = $location.search();
SearchHelper.parseParameters(params, $scope.defaultCriteria);
} }
); );

View File

@ -46,7 +46,13 @@ angular.module('sb.search').controller('SearchCriteriaController',
*/ */
$scope.init = function (types, defaultCriteria) { $scope.init = function (types, defaultCriteria) {
resourceTypes = types || $scope.resourceTypes || resourceTypes; resourceTypes = types || $scope.resourceTypes || resourceTypes;
$scope.criteria = defaultCriteria || []; if (!!defaultCriteria) {
defaultCriteria.then(function(criteria) {
$scope.criteria = criteria;
});
} else {
$scope.criteria = [];
}
$scope.searchForCriteria = $scope.searchForCriteria =
Criteria.buildCriteriaSearch(resourceTypes, 5); Criteria.buildCriteriaSearch(resourceTypes, 5);
}; };

View File

@ -19,13 +19,16 @@
* A service providing helper functions for search views. * A service providing helper functions for search views.
*/ */
angular.module('sb.search').factory('SearchHelper', angular.module('sb.search').factory('SearchHelper',
function(User, Project, ProjectGroup, Story, Task, Criteria, $filter) { function(User, Project, ProjectGroup, Story, Task, Criteria,
$filter, $q) {
'use strict'; 'use strict';
/** /**
* Create search criteria based on some given parameters. * Create search criteria based on some given parameters.
*/ */
function parseParameters(params, criteria) { function parseParameters(params) {
var criteria = [];
var promises = [];
if (params.q) { if (params.q) {
criteria.push( criteria.push(
Criteria.create('Text', params.q) Criteria.create('Text', params.q)
@ -57,8 +60,10 @@ angular.module('sb.search').factory('SearchHelper',
} }
if (params.assignee_id || params.creator_id) { if (params.assignee_id || params.creator_id) {
var id = params.assignee_id || params.creator_id; var id = params.assignee_id || params.creator_id;
User.get({'id': id}).$promise var userPromise = User.get({'id': id}).$promise;
.then(function(result) { promises.push(userPromise);
userPromise.then(function(result) {
criteria.push( criteria.push(
Criteria.create('User', Criteria.create('User',
params.assignee_id, params.assignee_id,
@ -68,8 +73,11 @@ angular.module('sb.search').factory('SearchHelper',
); );
} }
if (params.project_id) { if (params.project_id) {
Project.get({'id': params.project_id}).$promise var projectParams = {'id': params.project_id};
.then(function(result) { var projectPromise = Project.get(projectParams).$promise;
promises.push(projectPromise);
projectPromise.then(function(result) {
criteria.push( criteria.push(
Criteria.create('Project', Criteria.create('Project',
params.project_id, params.project_id,
@ -79,8 +87,11 @@ angular.module('sb.search').factory('SearchHelper',
); );
} }
if (params.project_group_id) { if (params.project_group_id) {
ProjectGroup.get({'id': params.project_group_id}).$promise var groupParams = {'id': params.project_group_id};
.then(function(result) { var groupPromise = ProjectGroup.get(groupParams).$promise;
promises.push(groupPromise);
groupPromise.then(function(result) {
criteria.push( criteria.push(
Criteria.create('ProjectGroup', Criteria.create('ProjectGroup',
params.project_group_id, params.project_group_id,
@ -90,8 +101,11 @@ angular.module('sb.search').factory('SearchHelper',
); );
} }
if (params.story_id) { if (params.story_id) {
Story.get({'id': params.story_id}).$promise var storyParams = {'id': params.story_id};
.then(function(result) { var storyPromise = Story.get(storyParams).$promise;
promises.push(storyPromise);
storyPromise.then(function(result) {
criteria.push( criteria.push(
Criteria.create('Story', Criteria.create('Story',
params.story_id, params.story_id,
@ -101,8 +115,11 @@ angular.module('sb.search').factory('SearchHelper',
); );
} }
if (params.task_id) { if (params.task_id) {
Task.get({'id': params.task_id}).$promise var taskParams = {'id': params.task_id};
.then(function(result) { var taskPromise = Task.get(taskParams).$promise;
promises.push(taskPromise);
taskPromise.then(function(result) {
criteria.push( criteria.push(
Criteria.create('Task', Criteria.create('Task',
params.task_id, params.task_id,
@ -111,6 +128,13 @@ angular.module('sb.search').factory('SearchHelper',
} }
); );
} }
var deferred = $q.defer();
$q.all(promises).then(function() {
deferred.resolve(criteria);
});
return deferred.promise;
} }
return { return {

View File

@ -27,9 +27,7 @@ angular.module('sb.story').controller('StoryListController',
$scope.resourceTypes = ['Story']; $scope.resourceTypes = ['Story'];
// Search result criteria default must be "active" // Search result criteria default must be "active"
$scope.defaultCriteria = []; $scope.defaultCriteria = SearchHelper.parseParameters($stateParams);
SearchHelper.parseParameters($stateParams, $scope.defaultCriteria);
/** /**
* Creates a new story. * Creates a new story.