Merge pull request #5104 from jaredevantabor/inventory-manage-sockets

Websocket data returns new data, without refreshing the entire page
This commit is contained in:
Jared Tabor 2017-02-01 11:07:35 -08:00 committed by GitHub
commit b56db8bc40
6 changed files with 51 additions and 21 deletions

View File

@ -13,7 +13,7 @@
export function JobsListController($state, $rootScope, $log, $scope, $compile, $stateParams,
ClearScope, Find, DeleteJob, RelaunchJob, AllJobsList, ScheduledJobsList, GetBasePath, Dataset) {
ClearScope, Find, DeleteJob, RelaunchJob, AllJobsList, ScheduledJobsList, GetBasePath, Dataset, qs) {
ClearScope();
@ -93,10 +93,6 @@ export function JobsListController($state, $rootScope, $log, $scope, $compile, $
RelaunchJob({ scope: $scope, id: typeId, type: job.type, name: job.name });
};
$scope.refreshJobs = function() {
$state.go('.', null, { reload: true });
};
$scope.viewJobDetails = function(job) {
var goToJobDetails = function(state) {
@ -126,7 +122,12 @@ export function JobsListController($state, $rootScope, $log, $scope, $compile, $
};
$scope.$on('ws-jobs', function(){
$scope.refreshJobs();
let path = GetBasePath(list.basePath) || GetBasePath(list.name);
qs.search(path, $state.params[`${list.iterator}_search`])
.then(function(searchResponse) {
$scope[`${list.iterator}_dataset`] = searchResponse.data;
$scope[list.name] = $scope[`${list.iterator}_dataset`].results;
});
});
$scope.$on('ws-schedules', function(){
@ -135,5 +136,5 @@ export function JobsListController($state, $rootScope, $log, $scope, $compile, $
}
JobsListController.$inject = ['$state', '$rootScope', '$log', '$scope', '$compile', '$stateParams',
'ClearScope', 'Find', 'DeleteJob', 'RelaunchJob', 'AllJobsList', 'ScheduledJobsList', 'GetBasePath', 'Dataset'
'ClearScope', 'Find', 'DeleteJob', 'RelaunchJob', 'AllJobsList', 'ScheduledJobsList', 'GetBasePath', 'Dataset','QuerySet'
];

View File

@ -6,10 +6,10 @@
export default
['$scope', '$rootScope', '$state', '$stateParams', 'InventoryGroups', 'generateList', 'InventoryUpdate',
'GroupManageService', 'GroupsCancelUpdate', 'ViewUpdateStatus', 'rbacUiControlService', 'GetBasePath',
'InventoryManageService', 'groupsUrl', 'GetSyncStatusMsg', 'GetHostsStatusMsg', 'groupsDataset', 'Find',
'InventoryManageService', 'groupsUrl', 'GetSyncStatusMsg', 'GetHostsStatusMsg', 'groupsDataset', 'Find', 'QuerySet',
function($scope, $rootScope, $state, $stateParams, InventoryGroups, generateList, InventoryUpdate,
GroupManageService, GroupsCancelUpdate, ViewUpdateStatus, rbacUiControlService, GetBasePath,
InventoryManageService, groupsUrl, GetSyncStatusMsg, GetHostsStatusMsg, groupsDataset, Find){
InventoryManageService, groupsUrl, GetSyncStatusMsg, GetHostsStatusMsg, groupsDataset, Find, qs){
let list = InventoryGroups;
@ -160,7 +160,20 @@
}
if(data.status === 'failed' || data.status === 'successful'){
$state.reload();
let path;
if($stateParams && $stateParams.group && $stateParams.group.length > 0) {
path = GetBasePath('groups') + _.last($stateParams.group) + '/children';
}
else {
//reaches here if the user is on the root level group
path = GetBasePath('inventory') + $stateParams.inventory_id + '/root_groups';
}
qs.search(path, $state.params[`${list.iterator}_search`])
.then(function(searchResponse) {
$scope[`${list.iterator}_dataset`] = searchResponse.data;
$scope[list.name] = $scope[`${list.iterator}_dataset`].results;
_.forEach($scope[list.name], buildStatusIndicators);
});
} else {
var status = GetSyncStatusMsg({
status: data.status,

View File

@ -5,9 +5,9 @@
*************************************************/
export default
['$scope', '$rootScope', '$state', '$stateParams', 'InventoryHosts', 'generateList', 'InventoryManageService', 'HostManageService',
'hostsUrl', 'SetStatus', 'Prompt', 'Wait', 'inventoryData', '$filter', 'hostsDataset', 'GetBasePath', 'rbacUiControlService',
'hostsUrl', 'SetStatus', 'Prompt', 'Wait', 'inventoryData', '$filter', 'hostsDataset', 'GetBasePath', 'rbacUiControlService', 'QuerySet',
function($scope, $rootScope, $state, $stateParams, InventoryHosts, generateList, InventoryManageService, HostManageService,
hostsUrl, SetStatus, Prompt, Wait, inventoryData, $filter, hostsDataset, GetBasePath, rbacUiControlService){
hostsUrl, SetStatus, Prompt, Wait, inventoryData, $filter, hostsDataset, GetBasePath, rbacUiControlService, qs){
var list = InventoryHosts;
init();
@ -32,6 +32,17 @@
host: host}));
});
$scope.$on(`ws-jobs`, function(e, data){
if(data.status === 'failed' || data.status === 'successful'){
let path = hostsUrl;
qs.search(path, $state.params[`${list.iterator}_search`])
.then(function(searchResponse) {
$scope[`${list.iterator}_dataset`] = searchResponse.data;
$scope[list.name] = $scope[`${list.iterator}_dataset`].results;
});
}
});
// The ncy breadcrumb directive will look at this attribute when attempting to bind to the correct scope.
// In this case, we don't want to incidentally bind to this scope when editing a host or a group. See:
// https://github.com/ncuillery/angular-breadcrumb/issues/42 for a little more information on the

View File

@ -7,18 +7,22 @@
export default ['$scope', '$rootScope', '$location', '$log',
'$stateParams', 'Rest', 'Alert', 'Prompt', 'ReturnToCaller', 'ClearScope', 'ProcessErrors',
'GetBasePath', 'JobTemplateForm', 'InitiatePlaybookRun', 'Wait',
'$compile', '$state', 'OrgJobTemplateList', 'OrgJobTemplateDataset',
'$compile', '$state', 'OrgJobTemplateList', 'OrgJobTemplateDataset', 'QuerySet',
function($scope, $rootScope, $location, $log,
$stateParams, Rest, Alert, Prompt, ReturnToCaller, ClearScope, ProcessErrors,
GetBasePath, JobTemplateForm, InitiatePlaybookRun, Wait,
$compile, $state, OrgJobTemplateList, Dataset) {
$compile, $state, OrgJobTemplateList, Dataset, qs) {
var list = OrgJobTemplateList,
orgBase = GetBasePath('organizations');
$scope.$on(`ws-jobs`, function () {
// @issue old search
//$scope.search(list.iterator);
let path = GetBasePath(list.basePath) || GetBasePath(list.name);
qs.search(path, $state.params[`${list.iterator}_search`])
.then(function(searchResponse) {
$scope[`${list.iterator}_dataset`] = searchResponse.data;
$scope[list.name] = $scope[`${list.iterator}_dataset`].results;
});
});
init();

View File

@ -9,7 +9,12 @@ export function PortalModeJobsController($scope, $rootScope, $state, $stateParam
var list = PortalJobsList;
$scope.$on('ws-jobs', function() {
$state.go('.', null, { reload: true });
let path = GetBasePath(list.basePath) || GetBasePath(list.name);
qs.search(path, $state.params[`${list.iterator}_search`])
.then(function(searchResponse) {
$scope[`${list.iterator}_dataset`] = searchResponse.data;
$scope[list.name] = $scope[`${list.iterator}_dataset`].results;
});
});
init();

View File

@ -72,10 +72,6 @@ export default ['$scope', '$rootScope', '$location', '$stateParams', 'Rest',
$scope.$on(`ws-jobs`, function () {
// @issue - this is no longer quite as ham-fisted but I'd like for someone else to take a peek
// calling $state.reload(); here was problematic when launching a job because job launch also
// attempts to transition the state and they were squashing each other.
let path = GetBasePath(list.basePath) || GetBasePath(list.name);
qs.search(path, $state.params[`${list.iterator}_search`])
.then(function(searchResponse) {