From a36981dcb98705fc9a8db21567b5224caba0a08a Mon Sep 17 00:00:00 2001 From: Michael Abashian Date: Tue, 10 Jan 2017 16:53:35 -0500 Subject: [PATCH] Now handling multiple instances of the same query param with different values --- .../shared/smart-search/queryset.service.js | 6 ++++-- .../smart-search/smart-search.controller.js | 19 +++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/awx/ui/client/src/shared/smart-search/queryset.service.js b/awx/ui/client/src/shared/smart-search/queryset.service.js index ec18f1b0d1..89ad2f14d1 100644 --- a/awx/ui/client/src/shared/smart-search/queryset.service.js +++ b/awx/ui/client/src/shared/smart-search/queryset.service.js @@ -69,10 +69,12 @@ export default ['$q', 'Rest', 'ProcessErrors', '$rootScope', 'Wait', 'DjangoSear function encodeTerm(value, key){ if (Array.isArray(value)){ - return _.map(value, function(item){ + let concated = ''; + angular.forEach(value, function(item){ item = item.replace(/"|'/g, ""); - return `${key}=${item}`.join('&') + '&'; + concated += `${key}=${item}&`; }); + return concated; } else { value = value.replace(/"|'/g, ""); diff --git a/awx/ui/client/src/shared/smart-search/smart-search.controller.js b/awx/ui/client/src/shared/smart-search/smart-search.controller.js index 7b09def616..2da9648ca1 100644 --- a/awx/ui/client/src/shared/smart-search/smart-search.controller.js +++ b/awx/ui/client/src/shared/smart-search/smart-search.controller.js @@ -120,23 +120,34 @@ export default ['$stateParams', '$scope', '$state', 'QuerySet', 'GetBasePath', ' let termParts = SmartSearchService.splitTermIntoParts(term); + function combineSameSearches(a,b){ + if (_.isArray(a)) { + return a.concat(b); + } + else { + if(a) { + return [a,b]; + } + } + } + // if only a value is provided, search using default keys if (termParts.length === 1) { - params = _.merge(params, setDefaults(term)); + params = _.merge(params, setDefaults(term), combineSameSearches); } else { // Figure out if this is a search term let root = termParts[0].split(".")[0].replace(/^-/, ''); if(_.has($scope.options.actions.GET, root)) { if($scope.options.actions.GET[root].type && $scope.options.actions.GET[root].type === 'field') { - params = _.merge(params, qs.encodeParam({term: term, relatedSearchTerm: true})); + params = _.merge(params, qs.encodeParam({term: term, relatedSearchTerm: true}), combineSameSearches); } else { - params = _.merge(params, qs.encodeParam({term: term, searchTerm: true})); + params = _.merge(params, qs.encodeParam({term: term, searchTerm: true}), combineSameSearches); } } // Its not a search term or a related search term else { - params = _.merge(params, qs.encodeParam({term: term})); + params = _.merge(params, qs.encodeParam({term: term}), combineSameSearches); } }