mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 01:17:37 -02:30
UI work to incorporate related_search_fields as valid fields when searching
This commit is contained in:
@@ -1,28 +1,3 @@
|
|||||||
// Ignored fields are not surfaced in the UI's search key
|
|
||||||
let isIgnored = function(key, value) {
|
|
||||||
let ignored = [
|
|
||||||
'type',
|
|
||||||
'url',
|
|
||||||
'related',
|
|
||||||
'summary_fields',
|
|
||||||
'object_roles',
|
|
||||||
'activity_stream',
|
|
||||||
'update',
|
|
||||||
'teams',
|
|
||||||
'users',
|
|
||||||
'owner_teams',
|
|
||||||
'owner_users',
|
|
||||||
'access_list',
|
|
||||||
'notification_templates_error',
|
|
||||||
'notification_templates_success',
|
|
||||||
'ad_hoc_command_events',
|
|
||||||
'fact_versions',
|
|
||||||
'variable_data',
|
|
||||||
'playbooks'
|
|
||||||
];
|
|
||||||
return ignored.indexOf(key) > -1 || value.type === 'field';
|
|
||||||
};
|
|
||||||
|
|
||||||
export default
|
export default
|
||||||
class DjangoSearchModel {
|
class DjangoSearchModel {
|
||||||
/*
|
/*
|
||||||
@@ -36,21 +11,21 @@ class DjangoSearchModel {
|
|||||||
}
|
}
|
||||||
@@property related ['field' ...]
|
@@property related ['field' ...]
|
||||||
*/
|
*/
|
||||||
constructor(name, endpoint, baseFields, relations) {
|
constructor(name, baseFields, relatedSearchFields) {
|
||||||
let base = {};
|
function trimRelated(relatedSearchField){
|
||||||
|
return relatedSearchField.replace(/\__search$/, "");
|
||||||
|
}
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.related = _.reject(relations, isIgnored);
|
this.related = _.map(relatedSearchFields, trimRelated);
|
||||||
_.forEach(baseFields, (value, key) => {
|
// Remove "object" type fields from this list
|
||||||
if (!isIgnored(key, value)) {
|
for (var key in baseFields) {
|
||||||
base[key] = value;
|
if (baseFields.hasOwnProperty(key)) {
|
||||||
|
if (baseFields[key].type === 'object'){
|
||||||
|
delete baseFields[key];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
this.base = base;
|
delete baseFields.url;
|
||||||
}
|
this.base = baseFields;
|
||||||
|
|
||||||
fields() {
|
|
||||||
let result = this.base;
|
|
||||||
result.related = this.related;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,42 +1,31 @@
|
|||||||
export default ['$q', 'Rest', 'ProcessErrors', '$rootScope', 'Wait', 'DjangoSearchModel', '$cacheFactory', 'SmartSearchService',
|
export default ['$q', 'Rest', 'ProcessErrors', '$rootScope', 'Wait', 'DjangoSearchModel', 'SmartSearchService',
|
||||||
function($q, Rest, ProcessErrors, $rootScope, Wait, DjangoSearchModel, $cacheFactory, SmartSearchService) {
|
function($q, Rest, ProcessErrors, $rootScope, Wait, DjangoSearchModel, SmartSearchService) {
|
||||||
return {
|
return {
|
||||||
// kick off building a model for a specific endpoint
|
// kick off building a model for a specific endpoint
|
||||||
// this is usually a list's basePath
|
// this is usually a list's basePath
|
||||||
// unified_jobs is the exception, where we need to fetch many subclass OPTIONS and summary_fields
|
// unified_jobs is the exception, where we need to fetch many subclass OPTIONS and summary_fields
|
||||||
initFieldset(path, name, relations) {
|
initFieldset(path, name) {
|
||||||
// get or set $cachFactory.Cache object with id '$http'
|
let defer = $q.defer();
|
||||||
let defer = $q.defer(),
|
defer.resolve(this.getCommonModelOptions(path, name));
|
||||||
cache = $cacheFactory.get('$http') || $cacheFactory('$http');
|
|
||||||
defer.resolve(this.getCommonModelOptions(path, name, relations, cache));
|
|
||||||
return defer.promise;
|
return defer.promise;
|
||||||
},
|
},
|
||||||
|
|
||||||
getCommonModelOptions(path, name, relations, cache) {
|
getCommonModelOptions(path, name) {
|
||||||
let resolve, base,
|
let resolve, base,
|
||||||
defer = $q.defer();
|
defer = $q.defer();
|
||||||
|
|
||||||
// grab a single model from the cache, if present
|
this.url = path;
|
||||||
if (cache.get(path)) {
|
resolve = this.options(path)
|
||||||
defer.resolve({
|
.then((res) => {
|
||||||
models: {
|
base = res.data.actions.GET;
|
||||||
[name] : new DjangoSearchModel(name, path, cache.get(path), relations)
|
let relatedSearchFields = res.data.related_search_fields;
|
||||||
},
|
defer.resolve({
|
||||||
options: cache.get(path)
|
models: {
|
||||||
});
|
[name]: new DjangoSearchModel(name, base, relatedSearchFields)
|
||||||
} else {
|
},
|
||||||
this.url = path;
|
options: res
|
||||||
resolve = this.options(path)
|
|
||||||
.then((res) => {
|
|
||||||
base = res.data.actions.GET;
|
|
||||||
defer.resolve({
|
|
||||||
models: {
|
|
||||||
[name]: new DjangoSearchModel(name, path, base, relations)
|
|
||||||
},
|
|
||||||
options: res
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
return defer.promise;
|
return defer.promise;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
export default ['$stateParams', '$scope', '$state', 'QuerySet', 'GetBasePath', 'QuerySet', 'SmartSearchService', 'i18n',
|
export default ['$stateParams', '$scope', '$state', 'QuerySet', 'GetBasePath', 'QuerySet', 'SmartSearchService', 'i18n',
|
||||||
function($stateParams, $scope, $state, QuerySet, GetBasePath, qs, SmartSearchService, i18n) {
|
function($stateParams, $scope, $state, QuerySet, GetBasePath, qs, SmartSearchService, i18n) {
|
||||||
|
|
||||||
let path, relations,
|
let path,
|
||||||
defaults,
|
defaults,
|
||||||
queryset,
|
queryset,
|
||||||
stateChangeSuccessListener;
|
stateChangeSuccessListener;
|
||||||
@@ -28,9 +28,8 @@ export default ['$stateParams', '$scope', '$state', 'QuerySet', 'GetBasePath', '
|
|||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
path = GetBasePath($scope.basePath) || $scope.basePath;
|
path = GetBasePath($scope.basePath) || $scope.basePath;
|
||||||
relations = getRelationshipFields($scope.dataset.results);
|
|
||||||
$scope.searchTags = stripDefaultParams($state.params[`${$scope.iterator}_search`]);
|
$scope.searchTags = stripDefaultParams($state.params[`${$scope.iterator}_search`]);
|
||||||
qs.initFieldset(path, $scope.djangoModel, relations).then((data) => {
|
qs.initFieldset(path, $scope.djangoModel).then((data) => {
|
||||||
$scope.models = data.models;
|
$scope.models = data.models;
|
||||||
$scope.options = data.options.data;
|
$scope.options = data.options.data;
|
||||||
$scope.$emit(`${$scope.list.iterator}_options`, data.options);
|
$scope.$emit(`${$scope.list.iterator}_options`, data.options);
|
||||||
@@ -107,14 +106,6 @@ export default ['$stateParams', '$scope', '$state', 'QuerySet', 'GetBasePath', '
|
|||||||
return _(strippedCopy).map(qs.decodeParam).flatten().value();
|
return _(strippedCopy).map(qs.decodeParam).flatten().value();
|
||||||
}
|
}
|
||||||
|
|
||||||
// searchable relationships
|
|
||||||
function getRelationshipFields(dataset) {
|
|
||||||
let flat = _(dataset).map((value) => {
|
|
||||||
return _.keys(value.related);
|
|
||||||
}).flatten().uniq().value();
|
|
||||||
return flat;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setDefaults(term) {
|
function setDefaults(term) {
|
||||||
if ($scope.list.defaultSearchParams) {
|
if ($scope.list.defaultSearchParams) {
|
||||||
return $scope.list.defaultSearchParams(term);
|
return $scope.list.defaultSearchParams(term);
|
||||||
@@ -175,8 +166,8 @@ export default ['$stateParams', '$scope', '$state', 'QuerySet', 'GetBasePath', '
|
|||||||
let encodeParams = {
|
let encodeParams = {
|
||||||
term: tagToRemove
|
term: tagToRemove
|
||||||
};
|
};
|
||||||
if(_.has($scope.options.actions.GET, root)) {
|
if(_.has($scope.models[$scope.list.name].base, root)) {
|
||||||
if($scope.options.actions.GET[root].type && $scope.options.actions.GET[root].type === 'field') {
|
if($scope.models[$scope.list.name].base[root].type && $scope.models[$scope.list.name].base[root].type === 'field') {
|
||||||
encodeParams.relatedSearchTerm = true;
|
encodeParams.relatedSearchTerm = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -184,6 +175,10 @@ export default ['$stateParams', '$scope', '$state', 'QuerySet', 'GetBasePath', '
|
|||||||
}
|
}
|
||||||
removed = qs.encodeParam(encodeParams);
|
removed = qs.encodeParam(encodeParams);
|
||||||
}
|
}
|
||||||
|
else if(_.contains($scope.models[$scope.list.name].related, root)) {
|
||||||
|
encodeParams.relatedSearchTerm = true;
|
||||||
|
removed = qs.encodeParam(encodeParams);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
removed = setDefaults(termParts[termParts.length-1]);
|
removed = setDefaults(termParts[termParts.length-1]);
|
||||||
}
|
}
|
||||||
@@ -241,8 +236,8 @@ export default ['$stateParams', '$scope', '$state', 'QuerySet', 'GetBasePath', '
|
|||||||
} else {
|
} else {
|
||||||
// Figure out if this is a search term
|
// Figure out if this is a search term
|
||||||
let root = termParts[0].split(".")[0].replace(/^-/, '');
|
let root = termParts[0].split(".")[0].replace(/^-/, '');
|
||||||
if(_.has($scope.options.actions.GET, root)) {
|
if(_.has($scope.models[$scope.list.name].base, root)) {
|
||||||
if($scope.options.actions.GET[root].type && $scope.options.actions.GET[root].type === 'field') {
|
if($scope.models[$scope.list.name].base[root].type && $scope.models[$scope.list.name].base[root].type === 'field') {
|
||||||
params = _.merge(params, qs.encodeParam({term: term, relatedSearchTerm: true}), combineSameSearches);
|
params = _.merge(params, qs.encodeParam({term: term, relatedSearchTerm: true}), combineSameSearches);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -47,7 +47,7 @@
|
|||||||
<div class="SmartSearch-keyRow">
|
<div class="SmartSearch-keyRow">
|
||||||
<b translate>FIELDS:</b> <span ng-repeat="(key,value) in model.base">{{ key }}<span ng-if="!$last">, </span></span>
|
<b translate>FIELDS:</b> <span ng-repeat="(key,value) in model.base">{{ key }}<span ng-if="!$last">, </span></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="SmartSearch-keyRow">
|
<div class="SmartSearch-keyRow" ng-show="model.related && model.related.length > 0">
|
||||||
<b translate>RELATED FIELDS:</b> <span ng-repeat="relation in model.related">{{ relation }}<span ng-if="!$last">, </span></span>
|
<b translate>RELATED FIELDS:</b> <span ng-repeat="relation in model.related">{{ relation }}<span ng-if="!$last">, </span></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="SmartSearch-keyRow">
|
<div class="SmartSearch-keyRow">
|
||||||
|
|||||||
Reference in New Issue
Block a user