1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 16:51:11 +03:00

Merge pull request #1743 from jakemcdermott/job-results/fix-1535

error handling for job results filter and route
This commit is contained in:
Jake McDermott 2018-05-10 11:53:53 -04:00 committed by GitHub
commit 6ccb2a46f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 32 deletions

View File

@ -26,6 +26,7 @@ const PAGE_SIZE = 50;
const WS_PREFIX = 'ws'; const WS_PREFIX = 'ws';
function resolveResource ( function resolveResource (
$state,
Job, Job,
ProjectUpdate, ProjectUpdate,
AdHocCommand, AdHocCommand,
@ -36,7 +37,9 @@ function resolveResource (
qs, qs,
Wait 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); const { name, key } = getWebSocketResource(type);
let Resource; let Resource;
@ -77,7 +80,7 @@ function resolveResource (
} }
Wait('start'); Wait('start');
return new Resource(['get', 'options'], [id, id]) const resourcePromise = new Resource(['get', 'options'], [id, id])
.then(model => { .then(model => {
const promises = [model.getStats()]; const promises = [model.getStats()];
@ -105,8 +108,17 @@ function resolveResource (
pageLimit: PAGE_LIMIT pageLimit: PAGE_LIMIT
} }
})) }))
.catch(({ data, status }) => qs.error(data, status))
.finally(() => Wait('stop')); .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) { function resolveWebSocketConnection ($stateParams, SocketService) {
@ -168,6 +180,9 @@ function JobsRun ($stateRegistry, strings) {
name: 'output', name: 'output',
parent, parent,
ncyBreadcrumb, ncyBreadcrumb,
params: {
handleErrors: true,
},
data: { data: {
activityStream: false, activityStream: false,
}, },
@ -185,6 +200,7 @@ function JobsRun ($stateRegistry, strings) {
resolveWebSocketConnection resolveWebSocketConnection
], ],
resource: [ resource: [
'$state',
'JobModel', 'JobModel',
'ProjectUpdateModel', 'ProjectUpdateModel',
'AdHocCommandModel', 'AdHocCommandModel',

View File

@ -1,11 +1,13 @@
const templateUrl = require('~features/output/search.partial.html'); 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 searchKeyExamples = ['id:>1', 'task:set', 'created:>=2000-01-01'];
const searchKeyFields = ['changed', 'failed', 'host_name', 'stdout', 'task', 'role', 'playbook', 'play']; const searchKeyFields = ['changed', 'failed', 'host_name', 'stdout', 'task', 'role', 'playbook', 'play'];
const PLACEHOLDER_RUNNING = 'CANNOT SEARCH RUNNING JOB'; const PLACEHOLDER_RUNNING = 'CANNOT SEARCH RUNNING JOB';
const PLACEHOLDER_DEFAULT = 'SEARCH'; const PLACEHOLDER_DEFAULT = 'SEARCH';
const REJECT_DEFAULT = 'Failed to update search results.';
const REJECT_INVALID = 'Invalid search filter provided.';
let $state; let $state;
let qs; let qs;
@ -30,38 +32,46 @@ function getSearchTags (queryset) {
.filter(tag => !tag.startsWith('order_by')); .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) { function removeSearchTag (index) {
const searchTerm = vm.tags[index]; const searchTerm = vm.tags[index];
const currentQueryset = getCurrentQueryset(); const currentQueryset = getCurrentQueryset();
const modifiedQueryset = qs.removeTermsFromQueryset(currentQueryset, searchTerm); const modifiedQueryset = qs.removeTermsFromQueryset(currentQueryset, searchTerm);
vm.tags = getSearchTags(modifiedQueryset); reloadQueryset(modifiedQueryset);
vm.disabled = true;
$state.params.job_event_search = qs.encodeArr(modifiedQueryset);
$state.transitionTo($state.current, $state.params, searchReloadOptions);
} }
function submitSearch () { function submitSearch () {
const searchInputQueryset = qs.getSearchInputQueryset(vm.value);
const currentQueryset = getCurrentQueryset(); const currentQueryset = getCurrentQueryset();
const searchInputQueryset = qs.getSearchInputQueryset(vm.value);
const modifiedQueryset = qs.mergeQueryset(currentQueryset, searchInputQueryset); const modifiedQueryset = qs.mergeQueryset(currentQueryset, searchInputQueryset);
vm.tags = getSearchTags(modifiedQueryset); reloadQueryset(modifiedQueryset, REJECT_INVALID);
vm.disabled = true;
$state.params.job_event_search = qs.encodeArr(modifiedQueryset);
$state.transitionTo($state.current, $state.params, searchReloadOptions);
} }
function clearSearch () { function clearSearch () {
vm.tags = []; reloadQueryset();
vm.disabled = true;
$state.params.job_event_search = '';
$state.transitionTo($state.current, $state.params, searchReloadOptions);
} }
function JobSearchController (_$state_, _qs_, { subscribe }) { function JobSearchController (_$state_, _qs_, { subscribe }) {
@ -70,15 +80,12 @@ function JobSearchController (_$state_, _qs_, { subscribe }) {
vm = this || {}; vm = this || {};
vm.value = ''; vm.examples = searchKeyExamples;
vm.key = false; vm.fields = searchKeyFields;
vm.rejected = false; vm.relatedFields = [];
vm.disabled = true; vm.placeholder = PLACEHOLDER_DEFAULT;
vm.tags = getSearchTags(getCurrentQueryset());
vm.clearSearch = clearSearch; vm.clearSearch = clearSearch;
vm.searchKeyExamples = searchKeyExamples;
vm.searchKeyFields = searchKeyFields;
vm.toggleSearchKey = toggleSearchKey; vm.toggleSearchKey = toggleSearchKey;
vm.removeSearchTag = removeSearchTag; vm.removeSearchTag = removeSearchTag;
vm.submitSearch = submitSearch; vm.submitSearch = submitSearch;
@ -86,10 +93,12 @@ function JobSearchController (_$state_, _qs_, { subscribe }) {
let unsubscribe; let unsubscribe;
vm.$onInit = () => { vm.$onInit = () => {
vm.examples = searchKeyExamples; vm.value = '';
vm.fields = searchKeyFields; vm.message = '';
vm.placeholder = PLACEHOLDER_DEFAULT; vm.key = false;
vm.relatedFields = []; vm.rejected = false;
vm.disabled = true;
vm.tags = getSearchTags(getCurrentQueryset());
unsubscribe = subscribe(({ running }) => { unsubscribe = subscribe(({ running }) => {
vm.disabled = running; vm.disabled = running;

View File

@ -28,6 +28,9 @@
</button> </button>
</span> </span>
</div> </div>
<p ng-if="vm.rejected" class="at-InputMessage--rejected">
{{ vm.message }}
</p>
</form> </form>
<div class="jobz-tagz"> <div class="jobz-tagz">