From b2d22613c56f0ccbd6472668b21cf81b3f11d5b4 Mon Sep 17 00:00:00 2001 From: Chris Houseknecht Date: Wed, 18 Jun 2014 18:48:17 -0400 Subject: [PATCH] Job detail page refactor Fixed issue with tracking last event id. --- awx/ui/static/js/controllers/JobDetail.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/awx/ui/static/js/controllers/JobDetail.js b/awx/ui/static/js/controllers/JobDetail.js index 31fbf03797..67562b53a1 100644 --- a/awx/ui/static/js/controllers/JobDetail.js +++ b/awx/ui/static/js/controllers/JobDetail.js @@ -68,6 +68,7 @@ function JobDetailController ($rootScope, $scope, $compile, $routeParams, $log, event_socket.on("job_events-" + job_id, function(data) { data.event = data.event_name; + console.log("id: " + data.id + " lastEventId: " + lastEventId); if (api_complete && data.id > lastEventId) { $log.debug('received event: ' + data.id); if (queue.length < 50) { @@ -109,12 +110,17 @@ function JobDetailController ($rootScope, $scope, $compile, $routeParams, $log, } scope.removeAPIComplete = scope.$on('APIComplete', function() { // process any events sitting in the queue - var url, hostId = 0, taskId = 0, playId = 0; + var keys, url, hostId = 0, taskId = 0, playId = 0; // Find the max event.id value in memory - hostId = (scope.hostResults.length > 0) ? scope.hostResults[scope.hostResults.length - 1] : 0; - taskId = (scope.tasks.length > 0) ? scope.tasks[scope.tasks.length - 1] : 0; - playId = (scope.plays.length > 0) ? scope.plays[scope.plays.length - 1] : 0; + hostId = (scope.hostResults.length > 0) ? scope.hostResults[scope.hostResults.length - 1].id : 0; + if (scope.hostResults.length > 0) { + keys = Object.keys(scope.hostResults); + keys.sort(); + hostId = keys[keys.length - 1]; + } + taskId = (scope.tasks.length > 0) ? scope.tasks[scope.tasks.length - 1].id : 0; + playId = (scope.plays.length > 0) ? scope.plays[scope.plays.length - 1].id : 0; lastEventId = Math.max(hostId, taskId, playId); api_complete = true;