From fab3f3d592526f064ef4f089b666f81585f4197f Mon Sep 17 00:00:00 2001 From: mabashian Date: Wed, 11 Apr 2018 16:53:03 -0400 Subject: [PATCH 1/2] Added cancel job logic to the jobs list --- .../features/jobs/jobsList.controller.js | 42 +++++++++++++++++++ .../client/features/jobs/jobsList.view.html | 13 +++++- .../lib/services/base-string.service.js | 5 +++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/awx/ui/client/features/jobs/jobsList.controller.js b/awx/ui/client/features/jobs/jobsList.controller.js index ea57c4e9f5..d64e1870a5 100644 --- a/awx/ui/client/features/jobs/jobsList.controller.js +++ b/awx/ui/client/features/jobs/jobsList.controller.js @@ -118,6 +118,48 @@ function ListJobsController ( actionText: 'DELETE' }); }; + + vm.cancelJob = (job) => { + const action = () => { + $('#prompt-modal').modal('hide'); + Wait('start'); + Rest.setUrl(job.related.cancel); + Rest.post() + .then(() => { + let reloadListStateParams = null; + + if ($scope.jobs.length === 1 && $state.params.job_search && + !_.isEmpty($state.params.job_search.page) && + $state.params.job_search.page !== '1') { + const page = `${(parseInt(reloadListStateParams + .job_search.page, 10) - 1)}`; + reloadListStateParams = _.cloneDeep($state.params); + reloadListStateParams.job_search.page = page; + } + + $state.go('.', reloadListStateParams, { reload: true }); + }) + .catch(({ data, status }) => { + ProcessErrors($scope, data, status, null, { + hdr: strings.get('error.HEADER'), + msg: strings.get('error.CALL', { path: `${job.url}`, status }) + }); + }) + .finally(() => { + Wait('stop'); + }); + }; + + const deleteModalBody = `
${strings.get('cancelJob.SUBMIT_REQUEST')}
`; + + Prompt({ + hdr: strings.get('cancelJob.HEADER'), + resourceName: $filter('sanitize')(job.name), + body: deleteModalBody, + action, + actionText: strings.get('CANCEL') + }); + }; } ListJobsController.$inject = [ diff --git a/awx/ui/client/features/jobs/jobsList.view.html b/awx/ui/client/features/jobs/jobsList.view.html index c5d18cecbe..183e9ce72f 100644 --- a/awx/ui/client/features/jobs/jobsList.view.html +++ b/awx/ui/client/features/jobs/jobsList.view.html @@ -71,8 +71,19 @@ + + + ng-show="job.summary_fields.user_capabilities.delete && + !(job.status === 'new' || + job.status === 'pending' || + job.status === 'waiting' || + job.status === 'running')"> diff --git a/awx/ui/client/lib/services/base-string.service.js b/awx/ui/client/lib/services/base-string.service.js index 11192aba29..6b5831aac9 100644 --- a/awx/ui/client/lib/services/base-string.service.js +++ b/awx/ui/client/lib/services/base-string.service.js @@ -76,6 +76,11 @@ function BaseStringService (namespace) { CONFIRM: resourceType => t.s('Are you sure you want to delete this {{ resourceType }}?', { resourceType }) }; + this.cancelJob = { + HEADER: t.s('Cancel'), + SUBMIT_REQUEST: t.s('Are you sure you want to submit the request to cancel this job?') + }; + this.error = { HEADER: t.s('Error!'), CALL: ({ path, action, status }) => t.s('Call to {{ path }} failed. {{ action }} returned status: {{ status }}.', { path, action, status }), From f35bc4b40a5569fcab7f956c67ba4d7f78740689 Mon Sep 17 00:00:00 2001 From: mabashian Date: Thu, 12 Apr 2018 09:30:04 -0400 Subject: [PATCH 2/2] Cancelable job status' should be pending, waiting or running --- awx/ui/client/features/jobs/jobsList.view.html | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/awx/ui/client/features/jobs/jobsList.view.html b/awx/ui/client/features/jobs/jobsList.view.html index 183e9ce72f..e9325b18f1 100644 --- a/awx/ui/client/features/jobs/jobsList.view.html +++ b/awx/ui/client/features/jobs/jobsList.view.html @@ -73,15 +73,13 @@