mirror of
https://github.com/ansible/awx.git
synced 2026-02-28 08:18:43 -03:30
Merge pull request #4534 from mabashian/3855-enter-key-search
Smart search enter key pressed logic
This commit is contained in:
@@ -1151,4 +1151,21 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'JobsHelper'])
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}])
|
||||||
|
|
||||||
|
.directive('awEnterKey', [function() {
|
||||||
|
return {
|
||||||
|
restrict: 'A',
|
||||||
|
link: function(scope, element, attrs) {
|
||||||
|
element.bind("keydown keypress", function(event) {
|
||||||
|
var keyCode = event.which || event.keyCode;
|
||||||
|
if (keyCode === 13) {
|
||||||
|
scope.$apply(function() {
|
||||||
|
scope.$eval(attrs.awEnterKey);
|
||||||
|
});
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|||||||
@@ -76,16 +76,8 @@ export default ['$stateParams', '$scope', '$state', 'QuerySet', 'GetBasePath', '
|
|||||||
|
|
||||||
// add a search tag, merge new queryset, $state.go()
|
// add a search tag, merge new queryset, $state.go()
|
||||||
$scope.add = function(terms) {
|
$scope.add = function(terms) {
|
||||||
let params = {};
|
let params = {},
|
||||||
|
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!
|
||||||
@@ -100,17 +92,47 @@ 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;
|
});
|
||||||
}
|
|
||||||
});
|
params.page = '1';
|
||||||
|
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) {
|
||||||
|
queryset = queryToBeRestored;
|
||||||
// https://ui-router.github.io/docs/latest/interfaces/params.paramdeclaration.html#dynamic
|
// https://ui-router.github.io/docs/latest/interfaces/params.paramdeclaration.html#dynamic
|
||||||
// This transition will not reload controllers/resolves/views
|
// This transition will not reload controllers/resolves/views
|
||||||
// but will register new $stateParams[$scope.iterator + '_search'] terms
|
// but will register new $stateParams[$scope.iterator + '_search'] terms
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<div class="SmartSearch-bar">
|
<div class="SmartSearch-bar">
|
||||||
<div class="SmartSearch-searchTermContainer">
|
<div class="SmartSearch-searchTermContainer">
|
||||||
<!-- string search input -->
|
<!-- string search input -->
|
||||||
<form class="SmartSearch-form" ng-submit="add(searchTerm)" novalidate>
|
<form name="smartSearch" class="SmartSearch-form" aw-enter-key="add(searchTerm)" novalidate>
|
||||||
<input class="SmartSearch-input" ng-model="searchTerm" placeholder="Search">
|
<input class="SmartSearch-input" ng-model="searchTerm" placeholder="Search">
|
||||||
</form>
|
</form>
|
||||||
<div type="submit" class="SmartSearch-searchButton" ng-disabled="!searchTerm" ng-click="add(searchTerm)">
|
<div type="submit" class="SmartSearch-searchButton" ng-disabled="!searchTerm" ng-click="add(searchTerm)">
|
||||||
|
|||||||
Reference in New Issue
Block a user