From 5ef297aec17cca3e964ead2a60a954a1416ac1ec Mon Sep 17 00:00:00 2001 From: mabashian Date: Tue, 1 May 2018 12:13:16 -0400 Subject: [PATCH] Update relaunch button on details page in real time as status changes --- .../features/output/details.directive.js | 8 +++- .../relaunchButton.component.js | 38 +++++++++---------- .../relaunchButton.partial.html | 5 ++- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/awx/ui/client/features/output/details.directive.js b/awx/ui/client/features/output/details.directive.js index b19475f70a..d4e590e1c3 100644 --- a/awx/ui/client/features/output/details.directive.js +++ b/awx/ui/client/features/output/details.directive.js @@ -556,7 +556,7 @@ function AtJobDetailsController ( vm.labels = getLabelDetails(); // Relaunch and Delete Components - vm.job = _.get(resource.model, 'model.GET', {}); + vm.job = angular.copy(_.get(resource.model, 'model.GET', {})); vm.canDelete = resource.model.get('summary_fields.user_capabilities.delete'); vm.cancelJob = cancelJob; @@ -568,10 +568,14 @@ function AtJobDetailsController ( }; observe(status.getStarted, getStartDetails, 'started'); - observe(status.getJobStatus, getStatusDetails, 'status'); observe(status.getFinished, getFinishDetails, 'finished'); observe(status.getProjectUpdateId, getProjectUpdateDetails, 'projectUpdate'); observe(status.getProjectStatus, getProjectStatusDetails, 'projectStatus'); + + $scope.$watch(status.getJobStatus, jobStatus => { + vm.status = getStatusDetails(jobStatus); + vm.job.status = jobStatus; + }); }; } diff --git a/awx/ui/client/lib/components/relaunchButton/relaunchButton.component.js b/awx/ui/client/lib/components/relaunchButton/relaunchButton.component.js index df97883dc4..1f258a94ba 100644 --- a/awx/ui/client/lib/components/relaunchButton/relaunchButton.component.js +++ b/awx/ui/client/lib/components/relaunchButton/relaunchButton.component.js @@ -23,6 +23,14 @@ function atRelaunchCtrl ( const jobObj = new Job(); const jobTemplate = new JobTemplate(); + const updateTooltip = () => { + if (vm.job.type === 'job' && vm.job.status === 'failed') { + vm.tooltip = strings.get('relaunch.HOSTS'); + } else { + vm.tooltip = strings.get('relaunch.DEFAULT'); + } + }; + const checkRelaunchPlaybook = (option) => { jobObj.getRelaunch({ id: vm.job.id @@ -113,7 +121,7 @@ function atRelaunchCtrl ( jobObj.postRelaunch(launchParams) .then((launchRes) => { - if (!$state.includes('jobs')) { + if (!$state.is('jobs')) { const relaunchType = launchRes.data.type === 'job' ? 'playbook' : launchRes.data.type; $state.go('jobz', { id: launchRes.data.id, type: relaunchType }, { reload: true }); } @@ -129,13 +137,7 @@ function atRelaunchCtrl ( vm.$onInit = () => { vm.showRelaunch = vm.job.type !== 'system_job' && vm.job.summary_fields.user_capabilities.start; - vm.showDropdown = vm.job.type === 'job' && vm.job.status === 'failed'; - vm.createDropdown(); - vm.createTooltips(); - }; - - vm.createDropdown = () => { vm.icon = 'icon-launch'; vm.dropdownTitle = strings.get('relaunch.DROPDOWN_TITLE'); vm.dropdownOptions = [ @@ -148,14 +150,12 @@ function atRelaunchCtrl ( icon: 'icon-host-failed' } ]; - }; - vm.createTooltips = () => { - if (vm.showDropdown) { - vm.tooltip = strings.get('relaunch.HOSTS'); - } else { - vm.tooltip = strings.get('relaunch.DEFAULT'); - } + updateTooltip(); + + $scope.$watch('vm.job.status', () => { + updateTooltip(); + }); }; vm.relaunchJob = () => { @@ -167,7 +167,7 @@ function atRelaunchCtrl ( if (getUpdateRes.data.can_update) { inventorySource.postUpdate(vm.job.inventory_source) .then((postUpdateRes) => { - if (!$state.includes('jobs')) { + if (!$state.is('jobs')) { $state.go('jobz', { id: postUpdateRes.data.id, type: 'inventory' }, { reload: true }); } }).catch(({ data, status, config }) => { @@ -191,7 +191,7 @@ function atRelaunchCtrl ( if (getUpdateRes.data.can_update) { project.postUpdate(vm.job.project) .then((postUpdateRes) => { - if (!$state.includes('jobs')) { + if (!$state.is('jobs')) { $state.go('jobz', { id: postUpdateRes.data.id, type: 'project' }, { reload: true }); } }).catch(({ data, status, config }) => { @@ -213,7 +213,7 @@ function atRelaunchCtrl ( workflowJob.postRelaunch({ id: vm.job.id }).then((launchRes) => { - if (!$state.includes('jobs')) { + if (!$state.is('jobs')) { $state.go('workflowResults', { id: launchRes.data.id }, { reload: true }); } }).catch(({ data, status, config }) => { @@ -237,7 +237,7 @@ function atRelaunchCtrl ( adHocCommand.postRelaunch({ id: vm.job.id }).then((launchRes) => { - if (!$state.includes('jobs')) { + if (!$state.is('jobs')) { $state.go('jobz', { id: launchRes.data.id, type: 'command' }, { reload: true }); } }).catch(({ data, status, config }) => { @@ -262,7 +262,7 @@ function atRelaunchCtrl ( id: vm.promptData.job, relaunchData: PromptService.bundlePromptDataForRelaunch(vm.promptData) }).then((launchRes) => { - if (!$state.includes('jobs')) { + if (!$state.is('jobs')) { $state.go('jobz', { id: launchRes.data.job, type: 'playbook' }, { reload: true }); } }).catch(({ data, status }) => { diff --git a/awx/ui/client/lib/components/relaunchButton/relaunchButton.partial.html b/awx/ui/client/lib/components/relaunchButton/relaunchButton.partial.html index 280380dcbc..22f7120152 100644 --- a/awx/ui/client/lib/components/relaunchButton/relaunchButton.partial.html +++ b/awx/ui/client/lib/components/relaunchButton/relaunchButton.partial.html @@ -1,9 +1,10 @@
-
+