diff --git a/awx/ui/client/src/app.js b/awx/ui/client/src/app.js index 9a2e6ccc7d..7399b6d130 100644 --- a/awx/ui/client/src/app.js +++ b/awx/ui/client/src/app.js @@ -316,23 +316,7 @@ angular activateTab(); }); - $transitions.onCreate({}, function(trans) { - console.log('$onCreate ' +trans.to().name); - }); - - $transitions.onBefore({}, function(trans) { - console.log('$onBefore ' +trans.to().name); - }); - $transitions.onError({}, function(trans) { - - console.log('$onError ' +trans.to().name); - }); - $transitions.onExit({}, function(trans) { - console.log('$onExit ' +trans.to().name); - }); - $transitions.onSuccess({}, function(trans) { - console.log('$onSuccess ' +trans.to().name); if(trans.to() === trans.from()) { // check to see if something other than a search param has changed let toParamsWithoutSearchKeys = {}; diff --git a/awx/ui/client/src/standard-out/standard-out-factories/delete-job.factory.js b/awx/ui/client/src/standard-out/standard-out-factories/delete-job.factory.js new file mode 100644 index 0000000000..6e28362f3a --- /dev/null +++ b/awx/ui/client/src/standard-out/standard-out-factories/delete-job.factory.js @@ -0,0 +1,145 @@ +export default +function DeleteJob($state, Find, Rest, Wait, ProcessErrors, Prompt, Alert, + $filter, i18n) { + return function(params) { + var scope = params.scope, + id = params.id, + job = params.job, + callback = params.callback, + action, jobs, url, action_label, hdr; + + if (!job) { + if (scope.completed_jobs) { + jobs = scope.completed_jobs; + } + else if (scope.running_jobs) { + jobs = scope.running_jobs; + } + else if (scope.queued_jobs) { + jobs = scope.queued_jobs; + } + else if (scope.all_jobs) { + jobs = scope.all_jobs; + } + else if (scope.jobs) { + jobs = scope.jobs; + } + job = Find({list: jobs, key: 'id', val: id }); + } + + if (job.status === 'pending' || job.status === 'running' || job.status === 'waiting') { + url = job.related.cancel; + action_label = 'cancel'; + hdr = i18n._('Cancel'); + } else { + url = job.url; + action_label = 'delete'; + hdr = i18n._('Delete'); + } + + action = function () { + Wait('start'); + Rest.setUrl(url); + if (action_label === 'cancel') { + Rest.post() + .then(() => { + $('#prompt-modal').modal('hide'); + if (callback) { + scope.$emit(callback, action_label); + } + else { + $state.reload(); + Wait('stop'); + } + }) + .catch(({obj, status}) => { + Wait('stop'); + $('#prompt-modal').modal('hide'); + if (status === 403) { + Alert('Error', obj.detail); + } + // Ignore the error. The job most likely already finished. + // ProcessErrors(scope, data, status, null, { hdr: 'Error!', msg: 'Call to ' + url + + // ' failed. POST returned status: ' + status }); + }); + } else { + Rest.destroy() + .then(() => { + $('#prompt-modal').modal('hide'); + if (callback) { + scope.$emit(callback, action_label); + } + else { + let reloadListStateParams = null; + + if(scope.jobs.length === 1 && $state.params.job_search && !_.isEmpty($state.params.job_search.page) && $state.params.job_search.page !== '1') { + reloadListStateParams = _.cloneDeep($state.params); + reloadListStateParams.job_search.page = (parseInt(reloadListStateParams.job_search.page)-1).toString(); + } + + $state.go('.', reloadListStateParams, {reload: true}); + Wait('stop'); + } + }) + .catch(({obj, status}) => { + Wait('stop'); + $('#prompt-modal').modal('hide'); + if (status === 403) { + Alert('Error', obj.detail); + } + // Ignore the error. The job most likely already finished. + //ProcessErrors(scope, data, status, null, { hdr: 'Error!', msg: 'Call to ' + url + + // ' failed. DELETE returned status: ' + status }); + }); + } + }; + + if (scope.removeCancelNotAllowed) { + scope.removeCancelNotAllowed(); + } + scope.removeCancelNotAllowed = scope.$on('CancelNotAllowed', function() { + Wait('stop'); + Alert('Job Completed', 'The request to cancel the job could not be submitted. The job already completed.', 'alert-info'); + }); + + if (scope.removeCancelJob) { + scope.removeCancelJob(); + } + scope.removeCancelJob = scope.$on('CancelJob', function() { + var cancelBody = "
" + i18n._("Are you sure you want to submit the request to cancel this job?") + "
"; + var deleteBody = "
" + i18n._("Are you sure you want to delete this job?") + "
"; + Prompt({ + hdr: hdr, + resourceName: `#${job.id} ` + $filter('sanitize')(job.name), + body: (action_label === 'cancel' || job.status === 'new') ? cancelBody : deleteBody, + action: action, + actionText: (action_label === 'cancel' || job.status === 'new') ? i18n._("OK") : i18n._("DELETE") + }); + }); + + if (action_label === 'cancel') { + Rest.setUrl(url); + Rest.get() + .then(({data}) => { + if (data.can_cancel) { + scope.$emit('CancelJob'); + } + else { + scope.$emit('CancelNotAllowed'); + } + }) + .catch(({data, status}) => { + ProcessErrors(scope, data, status, null, { hdr: 'Error!', msg: 'Call to ' + url + + ' failed. GET returned: ' + status }); + }); + } + else { + scope.$emit('CancelJob'); + } + }; +} + +DeleteJob.$inject = +[ '$state', 'Find', 'Rest', 'Wait', + 'ProcessErrors', 'Prompt', 'Alert', '$filter', 'i18n' +]; diff --git a/awx/ui/client/src/standard-out/standard-out-factories/main.js b/awx/ui/client/src/standard-out/standard-out-factories/main.js index fdded8ab31..935c8dca37 100644 --- a/awx/ui/client/src/standard-out/standard-out-factories/main.js +++ b/awx/ui/client/src/standard-out/standard-out-factories/main.js @@ -5,7 +5,9 @@ *************************************************/ import lookUpName from './lookup-name.factory'; +import DeleteJob from './delete-job.factory'; export default angular.module('StandardOutHelper', []) - .factory('LookUpName', lookUpName); + .factory('LookUpName', lookUpName) + .factory('DeleteJob', DeleteJob);