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:
commit
6ccb2a46f7
@ -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',
|
||||
|
@ -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;
|
||||
|
@ -28,6 +28,9 @@
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
<p ng-if="vm.rejected" class="at-InputMessage--rejected">
|
||||
{{ vm.message }}
|
||||
</p>
|
||||
</form>
|
||||
|
||||
<div class="jobz-tagz">
|
||||
|
Loading…
Reference in New Issue
Block a user