Prevent duplicate host filter strings

This commit is contained in:
mabashian
2017-08-25 13:27:01 -04:00
parent e1ee95234e
commit 5be6d5bf26
4 changed files with 22 additions and 11 deletions

View File

@@ -54,10 +54,7 @@ function SmartInventoryAdd($scope, $location,
data.variables = ToJSON($scope.parseType, $scope.smartinventory_variables, true); data.variables = ToJSON($scope.parseType, $scope.smartinventory_variables, true);
let decodedHostFilter = decodeURIComponent($scope.smart_hosts.host_filter); data.host_filter = decodeURIComponent($scope.smart_hosts.host_filter);
decodedHostFilter = decodedHostFilter.replace(/__icontains_DEFAULT/g, "__icontains");
decodedHostFilter = decodedHostFilter.replace(/__search_DEFAULT/g, "__search");
data.host_filter = decodedHostFilter;
data.kind = "smart"; data.kind = "smart";

View File

@@ -21,10 +21,7 @@ export default ['$scope', 'QuerySet', 'InventoryHostsStrings',
$.each(searchParam, function(index, param) { $.each(searchParam, function(index, param) {
let paramParts = decodeURIComponent(param).split(/=(.+)/); let paramParts = decodeURIComponent(param).split(/=(.+)/);
paramParts[0] = paramParts[0].replace(/__icontains(_DEFAULT)?/g, ""); $scope.hostFilterTags.push(qs.decodeParam(paramParts[1], paramParts[0]));
paramParts[0] = paramParts[0].replace(/__search(_DEFAULT)?/g, "");
let reconstructedSearchString = qs.decodeParam(paramParts[1], paramParts[0]);
$scope.hostFilterTags.push(reconstructedSearchString);
}); });
$scope.hostFilterTags = $scope.hostFilterTags.concat(qs.stripDefaultParams(hostFilterCopy)); $scope.hostFilterTags = $scope.hostFilterTags.concat(qs.stripDefaultParams(hostFilterCopy));

View File

@@ -80,10 +80,20 @@ export default ['$q', 'Rest', 'ProcessErrors', '$rootScope', 'Wait', 'DjangoSear
let valueString = paramParts[1]; let valueString = paramParts[1];
if(keySplit.length === 1) { if(keySplit.length === 1) {
if(params.searchTerm && !lessThanGreaterThan) { if(params.searchTerm && !lessThanGreaterThan) {
paramString += keySplit[0] + '__icontains_DEFAULT'; if(params.singleSearchParam) {
paramString += keySplit[0] + '__icontains';
}
else {
paramString += keySplit[0] + '__icontains_DEFAULT';
}
} }
else if(params.relatedSearchTerm) { else if(params.relatedSearchTerm) {
paramString += keySplit[0] + '__search_DEFAULT'; if(params.singleSearchParam) {
paramString += keySplit[0] + '__search';
}
else {
paramString += keySplit[0] + '__search_DEFAULT';
}
} }
else { else {
paramString += keySplit[0]; paramString += keySplit[0];

View File

@@ -236,7 +236,14 @@ export default ['$stateParams', '$scope', '$state', 'GetBasePath', 'QuerySet', '
return sourceValue; return sourceValue;
} }
else { else {
return object[key] + "%20and%20" + sourceValue; let singleSearchParamKeys = object[key].split("%20and%20");
if(_.includes(singleSearchParamKeys, sourceValue)) {
return object[key];
}
else {
return object[key] + "%20and%20" + sourceValue;
}
} }
} }
// Start the array of keys // Start the array of keys