Make the Tags resource look for existing tags to filter by

This commit causes the search bars to suggest existing tags based on
what the user types, rather than just suggesting they try to filter
by tags matching exactly what they've typed.

Change-Id: Ibf9809f270616f495efd255ba253d8d741ba423a
Depends-on: If13b29d050abd66428c6787121d6b61b357bc9fb
This commit is contained in:
Adam Coldrick 2016-06-17 11:32:51 +01:00
parent b61fbb908b
commit 4540658a00
2 changed files with 24 additions and 14 deletions

View File

@ -18,22 +18,26 @@
/**
* This criteria resolver may be injected by individual resources that accept a
* Tags search parameter.
*
* @see ResourceFactory
*/
angular.module('sb.services').factory('Tags',
function (Criteria, $q) {
function (ResourceFactory) {
'use strict';
/**
* Return a Tags search parameter constructed from the passed search
* string.
*/
var resource = ResourceFactory.build(
'/tags/:id',
'/tags/search',
{id: '@id'}
);
return {
criteriaResolver: function (searchString) {
var deferred = $q.defer();
deferred.resolve([Criteria.create('Tags', searchString)]);
ResourceFactory.applySearch(
'Tags',
resource,
'name',
{},
true // Use the name field for browse criteria, instead of the ID
);
return deferred.promise;
}
};
return resource;
});

View File

@ -113,7 +113,7 @@ angular.module('sb.services')
* @param searchParameters The search parameters to apply.
*/
applySearch: function (resourceName, resource, nameField,
searchParameters) {
searchParameters, useNameField) {
// List of criteria resolvers which we're building.
var criteriaResolvers = [];
@ -162,7 +162,13 @@ angular.module('sb.services')
// Transform the results to criteria tags.
var criteriaResults = [];
result.forEach(function (item) {
if (item.hasOwnProperty('id')) {
if (useNameField) {
criteriaResults.push(
Criteria.create(resourceName,
item[nameField],
item[nameField])
);
} else if (item.hasOwnProperty('id')) {
criteriaResults.push(
Criteria.create(resourceName,
item.id,