From f8c3fd11dacc06c7c5ccfd47e2e2206eb5468ccb Mon Sep 17 00:00:00 2001 From: Joe Fiorini Date: Wed, 4 Mar 2015 14:16:29 -0500 Subject: [PATCH] Fix live events on dashboard --- awx/ui/static/js/controllers/Home.js | 11 +++++++++++ awx/ui/static/js/directives/job-status-graph.js | 8 ++++++-- awx/ui/static/js/widgets/DashboardJobs.js | 4 ++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/awx/ui/static/js/controllers/Home.js b/awx/ui/static/js/controllers/Home.js index 4b74d4cd3f..263293d21a 100644 --- a/awx/ui/static/js/controllers/Home.js +++ b/awx/ui/static/js/controllers/Home.js @@ -94,6 +94,17 @@ export function Home($scope, $compile, $routeParams, $rootScope, $location, $log $scope.graphData = graphData; + var cleanupJobListener = + $rootScope.$on('DataReceived:JobStatusGraph', function(e, data) { + $scope.refresh(); + $scope.graphData.jobStatus = data; + }); + + $scope.$on('$destroy', function() { + cleanupJobListener(); + }); + + DashboardJobs({ scope: $scope, target: 'dash-jobs-list', diff --git a/awx/ui/static/js/directives/job-status-graph.js b/awx/ui/static/js/directives/job-status-graph.js index 97010587d6..0bb06afce9 100644 --- a/awx/ui/static/js/directives/job-status-graph.js +++ b/awx/ui/static/js/directives/job-status-graph.js @@ -12,6 +12,9 @@ export default function JobStatusGraph($rootScope, $compile , $location, $window, Wait, adjustGraphSize) { return { restrict: 'E', + scope: { + data: '=' + }, templateUrl: '/static/partials/job_status_graph.html', link: link }; @@ -22,11 +25,12 @@ function JobStatusGraph($rootScope, $compile , $location, $window, Wait, adjustG scope.period="month"; scope.jobType="all"; - scope.$watch(attr.data, function(value) { + scope.$watch('data', function(value) { if (value) { createGraph(value, scope.period, scope.jobType); } - }); + }, true); + function createGraph(data, period, jobtype){ diff --git a/awx/ui/static/js/widgets/DashboardJobs.js b/awx/ui/static/js/widgets/DashboardJobs.js index b3db9e1c45..ac6621a0e9 100644 --- a/awx/ui/static/js/widgets/DashboardJobs.js +++ b/awx/ui/static/js/widgets/DashboardJobs.js @@ -48,6 +48,10 @@ angular.module('DashboardJobsWidget', ['RestServices', 'Utilities']) e.html(html); $compile(e)(scope); + $rootScope.$on('JobStatusChange', function() { + jobs_scope.refreshJobs(); + }); + if (scope.removeListLoaded) { scope.removeListLoaded(); }