mirror of
https://github.com/ansible/awx.git
synced 2026-04-06 18:49:21 -02:30
Handle case where the user just hits enter without inputing a search string
This commit is contained in:
@@ -79,15 +79,6 @@ export default ['$stateParams', '$scope', '$state', 'QuerySet', 'GetBasePath', '
|
|||||||
let params = {},
|
let params = {},
|
||||||
origQueryset = _.clone(queryset);
|
origQueryset = _.clone(queryset);
|
||||||
|
|
||||||
_.forEach(terms.split(' '), (term) => {
|
|
||||||
// if only a value is provided, search using default keys
|
|
||||||
if (term.split(':').length === 1) {
|
|
||||||
params = _.merge(params, setDefaults(term));
|
|
||||||
} else {
|
|
||||||
params = _.merge(params, qs.encodeParam(term));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
function setDefaults(term) {
|
function setDefaults(term) {
|
||||||
// "name" and "description" are sane defaults for MOST models, but not ALL!
|
// "name" and "description" are sane defaults for MOST models, but not ALL!
|
||||||
// defaults may be configured in ListDefinition.defaultSearchParams
|
// defaults may be configured in ListDefinition.defaultSearchParams
|
||||||
@@ -101,32 +92,43 @@ export default ['$stateParams', '$scope', '$state', 'QuerySet', 'GetBasePath', '
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
params.page = '1';
|
if(terms && terms !== '') {
|
||||||
queryset = _.merge(queryset, params, (objectValue, sourceValue, key, object) => {
|
_.forEach(terms.split(' '), (term) => {
|
||||||
if (object[key] && object[key] !== sourceValue){
|
// if only a value is provided, search using default keys
|
||||||
return [object[key], sourceValue];
|
if (term.split(':').length === 1) {
|
||||||
}
|
params = _.merge(params, setDefaults(term));
|
||||||
else {
|
} else {
|
||||||
// // https://lodash.com/docs/3.10.1#merge
|
params = _.merge(params, qs.encodeParam(term));
|
||||||
// If customizer fn returns undefined merging is handled by default _.merge algorithm
|
}
|
||||||
return undefined;
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
// https://ui-router.github.io/docs/latest/interfaces/params.paramdeclaration.html#dynamic
|
|
||||||
// This transition will not reload controllers/resolves/views
|
|
||||||
// but will register new $stateParams[$scope.iterator + '_search'] terms
|
|
||||||
$state.go('.', {
|
|
||||||
[$scope.iterator + '_search']: queryset });
|
|
||||||
qs.search(path, queryset).then((res) => {
|
|
||||||
$scope.dataset = res.data;
|
|
||||||
$scope.collection = res.data.results;
|
|
||||||
})
|
|
||||||
.catch(function() {
|
|
||||||
$scope.revertSearch(origQueryset);
|
|
||||||
});
|
|
||||||
|
|
||||||
$scope.searchTerm = null;
|
params.page = '1';
|
||||||
$scope.searchTags = stripDefaultParams(queryset);
|
queryset = _.merge(queryset, params, (objectValue, sourceValue, key, object) => {
|
||||||
|
if (object[key] && object[key] !== sourceValue){
|
||||||
|
return [object[key], sourceValue];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// // https://lodash.com/docs/3.10.1#merge
|
||||||
|
// If customizer fn returns undefined merging is handled by default _.merge algorithm
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// https://ui-router.github.io/docs/latest/interfaces/params.paramdeclaration.html#dynamic
|
||||||
|
// This transition will not reload controllers/resolves/views
|
||||||
|
// but will register new $stateParams[$scope.iterator + '_search'] terms
|
||||||
|
$state.go('.', {
|
||||||
|
[$scope.iterator + '_search']: queryset });
|
||||||
|
qs.search(path, queryset).then((res) => {
|
||||||
|
$scope.dataset = res.data;
|
||||||
|
$scope.collection = res.data.results;
|
||||||
|
})
|
||||||
|
.catch(function() {
|
||||||
|
$scope.revertSearch(origQueryset);
|
||||||
|
});
|
||||||
|
|
||||||
|
$scope.searchTerm = null;
|
||||||
|
$scope.searchTags = stripDefaultParams(queryset);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.revertSearch = function(queryToBeRestored) {
|
$scope.revertSearch = function(queryToBeRestored) {
|
||||||
|
|||||||
Reference in New Issue
Block a user