1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 16:51:11 +03:00

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.
This commit is contained in:
Chris Houseknecht 2014-06-12 12:28:28 -04:00
parent eccfe128dd
commit 3c7344e986
5 changed files with 52 additions and 68 deletions

View File

@ -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
});
};

View File

@ -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'
];

View File

@ -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();

View File

@ -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 <i class="fa fa-refresh fa-lg"></i> 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) {

View File

@ -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 }}",