Merge pull request #338 from mabashian/7524-duplicate-host-filter

Prevent duplicate host filter strings
This commit is contained in:
Michael Abashian 2017-08-28 15:20:31 -04:00 committed by GitHub
commit 4043ec3bbd
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);
let decodedHostFilter = 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.host_filter = decodeURIComponent($scope.smart_hosts.host_filter);
data.kind = "smart";

View File

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

View File

@ -84,10 +84,20 @@ export default ['$q', 'Rest', 'ProcessErrors', '$rootScope', 'Wait', 'DjangoSear
let valueString = paramParts[1];
if(keySplit.length === 1) {
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) {
paramString += keySplit[0] + '__search_DEFAULT';
if(params.singleSearchParam) {
paramString += keySplit[0] + '__search';
}
else {
paramString += keySplit[0] + '__search_DEFAULT';
}
}
else {
paramString += keySplit[0];

View File

@ -236,7 +236,14 @@ export default ['$stateParams', '$scope', '$state', 'GetBasePath', 'QuerySet', '
return sourceValue;
}
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