diff --git a/awx/ui/client/src/app.js b/awx/ui/client/src/app.js index f3d665fafe..6df9567b34 100644 --- a/awx/ui/client/src/app.js +++ b/awx/ui/client/src/app.js @@ -802,7 +802,6 @@ var tower = angular.module('Tower', [ ConfigService.getConfig().then(function() { Timer.init().then(function(timer) { $rootScope.sessionTimer = timer; - // $rootScope.$emit('OpenSocket'); SocketService.init(); pendoService.issuePendoIdentity(); CheckLicense.test(); @@ -847,10 +846,6 @@ var tower = angular.module('Tower', [ // create a promise that will resolve when features are loaded $rootScope.featuresConfigured = $q.defer(); } - if (!$rootScope.socketPromise) { - // create a promise that resolves when the socket connection is open - $rootScope.socketPromise = $q.defer(); - } $rootScope.licenseMissing = true; //the authorization controller redirects to the home page automatcially if there is no last path defined. in order to override // this, set the last path to /portal for instances where portal is visited for the first time. diff --git a/awx/ui/client/src/controllers/Home.js b/awx/ui/client/src/controllers/Home.js index ff443923fc..a4999487f6 100644 --- a/awx/ui/client/src/controllers/Home.js +++ b/awx/ui/client/src/controllers/Home.js @@ -28,7 +28,7 @@ export function Home($scope, $compile, $stateParams, $rootScope, $location, $log var dataCount = 0; - $rootScope.$on('ws-jobs', function () { + $scope.$on('ws-jobs', function () { Rest.setUrl(GetBasePath('dashboard')); Rest.get() .success(function (data) { diff --git a/awx/ui/client/src/controllers/Jobs.js b/awx/ui/client/src/controllers/Jobs.js index 8ed4ca9da0..07e84df3ee 100644 --- a/awx/ui/client/src/controllers/Jobs.js +++ b/awx/ui/client/src/controllers/Jobs.js @@ -65,7 +65,7 @@ export function JobsListController ($rootScope, $log, $scope, $compile, $statePa jobs_scope.viewJob = function (id) { $state.transitionTo('jobDetail', {id: id}); }; - + jobs_scope.showJobType = true; LoadJobsScope({ parent_scope: $scope, @@ -110,17 +110,11 @@ export function JobsListController ($rootScope, $log, $scope, $compile, $statePa } }; - if ($rootScope.removeJobStatusChange) { - $rootScope.removeJobStatusChange(); - } - $rootScope.removeJobStatusChange = $rootScope.$on('ws-jobs', function() { + $scope.$on('ws-jobs', function() { $scope.refreshJobs(); }); - if ($rootScope.removeScheduleStatusChange) { - $rootScope.removeScheduleStatusChange(); - } - $rootScope.removeScheduleStatusChange = $rootScope.$on('ws-schedules', function() { + $scope.$on('ws-schedules', function() { if (api_complete) { scheduled_scope.search('schedule'); } diff --git a/awx/ui/client/src/controllers/Projects.js b/awx/ui/client/src/controllers/Projects.js index 3ec77ecb69..0a7b1dcd64 100644 --- a/awx/ui/client/src/controllers/Projects.js +++ b/awx/ui/client/src/controllers/Projects.js @@ -86,11 +86,7 @@ export function ProjectsList ($scope, $rootScope, $location, $log, $stateParams, } }); - // Handle project update status changes - if ($rootScope.removeJobStatusChange) { - $rootScope.removeJobStatusChange(); - } - $rootScope.removeJobStatusChange = $rootScope.$on(`ws-jobs`, function(e, data) { + $scope.$on(`ws-jobs`, function(e, data) { var project; $log.debug(data); if ($scope.projects) { diff --git a/awx/ui/client/src/inventories/manage/groups/groups-list.controller.js b/awx/ui/client/src/inventories/manage/groups/groups-list.controller.js index fc7326f6d0..f9a20a8830 100644 --- a/awx/ui/client/src/inventories/manage/groups/groups-list.controller.js +++ b/awx/ui/client/src/inventories/manage/groups/groups-list.controller.js @@ -101,10 +101,7 @@ })); }; - if ($rootScope.inventoryManageStatus) { - $rootScope.inventoryManageStatus(); - } - $rootScope.inventoryManageStatus = $rootScope.$on(`ws-jobs`, function(e, data){ + $scope.$on(`ws-jobs`, function(e, data){ var group = Find({ list: $scope.groups, key: 'id', val: data.group_id }); if(data.status === 'failed' || data.status === 'successful'){ $state.reload(); diff --git a/awx/ui/client/src/job-detail/host-summary/host-summary.controller.js b/awx/ui/client/src/job-detail/host-summary/host-summary.controller.js index c49eeb3d86..4f3e1be88d 100644 --- a/awx/ui/client/src/job-detail/host-summary/host-summary.controller.js +++ b/awx/ui/client/src/job-detail/host-summary/host-summary.controller.js @@ -53,17 +53,14 @@ } // emitted by the API in the same function used to persist host summary data // JobEvent.update_host_summary_from_stats() from /awx/main.models.jobs.py - $rootScope.removeJobSummaryComplete = $rootScope.$on('ws-jobs-summary', function(e, data) { + $scope.$on('ws-jobs-summary', function(e, data) { // discard socket msgs we don't care about in this context if (parseInt($stateParams.id) === data.unified_job_id){ init(); } }); - if ($rootScope.removeJobStatusChange) { - $rootScope.removeJobStatusChange(); - } - $rootScope.removeJobStatusChange = $rootScope.$on('ws-jobs', function(e, data) { + $scope.$on('ws-jobs', function(e, data) { if (parseInt($stateParams.id) === data.unified_job_id){ $scope.status = data.status; } diff --git a/awx/ui/client/src/job-detail/job-detail.controller.js b/awx/ui/client/src/job-detail/job-detail.controller.js index d7bd9c3457..81587e325d 100644 --- a/awx/ui/client/src/job-detail/job-detail.controller.js +++ b/awx/ui/client/src/job-detail/job-detail.controller.js @@ -197,30 +197,22 @@ export default "
Changed
\n" + "Unreachable
\n" + "Failed
\n"; - function openSocket() { - if ($rootScope.removeJobEventChange) { - $rootScope.removeJobEventChange(); - } - $rootScope.removeJobEventChange = $rootScope.$on(`ws-job_events-${job_id}`, function(e, data) { - // update elapsed time on each event received - scope.job_status.elapsed = GetElapsed({ - start: scope.job.created, - end: Date.now() - }); - if (api_complete && data.id > lastEventId) { - scope.waiting = false; - data.event = data.event_name; - DigestEvent({ scope: scope, event: data }); - } - UpdateDOM({ scope: scope }); - }); - } - openSocket(); - if ($rootScope.removeJobStatusChange) { - $rootScope.removeJobStatusChange(); - } - $rootScope.removeJobStatusChange = $rootScope.$on(`ws-jobs`, function(e, data) { + scope.$on(`ws-job_events-${job_id}`, function(e, data) { + // update elapsed time on each event received + scope.job_status.elapsed = GetElapsed({ + start: scope.job.created, + end: Date.now() + }); + if (api_complete && data.id > lastEventId) { + scope.waiting = false; + data.event = data.event_name; + DigestEvent({ scope: scope, event: data }); + } + UpdateDOM({ scope: scope }); + }); + + scope.$on(`ws-jobs`, function(e, data) { // if we receive a status change event for the current job indicating the job // is finished, stop event queue processing and reload if (parseInt(data.unified_job_id, 10) === parseInt(job_id,10)) { @@ -234,10 +226,7 @@ export default } }); - if ($rootScope.removeJobSummaryComplete) { - $rootScope.removeJobSummaryComplete(); - } - $rootScope.removeJobSummaryComplete = $rootScope.$on('ws-jobs-summary', function() { + scope.$on('ws-jobs-summary', function() { // the job host summary should now be available from the API $log.debug('Trigging reload of job_host_summaries'); scope.$emit('InitialLoadComplete'); diff --git a/awx/ui/client/src/job-templates/list/job-templates-list.controller.js b/awx/ui/client/src/job-templates/list/job-templates-list.controller.js index ed5372e908..5273f1c0b4 100644 --- a/awx/ui/client/src/job-templates/list/job-templates-list.controller.js +++ b/awx/ui/client/src/job-templates/list/job-templates-list.controller.js @@ -37,11 +37,7 @@ export default view.inject(list, { mode: mode, scope: $scope }); $rootScope.flashMessage = null; - - if ($rootScope.JobStatusChange) { - $rootScope.JobStatusChange(); - } - $rootScope.JobStatusChange = $rootScope.$on(`ws-jobs`, function () { + $scope.$on(`ws-jobs`, function () { $scope.search(list.iterator); }); diff --git a/awx/ui/client/src/organizations/linkout/controllers/organizations-job-templates.controller.js b/awx/ui/client/src/organizations/linkout/controllers/organizations-job-templates.controller.js index ae1000a5c8..c9669462b5 100644 --- a/awx/ui/client/src/organizations/linkout/controllers/organizations-job-templates.controller.js +++ b/awx/ui/client/src/organizations/linkout/controllers/organizations-job-templates.controller.js @@ -21,10 +21,7 @@ export default ['$scope', '$rootScope', '$location', '$log', generator = GenerateList, orgBase = GetBasePath('organizations'); - if ($rootScope.JobStatusChange) { - $rootScope.JobStatusChange(); - } - $rootScope.JobStatusChange = $rootScope.$on(`ws-jobs`, function () { + $scope.$on(`ws-jobs`, function () { $scope.search(list.iterator); }); diff --git a/awx/ui/client/src/organizations/linkout/controllers/organizations-projects.controller.js b/awx/ui/client/src/organizations/linkout/controllers/organizations-projects.controller.js index 73d6156862..5c3fde00fc 100644 --- a/awx/ui/client/src/organizations/linkout/controllers/organizations-projects.controller.js +++ b/awx/ui/client/src/organizations/linkout/controllers/organizations-projects.controller.js @@ -86,11 +86,7 @@ export default ['$scope', '$rootScope', '$location', '$log', } }); - // Handle project update status changes - if ($rootScope.removeJobStatusChange) { - $rootScope.removeJobStatusChange(); - } - $rootScope.removeJobStatusChange = $rootScope.$on(`ws-jobs`, function(e, data) { + $scope.$on(`ws-jobs`, function(e, data) { var project; $log.debug(data); if ($scope.projects) { diff --git a/awx/ui/client/src/portal-mode/portal-mode-jobs.controller.js b/awx/ui/client/src/portal-mode/portal-mode-jobs.controller.js index 06c2339633..81d899e85f 100644 --- a/awx/ui/client/src/portal-mode/portal-mode-jobs.controller.js +++ b/awx/ui/client/src/portal-mode/portal-mode-jobs.controller.js @@ -13,12 +13,9 @@ export function PortalModeJobsController($scope, $rootScope, GetBasePath, Genera defaultUrl = GetBasePath('jobs') + '?created_by=' + $rootScope.current_user.id, pageSize = 12; - if ($rootScope.removeJobStatusChange) { - $rootScope.removeJobStatusChange(); - } - $rootScope.removeJobStatusChange = $rootScope.$on('ws-jobs', function() { + $scope.$on('ws-jobs', function() { $scope.search('job'); - }); + }); $scope.iterator = list.iterator; $scope.activeFilter = 'user'; diff --git a/awx/ui/client/src/shared/socket/socket.service.js b/awx/ui/client/src/shared/socket/socket.service.js index 59419771af..6a992d4e5f 100644 --- a/awx/ui/client/src/shared/socket/socket.service.js +++ b/awx/ui/client/src/shared/socket/socket.service.js @@ -5,9 +5,10 @@ *************************************************/ import ReconnectingWebSocket from 'reconnectingwebsocket'; export default -['$rootScope', '$location', '$log','$state', - function ($rootScope, $location, $log, $state) { - var needsResubscribing = false; +['$rootScope', '$location', '$log','$state', '$q', + function ($rootScope, $location, $log, $state, $q) { + var needsResubscribing = false, + socketPromise = $q.defer(); return { init: function() { var self = this, @@ -24,7 +25,7 @@ export default self.socket.onopen = function () { $log.debug("Websocket connection opened."); - $rootScope.socketPromise.resolve(); + socketPromise.resolve(); self.checkStatus(); if(needsResubscribing){ self.subscribe(self.getLast()); @@ -60,22 +61,40 @@ export default } }, onMessage: function(e){ + // Function called when messages are received on by the UI from + // the API over the websocket. This will route each message to + // the appropriate controller for the current $state. + e.data = e.data.replace(/\\/g, ''); + e.data = e.data.substr(0, e.data.length-1); + e.data = e.data.substr(1); $log.debug('Received From Server: ' + e.data); + var data = JSON.parse(e.data), str = ""; if(data.group_name==="jobs" && !('status' in data)){ // we know that this must have been a - // summary complete message b/c status is missing + // summary complete message b/c status is missing. + // A an object w/ group_name === "jobs" AND a 'status' key + // means it was for the event: status_changed. $log.debug('Job summary_complete ' + data.unified_job_id); - $rootScope.$emit('ws-jobs-summary', data); + $rootScope.$broadcast('ws-jobs-summary', data); return; } else if(data.group_name==="job_events"){ - str = `ws-${data.group_name}-${data.job}`; + // The naming scheme is "ws" then a + // dash (-) and the group_name, then the job ID + // ex: 'ws-jobs-