From 3b5dd7eac50a3b57e23f9a76b2fbfb5d8b6bdc56 Mon Sep 17 00:00:00 2001 From: Jake McDermott Date: Tue, 8 May 2018 23:55:48 -0400 Subject: [PATCH] error handling for job results filter and route --- awx/ui/client/features/output/index.js | 22 +++++- .../features/output/search.component.js | 67 +++++++++++-------- .../features/output/search.partial.html | 3 + 3 files changed, 60 insertions(+), 32 deletions(-) diff --git a/awx/ui/client/features/output/index.js b/awx/ui/client/features/output/index.js index 6b14296553..813d1c2af3 100644 --- a/awx/ui/client/features/output/index.js +++ b/awx/ui/client/features/output/index.js @@ -26,6 +26,7 @@ const PAGE_SIZE = 50; const WS_PREFIX = 'ws'; function resolveResource ( + $state, Job, ProjectUpdate, AdHocCommand, @@ -36,7 +37,9 @@ function resolveResource ( qs, Wait ) { - const { id, type, job_event_search } = $stateParams; // eslint-disable-line camelcase + const { id, type, handleErrors } = $stateParams; + const { job_event_search } = $stateParams; // eslint-disable-line camelcase + const { name, key } = getWebSocketResource(type); let Resource; @@ -77,7 +80,7 @@ function resolveResource ( } Wait('start'); - return new Resource(['get', 'options'], [id, id]) + const resourcePromise = new Resource(['get', 'options'], [id, id]) .then(model => { const promises = [model.getStats()]; @@ -105,8 +108,17 @@ function resolveResource ( pageLimit: PAGE_LIMIT } })) - .catch(({ data, status }) => qs.error(data, status)) .finally(() => Wait('stop')); + + if (!handleErrors) { + return resourcePromise; + } + + return resourcePromise + .catch(({ data, status }) => { + $state.go($state.current, $state.params, { reload: true }); + qs.error(data, status); + }); } function resolveWebSocketConnection ($stateParams, SocketService) { @@ -168,6 +180,9 @@ function JobsRun ($stateRegistry, strings) { name: 'output', parent, ncyBreadcrumb, + params: { + handleErrors: true, + }, data: { activityStream: false, }, @@ -185,6 +200,7 @@ function JobsRun ($stateRegistry, strings) { resolveWebSocketConnection ], resource: [ + '$state', 'JobModel', 'ProjectUpdateModel', 'AdHocCommandModel', diff --git a/awx/ui/client/features/output/search.component.js b/awx/ui/client/features/output/search.component.js index d1e37edd14..b1f40efd3e 100644 --- a/awx/ui/client/features/output/search.component.js +++ b/awx/ui/client/features/output/search.component.js @@ -1,11 +1,13 @@ const templateUrl = require('~features/output/search.partial.html'); -const searchReloadOptions = { reload: true, inherit: false }; +const searchReloadOptions = { inherit: false, location: 'replace' }; const searchKeyExamples = ['id:>1', 'task:set', 'created:>=2000-01-01']; const searchKeyFields = ['changed', 'failed', 'host_name', 'stdout', 'task', 'role', 'playbook', 'play']; const PLACEHOLDER_RUNNING = 'CANNOT SEARCH RUNNING JOB'; const PLACEHOLDER_DEFAULT = 'SEARCH'; +const REJECT_DEFAULT = 'Failed to update search results.'; +const REJECT_INVALID = 'Invalid search filter provided.'; let $state; let qs; @@ -30,38 +32,46 @@ function getSearchTags (queryset) { .filter(tag => !tag.startsWith('order_by')); } +function reloadQueryset (queryset, rejection = REJECT_DEFAULT) { + const params = angular.copy($state.params); + const currentTags = vm.tags; + + params.handleErrors = false; + params.job_event_search = qs.encodeArr(queryset); + + vm.disabled = true; + vm.message = ''; + vm.tags = getSearchTags(queryset); + + return $state.transitionTo($state.current, params, searchReloadOptions) + .catch(() => { + vm.tags = currentTags; + vm.message = rejection; + vm.rejected = true; + vm.disabled = false; + }); +} + function removeSearchTag (index) { const searchTerm = vm.tags[index]; const currentQueryset = getCurrentQueryset(); const modifiedQueryset = qs.removeTermsFromQueryset(currentQueryset, searchTerm); - vm.tags = getSearchTags(modifiedQueryset); - vm.disabled = true; - - $state.params.job_event_search = qs.encodeArr(modifiedQueryset); - $state.transitionTo($state.current, $state.params, searchReloadOptions); + reloadQueryset(modifiedQueryset); } function submitSearch () { - const searchInputQueryset = qs.getSearchInputQueryset(vm.value); - const currentQueryset = getCurrentQueryset(); + + const searchInputQueryset = qs.getSearchInputQueryset(vm.value); const modifiedQueryset = qs.mergeQueryset(currentQueryset, searchInputQueryset); - vm.tags = getSearchTags(modifiedQueryset); - vm.disabled = true; - - $state.params.job_event_search = qs.encodeArr(modifiedQueryset); - $state.transitionTo($state.current, $state.params, searchReloadOptions); + reloadQueryset(modifiedQueryset, REJECT_INVALID); } function clearSearch () { - vm.tags = []; - vm.disabled = true; - - $state.params.job_event_search = ''; - $state.transitionTo($state.current, $state.params, searchReloadOptions); + reloadQueryset(); } function JobSearchController (_$state_, _qs_, { subscribe }) { @@ -70,15 +80,12 @@ function JobSearchController (_$state_, _qs_, { subscribe }) { vm = this || {}; - vm.value = ''; - vm.key = false; - vm.rejected = false; - vm.disabled = true; - vm.tags = getSearchTags(getCurrentQueryset()); + vm.examples = searchKeyExamples; + vm.fields = searchKeyFields; + vm.relatedFields = []; + vm.placeholder = PLACEHOLDER_DEFAULT; vm.clearSearch = clearSearch; - vm.searchKeyExamples = searchKeyExamples; - vm.searchKeyFields = searchKeyFields; vm.toggleSearchKey = toggleSearchKey; vm.removeSearchTag = removeSearchTag; vm.submitSearch = submitSearch; @@ -86,10 +93,12 @@ function JobSearchController (_$state_, _qs_, { subscribe }) { let unsubscribe; vm.$onInit = () => { - vm.examples = searchKeyExamples; - vm.fields = searchKeyFields; - vm.placeholder = PLACEHOLDER_DEFAULT; - vm.relatedFields = []; + vm.value = ''; + vm.message = ''; + vm.key = false; + vm.rejected = false; + vm.disabled = true; + vm.tags = getSearchTags(getCurrentQueryset()); unsubscribe = subscribe(({ running }) => { vm.disabled = running; diff --git a/awx/ui/client/features/output/search.partial.html b/awx/ui/client/features/output/search.partial.html index d7acedc3d4..c209394815 100644 --- a/awx/ui/client/features/output/search.partial.html +++ b/awx/ui/client/features/output/search.partial.html @@ -28,6 +28,9 @@ +

+ {{ vm.message }} +