diff --git a/awx/ui/static/js/app.js b/awx/ui/static/js/app.js index 2ee0160c33..bc8cda2691 100644 --- a/awx/ui/static/js/app.js +++ b/awx/ui/static/js/app.js @@ -220,6 +220,18 @@ var tower = angular.module('Tower', [ resolve: { features: ['FeaturesService', function(FeaturesService) { return FeaturesService.get(); + }], + jobEventsSocket: ['Socket', '$rootScope', function(Socket, $rootScope) { + if (!$rootScope.event_socket) { + $rootScope.event_socket = Socket({ + scope: $rootScope, + endpoint: "job_events" + }); + $rootScope.event_socket.init(); + return true; + } else { + return true; + } }] } }). @@ -231,6 +243,18 @@ var tower = angular.module('Tower', [ resolve: { features: ['FeaturesService', function(FeaturesService) { return FeaturesService.get(); + }], + jobEventsSocket: ['Socket', '$rootScope', function(Socket, $rootScope) { + if (!$rootScope.event_socket) { + $rootScope.event_socket = Socket({ + scope: $rootScope, + endpoint: "job_events" + }); + $rootScope.event_socket.init(); + return true; + } else { + return true; + } }] } }). @@ -242,6 +266,18 @@ var tower = angular.module('Tower', [ resolve: { features: ['FeaturesService', function(FeaturesService) { return FeaturesService.get(); + }], + jobEventsSocket: ['Socket', '$rootScope', function(Socket, $rootScope) { + if (!$rootScope.event_socket) { + $rootScope.event_socket = Socket({ + scope: $rootScope, + endpoint: "job_events" + }); + $rootScope.event_socket.init(); + return true; + } else { + return true; + } }] } }). @@ -942,16 +978,49 @@ var tower = angular.module('Tower', [ // Listen for job changes and issue callbacks to initiate // DOM updates function openSocket() { + var schedule_socket; + sock = Socket({ scope: $rootScope, endpoint: "jobs" }); sock.init(); sock.on("status_changed", function(data) { - $log.debug('Job ' + data.unified_job_id + ' status changed to ' + data.status); - $rootScope.$emit('JobStatusChange', data); + $log.debug('Job ' + data.unified_job_id + + ' status changed to ' + data.status + + ' send to ' + $location.$$url); + + // this acts as a router...it emits the proper + // value based on what URL the user is currently + // accessing. + if ($location.$$url === '/jobs') { + $rootScope.$emit('JobStatusChange-jobs', data); + } else if (/\/jobs\/(\d)+/.test($location.$$url)) { + $rootScope.$emit('JobStatusChange-jobDetails', data); + } else if ($location.$$url === '/home') { + $rootScope.$emit('JobStatusChange-home', data); + } else if ($location.$$url === '/portal') { + $rootScope.$emit('JobStatusChange-portal', data); + } else if ($location.$$url === '/projects') { + $rootScope.$emit('JobStatusChange-projects', data); + } else if (/\/jobs\/(\d)+\/stdout/.test($location.$$url) || + /\/ad_hoc_commands\/(\d)+/.test($location.$$url)) { + $rootScope.$emit('JobStatusChange-jobStdout', data); + } else if (/\/inventory\/(\d)+\/manage/.test($location.$$url)) { + $rootScope.$emit('JobStatusChange-inventory', data); + } }); sock.on("summary_complete", function(data) { $log.debug('Job summary_complete ' + data.unified_job_id); $rootScope.$emit('JobSummaryComplete', data); }); + + schedule_socket = Socket({ + scope: $rootScope, + endpoint: "schedules" + }); + schedule_socket.init(); + schedule_socket.on("schedule_changed", function(data) { + $log.debug('Schedule ' + data.unified_job_id + ' status changed to ' + data.status); + $rootScope.$emit('ScheduleStatusChange', data); + }); } openSocket(); diff --git a/awx/ui/static/js/controllers/Home.js b/awx/ui/static/js/controllers/Home.js index d130501828..00664fc466 100644 --- a/awx/ui/static/js/controllers/Home.js +++ b/awx/ui/static/js/controllers/Home.js @@ -115,9 +115,9 @@ Home.$inject = ['$scope', '$compile', '$routeParams', '$rootScope', '$location', * @description This controls the 'home/groups' page that is loaded from the dashboard * */ -export function HomeGroups($log, $scope, $filter, $compile, $location, $routeParams, LogViewer, HomeGroupList, GenerateList, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope, +export function HomeGroups($rootScope, $log, $scope, $filter, $compile, $location, $routeParams, LogViewer, HomeGroupList, GenerateList, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope, GetBasePath, SearchInit, PaginateInit, FormatDate, GetHostsStatusMsg, GetSyncStatusMsg, ViewUpdateStatus, Stream, GroupsEdit, Wait, - Alert, Rest, Empty, InventoryUpdate, Find, GroupsCancelUpdate, Store, Socket) { + Alert, Rest, Empty, InventoryUpdate, Find, GroupsCancelUpdate, Store) { ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior //scope. @@ -127,8 +127,7 @@ export function HomeGroups($log, $scope, $filter, $compile, $location, $routePar defaultUrl = GetBasePath('groups'), scope = $scope, modal_scope = $scope.$new(), - opt, PreviousSearchParams, - io; + opt, PreviousSearchParams; generator.inject(list, { mode: 'edit', scope: scope, breadCrumbs: true }); @@ -296,10 +295,10 @@ export function HomeGroups($log, $scope, $filter, $compile, $location, $routePar LoadBreadCrumbs(); - io = Socket({ scope: $scope, endpoint: "jobs" }); - io.init(); - $log.debug('Watching for job updates: '); - io.on("status_changed", function(data) { + if ($rootScope.removeJobStatusChange) { + $rootScope.removeJobStatusChange(); + } + $rootScope.removeJobStatusChange = $rootScope.$on('JobStatusChange-home', function(e, data) { var stat, group; if (data.group_id) { group = Find({ list: scope[list.name], key: 'id', val: data.group_id }); @@ -539,7 +538,7 @@ export function HomeGroups($log, $scope, $filter, $compile, $location, $routePar } -HomeGroups.$inject = ['$log', '$scope', '$filter', '$compile', '$location', '$routeParams', 'LogViewer', 'HomeGroupList', 'generateList', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', +HomeGroups.$inject = ['$rootScope', '$log', '$scope', '$filter', '$compile', '$location', '$routeParams', 'LogViewer', 'HomeGroupList', 'generateList', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope', 'GetBasePath', 'SearchInit', 'PaginateInit', 'FormatDate', 'GetHostsStatusMsg', 'GetSyncStatusMsg', 'ViewUpdateStatus', 'Stream', 'GroupsEdit', 'Wait', 'Alert', 'Rest', 'Empty', 'InventoryUpdate', 'Find', 'GroupsCancelUpdate', 'Store', 'Socket' ]; diff --git a/awx/ui/static/js/controllers/Inventories.js b/awx/ui/static/js/controllers/Inventories.js index 8e2a42bde3..1a24bde001 100644 --- a/awx/ui/static/js/controllers/Inventories.js +++ b/awx/ui/static/js/controllers/Inventories.js @@ -849,12 +849,11 @@ export function InventoriesManage ($log, $scope, $rootScope, $location, ViewUpdateStatus, GroupsDelete, Store, HostsEdit, HostsDelete, EditInventoryProperties, ToggleHostEnabled, Stream, ShowJobSummary, InventoryGroupsHelp, HelpDialog, ViewJob, - GroupsCopy, HostsCopy, Socket) { + GroupsCopy, HostsCopy) { var PreviousSearchParams, url, - hostScope = $scope.$new(), - io; + hostScope = $scope.$new(); ClearScope(); @@ -1095,38 +1094,33 @@ export function InventoriesManage ($log, $scope, $rootScope, $location, if ($scope.removeWatchUpdateStatus) { $scope.removeWatchUpdateStatus(); } - $scope.removeWatchUpdateStatus = $scope.$on('WatchUpdateStatus', function() { - io = Socket({ scope: $scope, endpoint: "jobs" }); - io.init(); - $log.debug('Watching for job updates: '); - io.on("status_changed", function(data) { - var stat, group; - if (data.group_id) { - group = Find({ list: $scope.groups, key: 'id', val: data.group_id }); - if (data.status === "failed" || data.status === "successful") { - if (data.group_id === $scope.selected_group_id || group) { - // job completed, fefresh all groups - $log.debug('Update completed. Refreshing the tree.'); - $scope.refreshGroups(); - } - } - else if (group) { - // incremental update, just update - $log.debug('Status of group: ' + data.group_id + ' changed to: ' + data.status); - stat = GetSyncStatusMsg({ - status: data.status, - has_inventory_sources: group.has_inventory_sources, - source: group.source - }); - $log.debug('changing tooltip to: ' + stat.tooltip); - group.status = data.status; - group.status_class = stat['class']; - group.status_tooltip = stat.tooltip; - group.launch_tooltip = stat.launch_tip; - group.launch_class = stat.launch_class; + $scope.removeWatchUpdateStatus = $scope.$on('JobStatusChange-inventory', function(data) { + var stat, group; + if (data.group_id) { + group = Find({ list: $scope.groups, key: 'id', val: data.group_id }); + if (data.status === "failed" || data.status === "successful") { + if (data.group_id === $scope.selected_group_id || group) { + // job completed, fefresh all groups + $log.debug('Update completed. Refreshing the tree.'); + $scope.refreshGroups(); } } - }); + else if (group) { + // incremental update, just update + $log.debug('Status of group: ' + data.group_id + ' changed to: ' + data.status); + stat = GetSyncStatusMsg({ + status: data.status, + has_inventory_sources: group.has_inventory_sources, + source: group.source + }); + $log.debug('changing tooltip to: ' + stat.tooltip); + group.status = data.status; + group.status_class = stat['class']; + group.status_tooltip = stat.tooltip; + group.launch_tooltip = stat.launch_tip; + group.launch_class = stat.launch_class; + } + } }); // Load group on selection @@ -1453,5 +1447,5 @@ InventoriesManage.$inject = ['$log', '$scope', '$rootScope', '$location', 'GroupsDelete', 'Store', 'HostsEdit', 'HostsDelete', 'EditInventoryProperties', 'ToggleHostEnabled', 'Stream', 'ShowJobSummary', 'InventoryGroupsHelp', 'HelpDialog', 'ViewJob', 'GroupsCopy', - 'HostsCopy', 'Socket' + 'HostsCopy' ]; diff --git a/awx/ui/static/js/controllers/JobDetail.js b/awx/ui/static/js/controllers/JobDetail.js index 9e1d435b9d..d2199b576b 100644 --- a/awx/ui/static/js/controllers/JobDetail.js +++ b/awx/ui/static/js/controllers/JobDetail.js @@ -18,7 +18,6 @@ export function JobDetailController ($location, $rootScope, $scope, $compile, $r ClearScope(); var job_id = $routeParams.id, - event_socket, scope = $scope, api_complete = false, refresh_count = 0, @@ -99,12 +98,7 @@ export function JobDetailController ($location, $rootScope, $scope, $compile, $r "
Unreachable
\n" + "Failed
\n"; function openSocket() { - event_socket = Socket({ - scope: scope, - endpoint: "job_events" - }); - event_socket.init(); - event_socket.on("job_events-" + job_id, function(data) { + $rootScope.event_socket.on("job_events-" + job_id, function(data) { if (api_complete && data.id > lastEventId) { scope.waiting = false; data.event = data.event_name; @@ -117,12 +111,12 @@ export function JobDetailController ($location, $rootScope, $scope, $compile, $r if ($rootScope.removeJobStatusChange) { $rootScope.removeJobStatusChange(); } - $rootScope.removeJobStatusChange = $rootScope.$on('JobStatusChange', function(e, data) { + $rootScope.removeJobStatusChange = $rootScope.$on('JobStatusChange-jobDetails', 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)) { if (data.status === 'failed' || data.status === 'canceled' || - data.status === 'error' || data.status === 'successful') { + data.status === 'error' || data.status === 'successful' || data.status === 'running') { $scope.liveEventProcessing = false; if ($rootScope.jobDetailInterval) { window.clearInterval($rootScope.jobDetailInterval); diff --git a/awx/ui/static/js/controllers/JobStdout.js b/awx/ui/static/js/controllers/JobStdout.js index 5f77b3a91d..5bbabd6665 100644 --- a/awx/ui/static/js/controllers/JobStdout.js +++ b/awx/ui/static/js/controllers/JobStdout.js @@ -11,7 +11,7 @@ */ -export function JobStdoutController ($location, $log, $rootScope, $scope, $compile, $routeParams, ClearScope, GetBasePath, Wait, Rest, ProcessErrors, Socket) { +export function JobStdoutController ($location, $log, $rootScope, $scope, $compile, $routeParams, ClearScope, GetBasePath, Wait, Rest, ProcessErrors) { ClearScope(); @@ -19,8 +19,6 @@ export function JobStdoutController ($location, $log, $rootScope, $scope, $compi api_complete = false, stdout_url, current_range, - event_socket, - status_socket, loaded_sections = [], event_queue = 0, auto_scroll_down=true, // programmatic scroll to bottom @@ -35,37 +33,7 @@ export function JobStdoutController ($location, $log, $rootScope, $scope, $compi function openSockets() { - status_socket = Socket({ - scope: $scope, - endpoint: "jobs" - }); - status_socket.init(); - status_socket.on("status_changed", function(data) { - if (parseInt(data.unified_job_id, 10) === parseInt(job_id,10) && $scope.job) { - $scope.job.status = data.status; - if (data.status === 'failed' || data.status === 'canceled' || - data.status === 'error' || data.status === 'successful') { - if ($rootScope.jobStdOutInterval) { - window.clearInterval($rootScope.jobStdOutInterval); - } - if (live_event_processing) { - if (loaded_sections.length === 0) { - $scope.$emit('LoadStdout'); - } - else { - getNextSection(); - } - } - live_event_processing = false; - } - } - }); - event_socket = Socket({ - scope: $scope, - endpoint: "job_events" - }); - event_socket.init(); - event_socket.on("job_events-" + job_id, function() { + $rootScope.event_socket.on("job_events-" + job_id, function() { if (api_complete) { event_queue++; } @@ -73,6 +41,30 @@ export function JobStdoutController ($location, $log, $rootScope, $scope, $compi } openSockets(); + if ($rootScope.removeJobStatusChange) { + $rootScope.removeJobStatusChange(); + } + $rootScope.removeJobStatusChange = $rootScope.$on('JobStatusChange-jobStdout', function(e, data) { + if (parseInt(data.unified_job_id, 10) === parseInt(job_id,10) && $scope.job) { + $scope.job.status = data.status; + if (data.status === 'failed' || data.status === 'canceled' || + data.status === 'error' || data.status === 'successful') { + if ($rootScope.jobStdOutInterval) { + window.clearInterval($rootScope.jobStdOutInterval); + } + if (live_event_processing) { + if (loaded_sections.length === 0) { + $scope.$emit('LoadStdout'); + } + else { + getNextSection(); + } + } + live_event_processing = false; + } + } + }); + $rootScope.jobStdOutInterval = setInterval( function() { if (event_queue > 0) { // events happened since the last check @@ -283,5 +275,4 @@ export function JobStdoutController ($location, $log, $rootScope, $scope, $compi } -JobStdoutController.$inject = [ '$location', '$log', '$rootScope', '$scope', '$compile', '$routeParams', 'ClearScope', 'GetBasePath', 'Wait', 'Rest', 'ProcessErrors', - 'Socket' ]; +JobStdoutController.$inject = [ '$location', '$log', '$rootScope', '$scope', '$compile', '$routeParams', 'ClearScope', 'GetBasePath', 'Wait', 'Rest', 'ProcessErrors']; diff --git a/awx/ui/static/js/controllers/Jobs.js b/awx/ui/static/js/controllers/Jobs.js index a0aec0953d..e6064444e0 100644 --- a/awx/ui/static/js/controllers/Jobs.js +++ b/awx/ui/static/js/controllers/Jobs.js @@ -16,7 +16,7 @@ export function JobsListController ($rootScope, $log, $scope, $compile, $routeParams, ClearScope, Breadcrumbs, LoadBreadCrumbs, LoadSchedulesScope, - LoadJobsScope, AllJobsList, ScheduledJobsList, GetChoices, GetBasePath, Wait, Socket) { + LoadJobsScope, AllJobsList, ScheduledJobsList, GetChoices, GetBasePath, Wait) { ClearScope(); @@ -24,35 +24,26 @@ export function JobsListController ($rootScope, $log, $scope, $compile, $routePa choicesCount = 0, listCount = 0, api_complete = false, - schedule_socket, - job_socket, max_rows; - function openSockets() { - job_socket = Socket({ - scope: $scope, - endpoint: "jobs" - }); - job_socket.init(); - job_socket.on("status_changed", function() { - // if (api_complete) { - jobs_scope.refreshJobs(); - // } - }); - schedule_socket = Socket({ - scope: $scope, - endpoint: "schedules" - }); - schedule_socket.init(); - schedule_socket.on("schedule_changed", function() { - if (api_complete) { - scheduled_scope.search('schedule'); - } - }); - } - LoadBreadCrumbs(); + if ($rootScope.removeJobStatusChange) { + $rootScope.removeJobStatusChange(); + } + $rootScope.removeJobStatusChange = $rootScope.$on('JobStatusChange-jobs', function() { + jobs_scope.refreshJobs(); + }); + + if ($rootScope.removeScheduleStatusChange) { + $rootScope.removeScheduleStatusChange(); + } + $rootScope.removeScheduleStatusChange = $rootScope.$on('ScheduleStatusChange', function() { + if (api_complete) { + scheduled_scope.search('schedule'); + } + }); + if ($scope.removeListLoaded) { $scope.removeListLoaded(); } @@ -60,7 +51,6 @@ export function JobsListController ($rootScope, $log, $scope, $compile, $routePa listCount++; if (listCount === 2) { api_complete = true; - openSockets(); } }); @@ -193,4 +183,4 @@ export function JobsListController ($rootScope, $log, $scope, $compile, $routePa JobsListController.$inject = ['$rootScope', '$log', '$scope', '$compile', '$routeParams', 'ClearScope', 'Breadcrumbs', 'LoadBreadCrumbs', 'LoadSchedulesScope', 'LoadJobsScope', -'AllJobsList', 'ScheduledJobsList', 'GetChoices', 'GetBasePath', 'Wait', 'Socket']; +'AllJobsList', 'ScheduledJobsList', 'GetChoices', 'GetBasePath', 'Wait']; diff --git a/awx/ui/static/js/controllers/Portal.js b/awx/ui/static/js/controllers/Portal.js index ecf4e0f38a..7e222b973d 100644 --- a/awx/ui/static/js/controllers/Portal.js +++ b/awx/ui/static/js/controllers/Portal.js @@ -86,7 +86,7 @@ export function PortalController($scope, $compile, $routeParams, $rootScope, $lo if ($rootScope.removeJobStatusChange) { $rootScope.removeJobStatusChange(); } - $rootScope.removeJobStatusChange = $rootScope.$on('JobStatusChange', function() { + $rootScope.removeJobStatusChange = $rootScope.$on('JobStatusChange-portal', function() { jobs_scope.search('portal_job'); //processEvent(event); }); diff --git a/awx/ui/static/js/controllers/Projects.js b/awx/ui/static/js/controllers/Projects.js index 82a7c05fe3..b3241de5b7 100644 --- a/awx/ui/static/js/controllers/Projects.js +++ b/awx/ui/static/js/controllers/Projects.js @@ -86,7 +86,7 @@ export function ProjectsList ($scope, $rootScope, $location, $log, $routeParams, if ($rootScope.removeJobStatusChange) { $rootScope.removeJobStatusChange(); } - $rootScope.removeJobStatusChange = $rootScope.$on('JobStatusChange', function(e, data) { + $rootScope.removeJobStatusChange = $rootScope.$on('JobStatusChange-projects', function(e, data) { var project; $log.debug(data); if ($scope.projects) { @@ -722,30 +722,6 @@ export function ProjectsEdit($scope, $rootScope, $compile, $location, $log, $rou callback: 'choicesReady' }); - // Handle project update status changes - if ($rootScope.removeJobStatusChange) { - $rootScope.removeJobStatusChange(); - } - $rootScope.removeJobStatusChange = $rootScope.$on('JobStatusChange', function(e, data) { - if ($scope.project_obj && data.project_id === $scope.project_obj.id) { - // This is the affected project - $log.debug('Received event for project: ' + $scope.project_obj.name); - $log.debug('Status changed to: ' + data.status); - // Set the status and re-evaluate the update button tooltip and class - $scope.project_obj.status = data.status; - $scope.scm_update_tooltip = "Start an SCM update"; - $scope.scm_type_class = ""; - if (data.status === 'running' || data.status === 'updating') { - $scope.scm_update_tooltip = "SCM update currently running"; - $scope.scm_type_class = "btn-disabled"; - } - if (Empty($scope.project_obj.scm_type)) { - $scope.scm_update_tooltip = 'Manual projects do not require an SCM update'; - $scope.scm_type_class = "btn-disabled"; - } - } - }); - // Save changes to the parent $scope.formSave = function () { var fld, i, params; diff --git a/awx/ui/static/js/controllers/Sockets.js b/awx/ui/static/js/controllers/Sockets.js index 4c38f6964c..d80dcae90f 100644 --- a/awx/ui/static/js/controllers/Sockets.js +++ b/awx/ui/static/js/controllers/Sockets.js @@ -80,11 +80,6 @@ export function SocketsController ($scope, $compile, ClearScope, Socket) { e.append(html); $compile(e)(job_events_scope); - schedules_socket.init(); - test_socket.init(); - jobs_socket.init(); - job_events_socket.init(); - schedules_scope.url = schedules_socket.getUrl(); test_scope.url = test_socket.getUrl(); jobs_scope.url = jobs_socket.getUrl(); diff --git a/awx/ui/static/js/services/job-status-graph-data.js b/awx/ui/static/js/services/job-status-graph-data.js index 492cda20fe..9c92eafd5d 100644 --- a/awx/ui/static/js/services/job-status-graph-data.js +++ b/awx/ui/static/js/services/job-status-graph-data.js @@ -38,7 +38,7 @@ function JobStatusGraphData(Rest, getBasePath, processErrors, $rootScope, $q) { destroyWatcher: angular.noop, setupWatcher: function(period, jobType) { this.destroyWatcher = - $rootScope.$on('JobStatusChange', function() { + $rootScope.$on('JobStatusChange-home', function() { getData(period, jobType).then(function(result) { $rootScope. $broadcast('DataReceived:JobStatusGraph', diff --git a/awx/ui/static/js/widgets/DashboardJobs.js b/awx/ui/static/js/widgets/DashboardJobs.js index ca4affefd5..1eeb44d040 100644 --- a/awx/ui/static/js/widgets/DashboardJobs.js +++ b/awx/ui/static/js/widgets/DashboardJobs.js @@ -48,7 +48,7 @@ angular.module('DashboardJobsWidget', ['RestServices', 'Utilities']) e.html(html); $compile(e)(scope); - $rootScope.$on('JobStatusChange', function() { + $rootScope.$on('JobStatusChange-home', function() { jobs_scope.refreshJobs(); }); diff --git a/awx/ui/tests/unit/services/job-status-graph-data-test.js b/awx/ui/tests/unit/services/job-status-graph-data-test.js index 9ec9e3f9be..42babc9ee8 100644 --- a/awx/ui/tests/unit/services/job-status-graph-data-test.js +++ b/awx/ui/tests/unit/services/job-status-graph-data-test.js @@ -58,7 +58,7 @@ describeModule('DashboardGraphs') $rootScope.$on('DataReceived:JobStatusGraph', function(e, data) { result.resolve(data); }); - $rootScope.$emit('JobStatusChange'); + $rootScope.$emit('JobStatusChange-home'); restStub.succeed({ data: expected }); restStub.flush(); }]);