Now handling multiple instances of the same query param with different values

This commit is contained in:
Michael Abashian 2017-01-10 16:53:35 -05:00
parent d589dceaa2
commit a36981dcb9
2 changed files with 19 additions and 6 deletions

View File

@ -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, "");

View File

@ -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);
}
}