From 3c7344e9869eca142f4dcae36be7a3361c0555e2 Mon Sep 17 00:00:00 2001 From: Chris Houseknecht Date: Thu, 12 Jun 2014 12:28:28 -0400 Subject: [PATCH] Fixed inventory real-time updates After bringing inventory changes from 1.4.11 forward real-time updates were not being handled by new inventory edit controller. --- awx/ui/static/js/controllers/Home.js | 2 +- awx/ui/static/js/controllers/Inventories.js | 50 +++++++++++++++-- awx/ui/static/js/helpers/Groups.js | 4 +- awx/ui/static/js/helpers/JobSubmission.js | 62 +-------------------- awx/ui/static/js/lists/InventoryGroups.js | 2 +- 5 files changed, 52 insertions(+), 68 deletions(-) diff --git a/awx/ui/static/js/controllers/Home.js b/awx/ui/static/js/controllers/Home.js index a8b6afcba9..edb51ca0b4 100644 --- a/awx/ui/static/js/controllers/Home.js +++ b/awx/ui/static/js/controllers/Home.js @@ -326,7 +326,7 @@ function HomeGroups($scope, $filter, $compile, $location, $routeParams, LogViewe scope.groups = scope.home_groups; ViewUpdateStatus({ scope: scope, - tree_id: id + id: id }); }; diff --git a/awx/ui/static/js/controllers/Inventories.js b/awx/ui/static/js/controllers/Inventories.js index 252acb5e2e..b9557f085b 100644 --- a/awx/ui/static/js/controllers/Inventories.js +++ b/awx/ui/static/js/controllers/Inventories.js @@ -481,11 +481,11 @@ InventoriesAdd.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log -function InventoriesEdit ($scope, $location, $routeParams, $compile, GenerateList, ClearScope, Empty, Wait, Rest, Alert, LoadBreadCrumbs, GetBasePath, ProcessErrors, +function InventoriesEdit ($log, $scope, $location, $routeParams, $compile, GenerateList, ClearScope, Empty, Wait, Rest, Alert, LoadBreadCrumbs, GetBasePath, ProcessErrors, Breadcrumbs, InventoryGroups, InjectHosts, Find, HostsReload, SearchInit, PaginateInit, GetSyncStatusMsg, GetHostsStatusMsg, GroupsEdit, InventoryUpdate, GroupsCancelUpdate, ViewUpdateStatus, GroupsDelete, Store, HostsEdit, HostsDelete, EditInventoryProperties, ToggleHostEnabled, Stream, ShowJobSummary, InventoryGroupsHelp, HelpDialog, ViewJob, WatchInventoryWindowResize, GetHostContainerRows, GetGroupContainerRows, GetGroupContainerHeight, - GroupsCopy, HostsCopy) + GroupsCopy, HostsCopy, Socket) { var PreviousSearchParams, @@ -600,9 +600,12 @@ function InventoriesEdit ($scope, $location, $routeParams, $compile, GenerateLis pageSize: rows }); + // Load data SearchInit({ scope: $scope, set: 'groups', list: InventoryGroups, url: $scope.inventory.related.root_groups }); PaginateInit({ scope: $scope, list: InventoryGroups , url: $scope.inventory.related.root_groups, pageSize: rows }); $scope.search(InventoryGroups.iterator, null, true); + + $scope.$emit('WatchUpdateStatus'); // init socket io conneciton and start watching for status updates }); if ($scope.removePostRefresh) { @@ -669,6 +672,44 @@ function InventoriesEdit ($scope, $location, $routeParams, $compile, GenerateLis ' GET returned status: ' + status }); }); + // start watching for real-time updates + if ($scope.removeWatchUpdateStatus) { + $scope.removeWatchUpdateStatus(); + } + $scope.removeWatchUpdateStatus = $scope.$on('WatchUpdateStatus', function() { + var 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; + } + } + }); + }); + // Load group on selection function loadGroups(url) { SearchInit({ scope: $scope, set: 'groups', list: InventoryGroups, url: url }); @@ -977,12 +1018,11 @@ function InventoriesEdit ($scope, $location, $routeParams, $compile, GenerateLis $scope.removeGroupDeleteCompleted = $scope.$on('GroupDeleteCompleted', function() { $scope.refreshGroups(); }); - } -InventoriesEdit.$inject = ['$scope', '$location', '$routeParams', '$compile', 'GenerateList', 'ClearScope', 'Empty', 'Wait', 'Rest', 'Alert', 'LoadBreadCrumbs', +InventoriesEdit.$inject = ['$log', '$scope', '$location', '$routeParams', '$compile', 'GenerateList', 'ClearScope', 'Empty', 'Wait', 'Rest', 'Alert', 'LoadBreadCrumbs', 'GetBasePath', 'ProcessErrors', 'Breadcrumbs', 'InventoryGroups', 'InjectHosts', 'Find', 'HostsReload', 'SearchInit', 'PaginateInit', 'GetSyncStatusMsg', 'GetHostsStatusMsg', 'GroupsEdit', 'InventoryUpdate', 'GroupsCancelUpdate', 'ViewUpdateStatus', 'GroupsDelete', 'Store', 'HostsEdit', 'HostsDelete', 'EditInventoryProperties', 'ToggleHostEnabled', 'Stream', 'ShowJobSummary', 'InventoryGroupsHelp', 'HelpDialog', 'ViewJob', 'WatchInventoryWindowResize', - 'GetHostContainerRows', 'GetGroupContainerRows', 'GetGroupContainerHeight', 'GroupsCopy', 'HostsCopy' + 'GetHostContainerRows', 'GetGroupContainerRows', 'GetGroupContainerHeight', 'GroupsCopy', 'HostsCopy', 'Socket' ]; \ No newline at end of file diff --git a/awx/ui/static/js/helpers/Groups.js b/awx/ui/static/js/helpers/Groups.js index f21a4e0df6..e7d9c04b47 100644 --- a/awx/ui/static/js/helpers/Groups.js +++ b/awx/ui/static/js/helpers/Groups.js @@ -53,8 +53,8 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', ' return function (params) { var scope = params.scope, - tree_id = params.tree_id, - group = Find({ list: scope.groups, key: 'id', val: tree_id }); + group_id = params.group_id, + group = Find({ list: scope.groups, key: 'id', val: group_id }); if (scope.removeSourceReady) { scope.removeSourceReady(); diff --git a/awx/ui/static/js/helpers/JobSubmission.js b/awx/ui/static/js/helpers/JobSubmission.js index b5a1818220..aeda2d677f 100644 --- a/awx/ui/static/js/helpers/JobSubmission.js +++ b/awx/ui/static/js/helpers/JobSubmission.js @@ -613,71 +613,15 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi var scope = params.scope, url = params.url, - //group_id = params.group_id, - //tree_id = params.tree_id, - //base = $location.path().replace(/^\//, '').split('/')[0], inventory_source; - /*if (scope.removeHostReloadComplete) { - scope.removeHostReloadComplete(); - } - scope.removeHostReloadComplete = scope.$on('HostReloadComplete', function () { - //Wait('stop'); - Alert('Update Started', 'Your request to start the inventory sync process was submitted. Monitor progress ' + - 'by clicking the button.', 'alert-info'); - if (scope.removeHostReloadComplete) { - scope.removeHostReloadComplete(); - } - });*/ - - /*function getJobID(url) { - var result=''; - url.split(/\//).every(function(path) { - if (/^\d+$/.test(path)) { - result = path; - return false; - } - return true; - }); - return result; - }*/ - if (scope.removeUpdateSubmitted) { scope.removeUpdateSubmitted(); } scope.removeUpdateSubmitted = scope.$on('UpdateSubmitted', function () { - // Get the current job - /*var path = url.replace(/update\/$/,''); - Rest.setUrl(path); - Rest.get() - .success(function(data) { - if (data.related.current_job) { - scope.$emit('WatchUpdateStatus', getJobID(data.related.current_job), group_id, tree_id); - } - else { - Wait('stop'); - } - }) - .error(function(data, status) { - ProcessErrors(scope, data, status, null, { hdr: 'Error!', - msg: 'Failed to get inventory source ' + url + ' GET returned: ' + status }); - }); - */ - //console.log('job submitted. callback returned: '); - //console.log(data); - /*setTimeout(function() { - if (base === 'jobs') { - scope.refreshJobs(); - } - else if (scope.refreshGroups) { - scope.selected_tree_id = tree_id; - scope.selected_group_id = group_id; - scope.refreshGroups(); - } else if (scope.refresh) { - scope.refresh(); - } - scope.$emit('HostReloadComplete'); - }, 300);*/ + Wait('stop'); + // No need to do anything else. The caller should be connected to the socket server and + // handling real-time updates }); if (scope.removePromptForPasswords) { diff --git a/awx/ui/static/js/lists/InventoryGroups.js b/awx/ui/static/js/lists/InventoryGroups.js index cc351a04ca..ed147ae0f1 100644 --- a/awx/ui/static/js/lists/InventoryGroups.js +++ b/awx/ui/static/js/lists/InventoryGroups.js @@ -98,7 +98,7 @@ angular.module('InventoryGroupsDefinition', []) sync_status: { mode: 'all', - ngClick: "viewUpdateStatus(group.id, group.group_id)", + ngClick: "viewUpdateStatus(group.id)", awToolTip: "{{ group.status_tooltip }}", dataTipWatch: "group.status_tooltip", iconClass: "{{ 'fa icon-cloud-' + group.status_class }}",