mirror of
https://github.com/ansible/awx.git
synced 2026-01-21 06:28:01 -03:30
First pass implementation of fact searching on hosts
This commit is contained in:
parent
c22e4a5023
commit
e58e593140
@ -10,6 +10,10 @@ export default ['i18n', function(i18n) {
|
||||
iterator: 'host',
|
||||
editTitle: '{{ selected_group }}',
|
||||
searchSize: 'col-lg-12 col-md-12 col-sm-12 col-xs-12',
|
||||
nonstandardSearchParam: {
|
||||
root: 'ansible_facts',
|
||||
param: 'host_filter'
|
||||
},
|
||||
showTitle: false,
|
||||
well: true,
|
||||
index: false,
|
||||
|
||||
@ -198,11 +198,15 @@ export default ['$compile', 'Attr', 'Icon',
|
||||
list.searchSize = 'col-lg-7 col-md-12 col-sm-12 col-xs-12';
|
||||
}
|
||||
if (options.showSearch === undefined || options.showSearch === true) {
|
||||
let nonstandardSearchParam = list.nonstandardSearchParam && list.nonstandardSearchParam.param ? list.nonstandardSearchParam.param : undefined;
|
||||
let nonstandardSearchParamRoot = list.nonstandardSearchParam && list.nonstandardSearchParam.root ? list.nonstandardSearchParam.root : undefined;
|
||||
html += `
|
||||
<div ng-hide="${list.name}.length === 0 && (searchTags | isEmpty)">
|
||||
<smart-search
|
||||
django-model="${list.name}"
|
||||
search-size="${list.searchSize}"
|
||||
nonstandard-search-param="${nonstandardSearchParam}"
|
||||
nonstandard-search-param-root="${nonstandardSearchParamRoot}"
|
||||
base-path="${list.basePath || list.name}"
|
||||
iterator="${list.iterator}"
|
||||
dataset="${list.iterator}_dataset"
|
||||
|
||||
@ -57,6 +57,8 @@ export default ['$q', 'Rest', 'ProcessErrors', '$rootScope', 'Wait', 'DjangoSear
|
||||
|
||||
function encodeTerm(value, key){
|
||||
|
||||
let root = key.split("__")[0].replace(/^-/, '');
|
||||
|
||||
key = key.replace(/__icontains_DEFAULT/g, "__icontains");
|
||||
key = key.replace(/__search_DEFAULT/g, "__search");
|
||||
|
||||
@ -69,13 +71,27 @@ export default ['$q', 'Rest', 'ProcessErrors', '$rootScope', 'Wait', 'DjangoSear
|
||||
}
|
||||
concated += `${key}=${item}&`;
|
||||
});
|
||||
return concated;
|
||||
|
||||
if(root === 'ansible_facts') {
|
||||
return `host_filter=${encodeURIComponent(concated)}&`;
|
||||
}
|
||||
else {
|
||||
return concated;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(value && typeof value === 'string') {
|
||||
value = decodeURIComponent(value).replace(/"|'/g, "");
|
||||
}
|
||||
return `${key}=${value}&`;
|
||||
|
||||
if(root === 'ansible_facts') {
|
||||
let foobar = encodeURIComponent(`${key}=${value}`);
|
||||
return `host_filter=${foobar}&`;
|
||||
}
|
||||
else {
|
||||
return `${key}=${value}&`;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@ -87,13 +87,9 @@ export default ['$stateParams', '$scope', '$state', 'GetBasePath', 'QuerySet', '
|
||||
}
|
||||
|
||||
function setDefaults(term) {
|
||||
if ($scope.list.defaultSearchParams) {
|
||||
return $scope.list.defaultSearchParams(encodeURIComponent(term));
|
||||
} else {
|
||||
return {
|
||||
search: encodeURIComponent(term)
|
||||
};
|
||||
}
|
||||
return {
|
||||
search: encodeURIComponent(term)
|
||||
};
|
||||
}
|
||||
|
||||
$scope.toggleKeyPane = function() {
|
||||
@ -160,6 +156,9 @@ export default ['$stateParams', '$scope', '$state', 'GetBasePath', 'QuerySet', '
|
||||
encodeParams.relatedSearchTerm = true;
|
||||
removed = qs.encodeParam(encodeParams);
|
||||
}
|
||||
else if($scope.nonstandardSearchParam && $scope.nonstandardSearchParamRoot && root === $scope.nonstandardSearchParamRoot) {
|
||||
removed = qs.encodeParam(encodeParams);
|
||||
}
|
||||
else {
|
||||
removed = setDefaults(termParts[termParts.length-1]);
|
||||
}
|
||||
@ -236,6 +235,9 @@ export default ['$stateParams', '$scope', '$state', 'GetBasePath', 'QuerySet', '
|
||||
else if(_.contains($scope.models[$scope.list.name].related, root)) {
|
||||
params = _.merge(params, qs.encodeParam({term: term, relatedSearchTerm: true}), combineSameSearches);
|
||||
}
|
||||
else if($scope.nonstandardSearchParam && $scope.nonstandardSearchParamRoot && root === $scope.nonstandardSearchParamRoot) {
|
||||
params = _.merge(params, qs.encodeParam({term: term, searchTerm: true}), combineSameSearches);
|
||||
}
|
||||
// Its not a search term or a related search term - treat it as a string
|
||||
else {
|
||||
params = _.merge(params, setDefaults(term), combineSameSearches);
|
||||
|
||||
@ -17,7 +17,9 @@ export default ['templateUrl',
|
||||
searchTags: '=',
|
||||
disableSearch: '=',
|
||||
defaultParams: '=',
|
||||
querySet: '='
|
||||
querySet: '=',
|
||||
nonstandardSearchParam: '@',
|
||||
nonstandardSearchParamRoot: '@'
|
||||
},
|
||||
controller: 'SmartSearchController',
|
||||
templateUrl: templateUrl('shared/smart-search/smart-search')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user