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"
$scope.resourceTypes = ['ProjectGroup'];
// Projects have no default criteria
$scope.defaultCriteria = [];
var params = $location.search();
SearchHelper.parseParameters(params, $scope.defaultCriteria);
$scope.defaultCriteria = SearchHelper.parseParameters(params);
/**
* Create a new project-group.

View File

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

View File

@ -26,7 +26,8 @@ angular.module('sb.search').controller('SearchController',
*
* @type {Array}
*/
$scope.defaultCriteria = [];
var params = $location.search();
$scope.defaultCriteria = SearchHelper.parseParameters(params);
/**
* 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',
'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) {
resourceTypes = types || $scope.resourceTypes || resourceTypes;
$scope.criteria = defaultCriteria || [];
if (!!defaultCriteria) {
defaultCriteria.then(function(criteria) {
$scope.criteria = criteria;
});
} else {
$scope.criteria = [];
}
$scope.searchForCriteria =
Criteria.buildCriteriaSearch(resourceTypes, 5);
};

View File

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

View File

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