Expose ordering criteria in search UI
Offering the user to sort the results according to a chosen field from a dropdown menu. Change-Id: I017285d537b4bb6c152deb1a406fdac97f465262 Story: 2000913 Task: 22137
This commit is contained in:
parent
fd8e560f95
commit
cb1c87f089
|
@ -131,6 +131,138 @@ angular.module('sb.search').directive('searchResults',
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allowing sorting stories in search results by certain fields.
|
||||
*/
|
||||
$scope.stories_sort_field = 'Sort Field';
|
||||
$scope.sort_stories_by_field = function(selected){
|
||||
$scope.stories_sort_field = selected.toString();
|
||||
var res = $scope.searchResults;
|
||||
switch(selected) {
|
||||
case 'Title':
|
||||
res.sort(function compare(a, b){
|
||||
if (a.title < b.title){
|
||||
return -1;
|
||||
}
|
||||
if (a.title > b.title){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
break;
|
||||
case 'Tags':
|
||||
res.sort(function compare(a, b){
|
||||
if (a.tags < b.tags){
|
||||
return -1;
|
||||
}
|
||||
if (a.tags > b.tags){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
break;
|
||||
case 'Status':
|
||||
res.sort(function compare(a, b){
|
||||
if (a.status < b.status){
|
||||
return -1;
|
||||
}
|
||||
if (a.status > b.status){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
break;
|
||||
case 'Updated':
|
||||
res.sort(function compare(a, b){
|
||||
if (a.updated_at < b.updated_at){
|
||||
return -1;
|
||||
}
|
||||
if (a.updated_at > b.updated_at){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Allowing sorting tasks in search results by certain fields.
|
||||
*/
|
||||
$scope.tasks_sort_field = 'Sort Field';
|
||||
$scope.sort_tasks_by_field = function(selected){
|
||||
$scope.tasks_sort_field = selected.toString();
|
||||
var res = $scope.searchResults;
|
||||
switch(selected) {
|
||||
case 'Story':
|
||||
res.sort(function compare(a, b){
|
||||
if (a.story_id < b.story_id){
|
||||
return -1;
|
||||
}
|
||||
if (a.story_id > b.story_id){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
break;
|
||||
case 'Status':
|
||||
res.sort(function compare(a, b){
|
||||
if (a.status < b.status){
|
||||
return -1;
|
||||
}
|
||||
if (a.status > b.status){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
break;
|
||||
case 'Title':
|
||||
res.sort(function compare(a, b){
|
||||
if (a.title < b.title){
|
||||
return -1;
|
||||
}
|
||||
if (a.title > b.title){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
break;
|
||||
case 'Project':
|
||||
res.sort(function compare(a, b){
|
||||
if (a.project_id < b.project_id){
|
||||
return -1;
|
||||
}
|
||||
if (a.project_id > b.project_id){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
break;
|
||||
case 'Created at':
|
||||
res.sort(function compare(a, b){
|
||||
if (a.created_at < b.created_at){
|
||||
return -1;
|
||||
}
|
||||
if (a.created_at > b.created_at){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
break;
|
||||
case 'Updated Since':
|
||||
res.sort(function compare(a, b){
|
||||
if (a.updated_at < b.updated_at){
|
||||
return -1;
|
||||
}
|
||||
if (a.updated_at > b.updated_at){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Update the page size preference and re-search.
|
||||
*/
|
||||
|
|
|
@ -120,7 +120,30 @@
|
|||
</div>
|
||||
<div class="col-xs-10" ng-if="hasValidCriteria">
|
||||
<table class="table table-condensed table-striped table-clean">
|
||||
<tbody ng-if="searchResults.length != 0">
|
||||
<tbody ng-show="searchResults.length != 0">
|
||||
<tr ng-show="searchResults.length != 0">
|
||||
<span class="btn-group" dropdown="" ng-show="searchResults.length != 0">
|
||||
<div>
|
||||
<button class="btn btn-xs btn-default" dropdown-toggle="" aria-haspopup="true" aria-expanded="true">
|
||||
<li class="dropdown-header">{{stories_sort_field}}</li>
|
||||
</button>
|
||||
</div>
|
||||
<ul class="dropdown-menu dropdown-menu-left" role="menu">
|
||||
<li ng-click="sort_stories_by_field('Title')">
|
||||
<a>Title</a>
|
||||
</li>
|
||||
<li ng-click="sort_stories_by_field('Tags')">
|
||||
<a>Tags</a>
|
||||
</li>
|
||||
<li ng-click="sort_stories_by_field('Status')">
|
||||
<a>Status</a>
|
||||
</li>
|
||||
<li ng-click="sort_stories_by_field('Updated')">
|
||||
<a>Updated Since</a>
|
||||
</li>
|
||||
</ul>
|
||||
</span>
|
||||
</tr>
|
||||
<tr ng-repeat="story in searchResults"
|
||||
ng-include="'app/search/template/story_search_item.html'">
|
||||
</tr>
|
||||
|
@ -166,6 +189,35 @@
|
|||
<div class="col-xs-10" ng-if="hasValidCriteria">
|
||||
<table class="table table-condensed table-striped table-clean">
|
||||
<tbody ng-if="searchResults.length != 0">
|
||||
<tr ng-show="searchResults.length != 0">
|
||||
<span class="btn-group" dropdown="" ng-show="searchResults.length != 0">
|
||||
<div>
|
||||
<button class="btn btn-xs btn-default" dropdown-toggle="" aria-haspopup="true" aria-expanded="true">
|
||||
<li class="dropdown-header">{{tasks_sort_field}}</li>
|
||||
</button>
|
||||
</div>
|
||||
<ul class="dropdown-menu dropdown-menu-left" role="menu">
|
||||
<li ng-click="sort_tasks_by_field('Story')">
|
||||
<a>Story</a>
|
||||
</li>
|
||||
<li ng-click="sort_tasks_by_field('Title')">
|
||||
<a>Title</a>
|
||||
</li>
|
||||
<li ng-click="sort_tasks_by_field('Status')">
|
||||
<a>Status</a>
|
||||
</li>
|
||||
<li ng-click="sort_tasks_by_field('Project')">
|
||||
<a>Project</a>
|
||||
</li>
|
||||
<li ng-click="sort_tasks_by_field('Created at')">
|
||||
<a>Created at</a>
|
||||
</li>
|
||||
<li ng-click="sort_tasks_by_field('Updated Since')">
|
||||
<a>Updated Since</a>
|
||||
</li>
|
||||
</ul>
|
||||
</span>
|
||||
</tr>
|
||||
<tr ng-repeat="task in searchResults"
|
||||
ng-include="'app/search/template/task_search_item.html'">
|
||||
</tr>
|
||||
|
|
Loading…
Reference in New Issue