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