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:
parent
b61fbb908b
commit
4540658a00
@ -18,22 +18,26 @@
|
|||||||
/**
|
/**
|
||||||
* This criteria resolver may be injected by individual resources that accept a
|
* This criteria resolver may be injected by individual resources that accept a
|
||||||
* Tags search parameter.
|
* Tags search parameter.
|
||||||
|
*
|
||||||
|
* @see ResourceFactory
|
||||||
*/
|
*/
|
||||||
angular.module('sb.services').factory('Tags',
|
angular.module('sb.services').factory('Tags',
|
||||||
function (Criteria, $q) {
|
function (ResourceFactory) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
var resource = ResourceFactory.build(
|
||||||
* Return a Tags search parameter constructed from the passed search
|
'/tags/:id',
|
||||||
* string.
|
'/tags/search',
|
||||||
*/
|
{id: '@id'}
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
ResourceFactory.applySearch(
|
||||||
criteriaResolver: function (searchString) {
|
'Tags',
|
||||||
var deferred = $q.defer();
|
resource,
|
||||||
deferred.resolve([Criteria.create('Tags', searchString)]);
|
'name',
|
||||||
|
{},
|
||||||
|
true // Use the name field for browse criteria, instead of the ID
|
||||||
|
);
|
||||||
|
|
||||||
return deferred.promise;
|
return resource;
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
});
|
@ -113,7 +113,7 @@ angular.module('sb.services')
|
|||||||
* @param searchParameters The search parameters to apply.
|
* @param searchParameters The search parameters to apply.
|
||||||
*/
|
*/
|
||||||
applySearch: function (resourceName, resource, nameField,
|
applySearch: function (resourceName, resource, nameField,
|
||||||
searchParameters) {
|
searchParameters, useNameField) {
|
||||||
|
|
||||||
// List of criteria resolvers which we're building.
|
// List of criteria resolvers which we're building.
|
||||||
var criteriaResolvers = [];
|
var criteriaResolvers = [];
|
||||||
@ -162,7 +162,13 @@ angular.module('sb.services')
|
|||||||
// Transform the results to criteria tags.
|
// Transform the results to criteria tags.
|
||||||
var criteriaResults = [];
|
var criteriaResults = [];
|
||||||
result.forEach(function (item) {
|
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(
|
criteriaResults.push(
|
||||||
Criteria.create(resourceName,
|
Criteria.create(resourceName,
|
||||||
item.id,
|
item.id,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user