diff --git a/awx/ui/client/features/output/index.controller.js b/awx/ui/client/features/output/index.controller.js index 0c3a149679..c06e744faa 100644 --- a/awx/ui/client/features/output/index.controller.js +++ b/awx/ui/client/features/output/index.controller.js @@ -1,9 +1,7 @@ let $compile; let $q; let $scope; -let $state; let page; -let qs; let render; let resource; let scroll; @@ -21,8 +19,6 @@ function JobsIndexController ( _$scope_, _$compile_, _$q_, - _$state_, - _qs_, _status_, ) { vm = this || {}; @@ -50,24 +46,6 @@ function JobsIndexController ( vm.resource = resource; vm.title = resource.model.get('name'); - // Search - $state = _$state_; - qs = _qs_; - - vm.search = { - clearSearch, - searchKeyExamples, - searchKeyFields, - toggleSearchKey, - removeSearchTag, - submitSearch, - value: '', - key: false, - rejected: false, - disabled: !resource.model.get('finished'), - tags: getSearchTags(getCurrentQueryset()), - }; - // Stdout Navigation vm.scroll = { showBackToTop: false, @@ -111,13 +89,9 @@ function init () { onStart () { status.resetCounts(); status.setJobStatus('running'); - - vm.search.disabled = true; }, onStop () { status.updateStats(); - - vm.search.disabled = false; } }); @@ -346,63 +320,6 @@ function toggle (uuid, menu) { } } -// -// Search -// - -const searchReloadOptions = { reload: true, inherit: false }; -const searchKeyExamples = ['id:>1', 'task:set', 'created:>=2000-01-01']; -const searchKeyFields = ['changed', 'failed', 'host_name', 'stdout', 'task', 'role', 'playbook', 'play']; - -function toggleSearchKey () { - vm.search.key = !vm.search.key; -} - -function getCurrentQueryset () { - const { job_event_search } = $state.params; // eslint-disable-line camelcase - - return qs.decodeArr(job_event_search); -} - -function getSearchTags (queryset) { - return qs.createSearchTagsFromQueryset(queryset) - .filter(tag => !tag.startsWith('event')) - .filter(tag => !tag.startsWith('-event')) - .filter(tag => !tag.startsWith('page_size')) - .filter(tag => !tag.startsWith('order_by')); -} - -function removeSearchTag (index) { - const searchTerm = vm.search.tags[index]; - - const currentQueryset = getCurrentQueryset(); - const modifiedQueryset = qs.removeTermsFromQueryset(currentQueryset, searchTerm); - - vm.search.tags = getSearchTags(modifiedQueryset); - - $state.params.job_event_search = qs.encodeArr(modifiedQueryset); - $state.transitionTo($state.current, $state.params, searchReloadOptions); -} - -function submitSearch () { - const searchInputQueryset = qs.getSearchInputQueryset(vm.search.value); - - const currentQueryset = getCurrentQueryset(); - const modifiedQueryset = qs.mergeQueryset(currentQueryset, searchInputQueryset); - - vm.search.tags = getSearchTags(modifiedQueryset); - - $state.params.job_event_search = qs.encodeArr(modifiedQueryset); - $state.transitionTo($state.current, $state.params, searchReloadOptions); -} - -function clearSearch () { - vm.search.tags = []; - - $state.params.job_event_search = ''; - $state.transitionTo($state.current, $state.params, searchReloadOptions); -} - JobsIndexController.$inject = [ 'resource', 'JobPageService', @@ -412,8 +329,6 @@ JobsIndexController.$inject = [ '$scope', '$compile', '$q', - '$state', - 'QuerySet', 'JobStatusService', ]; diff --git a/awx/ui/client/features/output/index.js b/awx/ui/client/features/output/index.js index d9cc3a140d..e1727c3dc5 100644 --- a/awx/ui/client/features/output/index.js +++ b/awx/ui/client/features/output/index.js @@ -10,7 +10,7 @@ import EngineService from '~features/output/engine.service'; import StatusService from '~features/output/status.service'; import DetailsDirective from '~features/output/details.directive'; -import SearchKeyDirective from '~features/output/search-key.directive'; +import SearchDirective from '~features/output/search.directive'; import StatsDirective from '~features/output/stats.directive'; const Template = require('~features/output/index.view.html'); @@ -220,7 +220,7 @@ angular .service('JobEventEngine', EngineService) .service('JobStatusService', StatusService) .directive('atJobDetails', DetailsDirective) - .directive('atSearchKey', SearchKeyDirective) + .directive('atJobSearch', SearchDirective) .directive('atJobStats', StatsDirective) .run(JobsRun); diff --git a/awx/ui/client/features/output/index.view.html b/awx/ui/client/features/output/index.view.html index 089fcd1ce5..4e0a791bc4 100644 --- a/awx/ui/client/features/output/index.view.html +++ b/awx/ui/client/features/output/index.view.html @@ -9,55 +9,8 @@
{{ vm.title }}
- -
-
- - - - - - -
-
+ -
-
-
{{ tag }}
-
- -
-
-
CLEAR ALL
-
- - - - -
{ - vm.examples = scope.examples || []; - vm.fields = scope.fields || []; - vm.relatedFields = scope.relatedFields || []; - }; -} - -AtSearchKeyController.$inject = ['$scope']; - -function atSearchKey () { - return { - templateUrl, - restrict: 'E', - require: ['atSearchKey'], - controllerAs: 'vm', - link: atSearchKeyLink, - controller: AtSearchKeyController, - scope: { - examples: '=', - fields: '=', - relatedFields: '=', - }, - }; -} - -export default atSearchKey; diff --git a/awx/ui/client/features/output/search-key.partial.html b/awx/ui/client/features/output/search-key.partial.html deleted file mode 100644 index d2790d285f..0000000000 --- a/awx/ui/client/features/output/search-key.partial.html +++ /dev/null @@ -1,20 +0,0 @@ - -
-
-
-
-
EXAMPLES:
- -
-
-
- FIELDS: - {{ field }}, -
-
- ADDITIONAL INFORMATION: - For additional information on advanced search search syntax please see the Ansible Tower - documentation. -
-
-
diff --git a/awx/ui/client/features/output/search.directive.js b/awx/ui/client/features/output/search.directive.js new file mode 100644 index 0000000000..5945594ab1 --- /dev/null +++ b/awx/ui/client/features/output/search.directive.js @@ -0,0 +1,119 @@ +const templateUrl = require('~features/output/search.partial.html'); + +const searchReloadOptions = { reload: true, inherit: false }; +const searchKeyExamples = ['id:>1', 'task:set', 'created:>=2000-01-01']; +const searchKeyFields = ['changed', 'failed', 'host_name', 'stdout', 'task', 'role', 'playbook', 'play']; + +let $state; +let status; +let qs; + +let vm; + +function toggleSearchKey () { + vm.key = !vm.key; +} + +function getCurrentQueryset () { + const { job_event_search } = $state.params; // eslint-disable-line camelcase + + return qs.decodeArr(job_event_search); +} + +function getSearchTags (queryset) { + return qs.createSearchTagsFromQueryset(queryset) + .filter(tag => !tag.startsWith('event')) + .filter(tag => !tag.startsWith('-event')) + .filter(tag => !tag.startsWith('page_size')) + .filter(tag => !tag.startsWith('order_by')); +} + +function removeSearchTag (index) { + const searchTerm = vm.tags[index]; + + const currentQueryset = getCurrentQueryset(); + const modifiedQueryset = qs.removeTermsFromQueryset(currentQueryset, searchTerm); + + vm.tags = getSearchTags(modifiedQueryset); + + $state.params.job_event_search = qs.encodeArr(modifiedQueryset); + $state.transitionTo($state.current, $state.params, searchReloadOptions); +} + +function submitSearch () { + const searchInputQueryset = qs.getSearchInputQueryset(vm.value); + + const currentQueryset = getCurrentQueryset(); + const modifiedQueryset = qs.mergeQueryset(currentQueryset, searchInputQueryset); + + vm.tags = getSearchTags(modifiedQueryset); + + $state.params.job_event_search = qs.encodeArr(modifiedQueryset); + $state.transitionTo($state.current, $state.params, searchReloadOptions); +} + +function clearSearch () { + vm.tags = []; + + $state.params.job_event_search = ''; + $state.transitionTo($state.current, $state.params, searchReloadOptions); +} + +function atJobSearchLink (scope, el, attrs, controllers) { + const [atJobSearchController] = controllers; + + atJobSearchController.init(scope); +} + +function AtJobSearchController (_$state_, _status_, _qs_) { + $state = _$state_; + status = _status_; + qs = _qs_; + + vm = this || {}; + + vm.value = ''; + vm.key = false; + vm.rejected = false; + vm.disabled = true; + vm.tags = getSearchTags(getCurrentQueryset()); + + vm.clearSearch = clearSearch; + vm.searchKeyExamples = searchKeyExamples; + vm.searchKeyFields = searchKeyFields; + vm.toggleSearchKey = toggleSearchKey; + vm.removeSearchTag = removeSearchTag; + vm.submitSearch = submitSearch; + + vm.init = scope => { + vm.examples = scope.examples || searchKeyExamples; + vm.fields = scope.fields || searchKeyFields; + vm.relatedFields = scope.relatedFields || []; + + scope.$watch(status.isRunning, value => { vm.disabled = value; }); + }; +} + +AtJobSearchController.$inject = [ + '$state', + 'JobStatusService', + 'QuerySet', +]; + +function atJobSearch () { + return { + templateUrl, + restrict: 'E', + require: ['atJobSearch'], + controllerAs: 'vm', + link: atJobSearchLink, + controller: AtJobSearchController, + scope: { + examples: '=', + fields: '=', + relatedFields: '=', + }, + }; +} + +export default atJobSearch; diff --git a/awx/ui/client/features/output/search.partial.html b/awx/ui/client/features/output/search.partial.html new file mode 100644 index 0000000000..af34bac344 --- /dev/null +++ b/awx/ui/client/features/output/search.partial.html @@ -0,0 +1,61 @@ + +
+
+ + + + + + +
+
+ +
+
+
{{ tag }}
+
+ +
+
+ +
+ +
+
+
+
+
EXAMPLES:
+ +
+
+
+ FIELDS: + {{ field }}, +
+
+ ADDITIONAL INFORMATION: + For additional information on advanced search search syntax please see the Ansible Tower + documentation. +
+
+