mirror of
https://github.com/ansible/awx.git
synced 2026-03-10 22:19:28 -02:30
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:
@@ -326,7 +326,7 @@ function HomeGroups($scope, $filter, $compile, $location, $routeParams, LogViewe
|
|||||||
scope.groups = scope.home_groups;
|
scope.groups = scope.home_groups;
|
||||||
ViewUpdateStatus({
|
ViewUpdateStatus({
|
||||||
scope: scope,
|
scope: scope,
|
||||||
tree_id: id
|
id: id
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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,
|
Breadcrumbs, InventoryGroups, InjectHosts, Find, HostsReload, SearchInit, PaginateInit, GetSyncStatusMsg, GetHostsStatusMsg, GroupsEdit, InventoryUpdate,
|
||||||
GroupsCancelUpdate, ViewUpdateStatus, GroupsDelete, Store, HostsEdit, HostsDelete, EditInventoryProperties, ToggleHostEnabled, Stream, ShowJobSummary,
|
GroupsCancelUpdate, ViewUpdateStatus, GroupsDelete, Store, HostsEdit, HostsDelete, EditInventoryProperties, ToggleHostEnabled, Stream, ShowJobSummary,
|
||||||
InventoryGroupsHelp, HelpDialog, ViewJob, WatchInventoryWindowResize, GetHostContainerRows, GetGroupContainerRows, GetGroupContainerHeight,
|
InventoryGroupsHelp, HelpDialog, ViewJob, WatchInventoryWindowResize, GetHostContainerRows, GetGroupContainerRows, GetGroupContainerHeight,
|
||||||
GroupsCopy, HostsCopy)
|
GroupsCopy, HostsCopy, Socket)
|
||||||
{
|
{
|
||||||
|
|
||||||
var PreviousSearchParams,
|
var PreviousSearchParams,
|
||||||
@@ -600,9 +600,12 @@ function InventoriesEdit ($scope, $location, $routeParams, $compile, GenerateLis
|
|||||||
pageSize: rows
|
pageSize: rows
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Load data
|
||||||
SearchInit({ scope: $scope, set: 'groups', list: InventoryGroups, url: $scope.inventory.related.root_groups });
|
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 });
|
PaginateInit({ scope: $scope, list: InventoryGroups , url: $scope.inventory.related.root_groups, pageSize: rows });
|
||||||
$scope.search(InventoryGroups.iterator, null, true);
|
$scope.search(InventoryGroups.iterator, null, true);
|
||||||
|
|
||||||
|
$scope.$emit('WatchUpdateStatus'); // init socket io conneciton and start watching for status updates
|
||||||
});
|
});
|
||||||
|
|
||||||
if ($scope.removePostRefresh) {
|
if ($scope.removePostRefresh) {
|
||||||
@@ -669,6 +672,44 @@ function InventoriesEdit ($scope, $location, $routeParams, $compile, GenerateLis
|
|||||||
' GET returned status: ' + status });
|
' 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
|
// Load group on selection
|
||||||
function loadGroups(url) {
|
function loadGroups(url) {
|
||||||
SearchInit({ scope: $scope, set: 'groups', list: InventoryGroups, url: 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.removeGroupDeleteCompleted = $scope.$on('GroupDeleteCompleted', function() {
|
||||||
$scope.refreshGroups();
|
$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',
|
'GetBasePath', 'ProcessErrors', 'Breadcrumbs', 'InventoryGroups', 'InjectHosts', 'Find', 'HostsReload', 'SearchInit', 'PaginateInit', 'GetSyncStatusMsg',
|
||||||
'GetHostsStatusMsg', 'GroupsEdit', 'InventoryUpdate', 'GroupsCancelUpdate', 'ViewUpdateStatus', 'GroupsDelete', 'Store', 'HostsEdit', 'HostsDelete',
|
'GetHostsStatusMsg', 'GroupsEdit', 'InventoryUpdate', 'GroupsCancelUpdate', 'ViewUpdateStatus', 'GroupsDelete', 'Store', 'HostsEdit', 'HostsDelete',
|
||||||
'EditInventoryProperties', 'ToggleHostEnabled', 'Stream', 'ShowJobSummary', 'InventoryGroupsHelp', 'HelpDialog', 'ViewJob', 'WatchInventoryWindowResize',
|
'EditInventoryProperties', 'ToggleHostEnabled', 'Stream', 'ShowJobSummary', 'InventoryGroupsHelp', 'HelpDialog', 'ViewJob', 'WatchInventoryWindowResize',
|
||||||
'GetHostContainerRows', 'GetGroupContainerRows', 'GetGroupContainerHeight', 'GroupsCopy', 'HostsCopy'
|
'GetHostContainerRows', 'GetGroupContainerRows', 'GetGroupContainerHeight', 'GroupsCopy', 'HostsCopy', 'Socket'
|
||||||
];
|
];
|
||||||
@@ -53,8 +53,8 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
|
|||||||
return function (params) {
|
return function (params) {
|
||||||
|
|
||||||
var scope = params.scope,
|
var scope = params.scope,
|
||||||
tree_id = params.tree_id,
|
group_id = params.group_id,
|
||||||
group = Find({ list: scope.groups, key: 'id', val: tree_id });
|
group = Find({ list: scope.groups, key: 'id', val: group_id });
|
||||||
|
|
||||||
if (scope.removeSourceReady) {
|
if (scope.removeSourceReady) {
|
||||||
scope.removeSourceReady();
|
scope.removeSourceReady();
|
||||||
|
|||||||
@@ -613,71 +613,15 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
|
|||||||
|
|
||||||
var scope = params.scope,
|
var scope = params.scope,
|
||||||
url = params.url,
|
url = params.url,
|
||||||
//group_id = params.group_id,
|
|
||||||
//tree_id = params.tree_id,
|
|
||||||
//base = $location.path().replace(/^\//, '').split('/')[0],
|
|
||||||
inventory_source;
|
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) {
|
if (scope.removeUpdateSubmitted) {
|
||||||
scope.removeUpdateSubmitted();
|
scope.removeUpdateSubmitted();
|
||||||
}
|
}
|
||||||
scope.removeUpdateSubmitted = scope.$on('UpdateSubmitted', function () {
|
scope.removeUpdateSubmitted = scope.$on('UpdateSubmitted', function () {
|
||||||
// Get the current job
|
Wait('stop');
|
||||||
/*var path = url.replace(/update\/$/,'');
|
// No need to do anything else. The caller should be connected to the socket server and
|
||||||
Rest.setUrl(path);
|
// handling real-time updates
|
||||||
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);*/
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (scope.removePromptForPasswords) {
|
if (scope.removePromptForPasswords) {
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ angular.module('InventoryGroupsDefinition', [])
|
|||||||
|
|
||||||
sync_status: {
|
sync_status: {
|
||||||
mode: 'all',
|
mode: 'all',
|
||||||
ngClick: "viewUpdateStatus(group.id, group.group_id)",
|
ngClick: "viewUpdateStatus(group.id)",
|
||||||
awToolTip: "{{ group.status_tooltip }}",
|
awToolTip: "{{ group.status_tooltip }}",
|
||||||
dataTipWatch: "group.status_tooltip",
|
dataTipWatch: "group.status_tooltip",
|
||||||
iconClass: "{{ 'fa icon-cloud-' + group.status_class }}",
|
iconClass: "{{ 'fa icon-cloud-' + group.status_class }}",
|
||||||
|
|||||||
Reference in New Issue
Block a user