diff --git a/awx/ui/client/features/output/details.directive.js b/awx/ui/client/features/output/details.directive.js index 80251e3d9d..e0015d0b94 100644 --- a/awx/ui/client/features/output/details.directive.js +++ b/awx/ui/client/features/output/details.directive.js @@ -184,7 +184,6 @@ function getInventoryDetails () { function getProjectDetails () { const project = resource.model.get('summary_fields.project'); - const projectUpdate = resource.model.get('summary_fields.project_update'); if (!project) { return null; @@ -195,17 +194,32 @@ function getProjectDetails () { const value = $filter('sanitize')(project.name); const tooltip = strings.get('resourceTooltips.PROJECT'); - if (projectUpdate) { - const update = { - link: `/#/jobz/project/${projectUpdate.id}`, - tooltip: strings.get('resourceTooltips.PROJECT_UPDATE'), - status: projectUpdate.status, - }; + return { label, link, value, tooltip }; +} - return { label, link, value, tooltip, update }; +function getProjectStatusDetails (projectStatus) { + const project = resource.model.get('summary_fields.project'); + const jobStatus = projectStatus || resource.model.get('summary_fields.project_update.status'); + + if (!project) { + return null; } - return { label, link, value, tooltip }; + return jobStatus; +} + +function getProjectUpdateDetails (updateId) { + const project = resource.model.get('summary_fields.project'); + const jobId = updateId || resource.model.get('summary_fields.project_update.id'); + + if (!project) { + return null; + } + + const link = `/#/jobz/project/${jobId}`; + const tooltip = strings.get('resourceTooltips.PROJECT_UPDATE'); + + return { link, tooltip }; } function getSCMRevisionDetails () { @@ -495,6 +509,8 @@ function AtJobDetailsController ( vm.sourceWorkflowJob = getSourceWorkflowJobDetails(); vm.inventory = getInventoryDetails(); vm.project = getProjectDetails(); + vm.projectUpdate = getProjectUpdateDetails(); + vm.projectStatus = getProjectStatusDetails(); vm.scmRevision = getSCMRevisionDetails(); vm.playbook = getPlaybookDetails(); vm.resultTraceback = getResultTracebackDetails(); @@ -533,16 +549,15 @@ function AtJobDetailsController ( vm.deleteJob = deleteJob; vm.toggleLabels = toggleLabels; - $scope.$watch(status.getStarted, value => { vm.started = getStartDetails(value); }); - $scope.$watch(status.getJobStatus, value => { vm.status = getStatusDetails(value); }); - $scope.$watch(status.getFinished, value => { vm.finished = getFinishDetails(value); }); + const observe = (getter, transform, key) => { + $scope.$watch(getter, value => { vm[key] = transform(value); }); + }; - $scope.$watch(status.getProjectStatus, value => { - if (!value) return; - - vm.project.update = vm.project.update || {}; - vm.project.update.status = value; - }); + 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'); }; } diff --git a/awx/ui/client/features/output/details.partial.html b/awx/ui/client/features/output/details.partial.html index db5864647f..cc3f18b19d 100644 --- a/awx/ui/client/features/output/details.partial.html +++ b/awx/ui/client/features/output/details.partial.html @@ -119,11 +119,11 @@
- - + { - if (!this.statsEvent) { - return; - } - this.updateHostCounts(); - this.setFinished(this.statsEvent.created); - this.setJobStatus(this.statsEvent.failed ? 'failed' : 'successful'); + if (this.statsEvent) { + this.setFinished(this.statsEvent.created); + this.setJobStatus(this.statsEvent.failed ? 'failed' : 'successful'); + } }; this.isRunning = () => (Boolean(this.started) && !this.finished) || @@ -112,12 +116,16 @@ function JobStatusService (_moment_) { (this.jobStatus === 'pending') || (this.jobStatus === 'waiting'); + this.isExpectingStatsEvent = () => (this.jobType === 'job') || + (this.jobType === 'project_update'); + this.getPlayCount = () => this.playCount; this.getTaskCount = () => this.taskCount; this.getHostCount = () => this.hostCount; this.getHostStatusCounts = () => this.hostStatusCounts || {}; this.getJobStatus = () => this.jobStatus; this.getProjectStatus = () => this.projectStatus; + this.getProjectUpdateId = () => this.projectUpdateId; this.getElapsed = () => this.elapsed; this.getStatsEvent = () => this.statsEvent; this.getStarted = () => this.started; @@ -125,12 +133,26 @@ function JobStatusService (_moment_) { this.setJobStatus = status => { this.jobStatus = status; + + if (!this.isExpectingStatsEvent() && _.includes(FINISHED, status)) { + if (this.latestTime) { + this.setFinished(this.latestTime); + + if (!this.started && this.elapsed) { + this.started = moment(this.latestTime).subtract(this.elapsed, 'seconds'); + } + } + } }; this.setProjectStatus = status => { this.projectStatus = status; }; + this.setProjectUpdateId = id => { + this.projectUpdateId = id; + }; + this.setFinished = time => { this.finished = time; };