Inventory sources socket work. Refactoring sources/factories. Small fixes to inventory sync stdout

This commit is contained in:
Michael Abashian 2017-04-28 14:49:17 -04:00 committed by Jared Tabor
parent 11f3f057f6
commit fcc70f69fa
19 changed files with 146 additions and 539 deletions

View File

@ -6,11 +6,11 @@
export default ['$state', '$stateParams', '$scope', 'GroupForm',
'ParseTypeChange', 'GenerateForm', 'inventoryData', 'GroupManageService',
'GetChoices', 'GetBasePath', 'CreateSelect2', 'GetSourceTypeOptions',
'GetChoices', 'GetBasePath', 'CreateSelect2',
'rbacUiControlService', 'ToJSON',
function($state, $stateParams, $scope, GroupForm, ParseTypeChange,
GenerateForm, inventoryData, GroupManageService, GetChoices,
GetBasePath, CreateSelect2, GetSourceTypeOptions, rbacUiControlService,
GetBasePath, CreateSelect2, rbacUiControlService,
ToJSON) {
let form = GroupForm;

View File

@ -5,9 +5,9 @@
*************************************************/
export default ['$state', '$stateParams', '$scope', 'ParseVariableString', 'rbacUiControlService', 'ToJSON',
'ParseTypeChange', 'GroupManageService', 'GetChoices', 'GetBasePath', 'CreateSelect2', 'GetSourceTypeOptions', 'groupData',
'ParseTypeChange', 'GroupManageService', 'GetChoices', 'GetBasePath', 'CreateSelect2', 'groupData',
function($state, $stateParams, $scope, ParseVariableString, rbacUiControlService, ToJSON,
ParseTypeChange, GroupManageService, GetChoices, GetBasePath, CreateSelect2, GetSourceTypeOptions, groupData) {
ParseTypeChange, GroupManageService, GetChoices, GetBasePath, CreateSelect2, groupData) {
init();

View File

@ -1,37 +0,0 @@
export default
function GetSourceTypeOptions(Rest, ProcessErrors, GetBasePath) {
return function(params) {
var scope = params.scope,
variable = params.variable;
if (scope[variable] === undefined) {
scope[variable] = [];
Rest.setUrl(GetBasePath('inventory_sources'));
Rest.options()
.success(function (data) {
var i, choices = data.actions.GET.source.choices;
for (i = 0; i < choices.length; i++) {
if (choices[i][0] !== 'file') {
scope[variable].push({
label: choices[i][1],
value: choices[i][0]
});
}
}
scope.cloudCredentialRequired = false;
scope.$emit('sourceTypeOptionsReady');
})
.error(function (data, status) {
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Failed to retrieve options for inventory_sources.source. OPTIONS status: ' + status
});
});
}
};
}
GetSourceTypeOptions.$inject =
[ 'Rest',
'ProcessErrors',
'GetBasePath'
];

View File

@ -1,77 +0,0 @@
export default
function GetSyncStatusMsg(Empty) {
return function(params) {
var status = params.status,
source = params.source,
has_inventory_sources = params.has_inventory_sources,
launch_class = '',
launch_tip = 'Start sync process',
schedule_tip = 'Schedule future inventory syncs',
stat, stat_class, status_tip;
stat = status;
stat_class = stat;
switch (status) {
case 'never updated':
stat = 'never';
stat_class = 'na';
status_tip = 'Sync not performed. Click <i class="fa fa-refresh"></i> to start it now.';
break;
case 'none':
case 'ok':
case '':
launch_class = 'btn-disabled';
stat = 'n/a';
stat_class = 'na';
status_tip = 'Cloud source not configured. Click <i class="fa fa-pencil"></i> to update.';
launch_tip = 'Cloud source not configured.';
break;
case 'canceled':
status_tip = 'Sync canceled. Click to view log.';
break;
case 'failed':
status_tip = 'Sync failed. Click to view log.';
break;
case 'successful':
status_tip = 'Sync completed. Click to view log.';
break;
case 'pending':
status_tip = 'Sync pending.';
launch_class = "btn-disabled";
launch_tip = "Sync pending";
break;
case 'updating':
case 'running':
launch_class = "btn-disabled";
launch_tip = "Sync running";
status_tip = "Sync running. Click to view log.";
break;
}
if (has_inventory_sources && Empty(source)) {
// parent has a source, therefore this group should not have a source
launch_class = "btn-disabled";
status_tip = 'Managed by an external cloud source.';
launch_tip = 'Can only be updated by running a sync on the parent group.';
}
if (has_inventory_sources === false && Empty(source)) {
launch_class = 'btn-disabled';
status_tip = 'Cloud source not configured. Click <i class="fa fa-pencil"></i> to update.';
launch_tip = 'Cloud source not configured.';
}
return {
"class": stat_class,
"tooltip": status_tip,
"status": stat,
"launch_class": launch_class,
"launch_tip": launch_tip,
"schedule_tip": schedule_tip
};
};
}
GetSyncStatusMsg.$inject =
[ 'Empty' ];

View File

@ -1,81 +0,0 @@
export default
function GroupsCancelUpdate(Empty, Rest, ProcessErrors, Alert, Wait, Find) {
return function(params) {
var scope = params.scope,
id = params.id,
group = params.group;
if (scope.removeCancelUpdate) {
scope.removeCancelUpdate();
}
scope.removeCancelUpdate = scope.$on('CancelUpdate', function (e, url) {
// Cancel the update process
Rest.setUrl(url);
Rest.post()
.success(function () {
Wait('stop');
//Alert('Inventory Sync Cancelled', 'Request to cancel the sync process was submitted to the task manger. ' +
// 'Click the <i class="fa fa-refresh fa-lg"></i> button to monitor the status.', 'alert-info');
})
.error(function (data, status) {
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Call to ' + url + ' failed. POST status: ' + status
});
});
});
if (scope.removeCheckCancel) {
scope.removeCheckCancel();
}
scope.removeCheckCancel = scope.$on('CheckCancel', function (e, last_update, current_update) {
// Check that we have access to cancelling an update
var url = (current_update) ? current_update : last_update;
url += 'cancel/';
Rest.setUrl(url);
Rest.get()
.success(function (data) {
if (data.can_cancel) {
scope.$emit('CancelUpdate', url);
//} else {
// Wait('stop');
// Alert('Cancel Inventory Sync', 'The sync process completed. Click the <i class="fa fa-refresh fa-lg"></i> button to view ' +
// 'the latest status.', 'alert-info');
}
else {
Wait('stop');
}
})
.error(function (data, status) {
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Call to ' + url + ' failed. GET status: ' + status
});
});
});
// Cancel the update process
if (Empty(group)) {
group = Find({ list: scope.groups, key: 'id', val: id });
scope.selected_group_id = group.id;
}
if (group && (group.status === 'running' || group.status === 'pending')) {
// We found the group, and there is a running update
Wait('start');
Rest.setUrl(group.related.inventory_source);
Rest.get()
.success(function (data) {
scope.$emit('CheckCancel', data.related.last_update, data.related.current_update);
})
.error(function (data, status) {
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Call to ' + group.related.inventory_source + ' failed. GET status: ' + status
});
});
}
};
}
GroupsCancelUpdate.$inject =
[ 'Empty', 'Rest', 'ProcessErrors',
'Alert', 'Wait', 'Find'
];

View File

@ -1,46 +0,0 @@
export default
function ViewUpdateStatus($state, Rest, ProcessErrors, Alert, Wait, Empty, Find) {
return function(params) {
var scope = params.scope,
group_id = params.group_id,
group = Find({ list: scope.groups, key: 'id', val: group_id });
if (scope.removeSourceReady) {
scope.removeSourceReady();
}
scope.removeSourceReady = scope.$on('SourceReady', function(e, source) {
// Get the ID from the correct summary field
var update_id = (source.summary_fields.current_update) ? source.summary_fields.current_update.id : source.summary_fields.last_update.id;
$state.go('inventorySyncStdout', {id: update_id});
});
if (group) {
if (Empty(group.source)) {
// do nothing
} else if (Empty(group.status) || group.status === "never updated") {
Alert('No Status Available', '<div>An inventory sync has not been performed for the selected group. Start the process by ' +
'clicking the <i class="fa fa-refresh"></i> button.</div>', 'alert-info', null, null, null, null, true);
} else {
Wait('start');
Rest.setUrl(group.related.inventory_source);
Rest.get()
.success(function (data) {
scope.$emit('SourceReady', data);
})
.error(function (data, status) {
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Failed to retrieve inventory source: ' + group.related.inventory_source +
' GET returned status: ' + status });
});
}
}
};
}
ViewUpdateStatus.$inject =
[ '$state', 'Rest', 'ProcessErrors',
'Alert', 'Wait', 'Empty', 'Find'
];

View File

@ -5,11 +5,11 @@
*************************************************/
export default
['$scope', '$rootScope', '$state', '$stateParams', 'GroupList', 'InventoryUpdate',
'GroupManageService', 'GroupsCancelUpdate', 'ViewUpdateStatus', 'rbacUiControlService', 'GetBasePath',
'GetSyncStatusMsg', 'GetHostsStatusMsg', 'Dataset', 'Find', 'QuerySet', 'inventoryData',
'GroupManageService', 'CancelSourceUpdate', 'rbacUiControlService', 'GetBasePath',
'GetHostsStatusMsg', 'Dataset', 'Find', 'QuerySet', 'inventoryData',
function($scope, $rootScope, $state, $stateParams, GroupList, InventoryUpdate,
GroupManageService, GroupsCancelUpdate, ViewUpdateStatus, rbacUiControlService, GetBasePath,
GetSyncStatusMsg, GetHostsStatusMsg, Dataset, Find, qs, inventoryData){
GroupManageService, CancelSourceUpdate, rbacUiControlService, GetBasePath,
GetHostsStatusMsg, Dataset, Find, qs, inventoryData){
let list = GroupList;
@ -144,51 +144,8 @@
}));
};
$scope.$on(`ws-jobs`, function(e, data){
var group = Find({ list: $scope.groups, key: 'id', val: data.group_id });
if (group === undefined || group === null) {
group = {};
}
if(data.status === 'failed' || data.status === 'successful'){
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,
has_inventory_sources: group.has_inventory_sources,
source: group.source
});
group.status = data.status;
group.status_class = status.class;
group.status_tooltip = status.tooltip;
group.launch_tooltip = status.launch_tip;
group.launch_class = status.launch_class;
}
});
$scope.cancelUpdate = function (id) {
GroupsCancelUpdate({ scope: $scope, id: id });
};
$scope.viewUpdateStatus = function (id) {
ViewUpdateStatus({
scope: $scope,
group_id: id
});
CancelSourceUpdate({ scope: $scope, id: id });
};
$scope.copyMoveGroup = function(id){

View File

@ -13,10 +13,6 @@ import groupFormDefinition from './groups.form';
import groupListDefinition from './groups.list';
import service from './groups.service';
import GetHostsStatusMsg from './factories/get-hosts-status-msg.factory';
import GetSourceTypeOptions from './factories/get-source-type-options.factory';
import GetSyncStatusMsg from './factories/get-sync-status-msg.factory';
import GroupsCancelUpdate from './factories/groups-cancel-update.factory';
import ViewUpdateStatus from './factories/view-update-status.factory';
export default
angular.module('group', [
@ -29,8 +25,4 @@ export default
.factory('GroupForm', groupFormDefinition)
.value('GroupList', groupListDefinition)
.factory('GetHostsStatusMsg', GetHostsStatusMsg)
.factory('GetSourceTypeOptions', GetSourceTypeOptions)
.factory('GetSyncStatusMsg', GetSyncStatusMsg)
.factory('GroupsCancelUpdate', GroupsCancelUpdate)
.factory('ViewUpdateStatus', ViewUpdateStatus)
.service('GroupManageService', service);

View File

@ -5,11 +5,11 @@
*************************************************/
export default
['$scope', '$rootScope', '$state', '$stateParams', 'NestedGroupListDefinition', 'InventoryUpdate',
'GroupManageService', 'GroupsCancelUpdate', 'ViewUpdateStatus', 'rbacUiControlService', 'GetBasePath',
'GetSyncStatusMsg', 'GetHostsStatusMsg', 'Dataset', 'Find', 'QuerySet', 'inventoryData',
'GroupManageService', 'CancelSourceUpdate', 'rbacUiControlService', 'GetBasePath',
'GetHostsStatusMsg', 'Dataset', 'Find', 'QuerySet', 'inventoryData',
function($scope, $rootScope, $state, $stateParams, NestedGroupListDefinition, InventoryUpdate,
GroupManageService, GroupsCancelUpdate, ViewUpdateStatus, rbacUiControlService, GetBasePath,
GetSyncStatusMsg, GetHostsStatusMsg, Dataset, Find, qs, inventoryData){
GroupManageService, CancelSourceUpdate, rbacUiControlService, GetBasePath,
GetHostsStatusMsg, Dataset, Find, qs, inventoryData){
let list = NestedGroupListDefinition;
@ -131,51 +131,8 @@
}));
};
$scope.$on(`ws-jobs`, function(e, data){
var group = Find({ list: $scope.groups, key: 'id', val: data.group_id });
if (group === undefined || group === null) {
group = {};
}
if(data.status === 'failed' || data.status === 'successful'){
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,
has_inventory_sources: group.has_inventory_sources,
source: group.source
});
group.status = data.status;
group.status_class = status.class;
group.status_tooltip = status.tooltip;
group.launch_tooltip = status.launch_tip;
group.launch_class = status.launch_class;
}
});
$scope.cancelUpdate = function (id) {
GroupsCancelUpdate({ scope: $scope, id: id });
};
$scope.viewUpdateStatus = function (id) {
ViewUpdateStatus({
scope: $scope,
group_id: id
});
CancelSourceUpdate({ scope: $scope, id: id });
};
// $scope.$parent governed by InventoryManageController, for unified multiSelect options

View File

@ -0,0 +1,63 @@
export default
function CancelSourceUpdate(Empty, Rest, ProcessErrors, Alert, Wait, Find) {
return function(params) {
var scope = params.scope,
id = params.id,
inventory_source = params.inventory_source;
// Cancel the update process
if (Empty(inventory_source)) {
inventory_source = Find({ list: scope.inventory_sources, key: 'id', val: id });
scope.selected_inventory_source_id = inventory_source.id;
}
if (inventory_source && (inventory_source.status === 'running' || inventory_source.status === 'pending')) {
// We found the inventory_source, and there is a running update
Wait('start');
Rest.setUrl(inventory_source.url);
Rest.get()
.success(function (data) {
// Check that we have access to cancelling an update
var url = (data.related.current_update) ? data.related.current_update : data.related.last_update;
url += 'cancel/';
Rest.setUrl(url);
Rest.get()
.success(function (data) {
if (data.can_cancel) {
// Cancel the update process
Rest.setUrl(url);
Rest.post()
.success(function () {
Wait('stop');
//Alert('Inventory Sync Cancelled', 'Request to cancel the sync process was submitted to the task manger. ' +
// 'Click the <i class="fa fa-refresh fa-lg"></i> button to monitor the status.', 'alert-info');
})
.error(function (data, status) {
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Call to ' + url + ' failed. POST status: ' + status
});
});
}
else {
Wait('stop');
}
})
.error(function (data, status) {
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Call to ' + url + ' failed. GET status: ' + status
});
});
})
.error(function (data, status) {
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Call to ' + inventory_source.url + ' failed. GET status: ' + status
});
});
}
};
}
CancelSourceUpdate.$inject =
[ 'Empty', 'Rest', 'ProcessErrors',
'Alert', 'Wait', 'Find'
];

View File

@ -1,33 +0,0 @@
export default
function GetHostsStatusMsg() {
return function(params) {
var active_failures = params.active_failures,
total_hosts = params.total_hosts,
tip, failures, html_class;
// Return values for use on host status indicator
if (active_failures > 0) {
tip = total_hosts + ((total_hosts === 1) ? ' host' : ' hosts') + '. ' + active_failures + ' with failed jobs.';
html_class = 'error';
failures = true;
} else {
failures = false;
if (total_hosts === 0) {
// no hosts
tip = "Contains 0 hosts.";
html_class = 'none';
} else {
// many hosts with 0 failures
tip = total_hosts + ((total_hosts === 1) ? ' host' : ' hosts') + '. No job failures';
html_class = 'success';
}
}
return {
tooltip: tip,
failures: failures,
'class': html_class
};
};
}

View File

@ -1,9 +1,7 @@
export default
function GetSyncStatusMsg(Empty) {
function GetSyncStatusMsg() {
return function(params) {
var status = params.status,
source = params.source,
has_inventory_sources = params.has_inventory_sources,
launch_class = '',
launch_tip = 'Start sync process',
schedule_tip = 'Schedule future inventory syncs',
@ -49,19 +47,6 @@ export default
break;
}
if (has_inventory_sources && Empty(source)) {
// parent has a source, therefore this group should not have a source
launch_class = "btn-disabled";
status_tip = 'Managed by an external cloud source.';
launch_tip = 'Can only be updated by running a sync on the parent group.';
}
if (has_inventory_sources === false && Empty(source)) {
launch_class = 'btn-disabled';
status_tip = 'Cloud source not configured. Click <i class="fa fa-pencil"></i> to update.';
launch_tip = 'Cloud source not configured.';
}
return {
"class": stat_class,
"tooltip": status_tip,
@ -73,5 +58,4 @@ export default
};
}
GetSyncStatusMsg.$inject =
[ 'Empty' ];
GetSyncStatusMsg.$inject = [];

View File

@ -1,81 +0,0 @@
export default
function GroupsCancelUpdate(Empty, Rest, ProcessErrors, Alert, Wait, Find) {
return function(params) {
var scope = params.scope,
id = params.id,
group = params.group;
if (scope.removeCancelUpdate) {
scope.removeCancelUpdate();
}
scope.removeCancelUpdate = scope.$on('CancelUpdate', function (e, url) {
// Cancel the update process
Rest.setUrl(url);
Rest.post()
.success(function () {
Wait('stop');
//Alert('Inventory Sync Cancelled', 'Request to cancel the sync process was submitted to the task manger. ' +
// 'Click the <i class="fa fa-refresh fa-lg"></i> button to monitor the status.', 'alert-info');
})
.error(function (data, status) {
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Call to ' + url + ' failed. POST status: ' + status
});
});
});
if (scope.removeCheckCancel) {
scope.removeCheckCancel();
}
scope.removeCheckCancel = scope.$on('CheckCancel', function (e, last_update, current_update) {
// Check that we have access to cancelling an update
var url = (current_update) ? current_update : last_update;
url += 'cancel/';
Rest.setUrl(url);
Rest.get()
.success(function (data) {
if (data.can_cancel) {
scope.$emit('CancelUpdate', url);
//} else {
// Wait('stop');
// Alert('Cancel Inventory Sync', 'The sync process completed. Click the <i class="fa fa-refresh fa-lg"></i> button to view ' +
// 'the latest status.', 'alert-info');
}
else {
Wait('stop');
}
})
.error(function (data, status) {
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Call to ' + url + ' failed. GET status: ' + status
});
});
});
// Cancel the update process
if (Empty(group)) {
group = Find({ list: scope.groups, key: 'id', val: id });
scope.selected_group_id = group.id;
}
if (group && (group.status === 'running' || group.status === 'pending')) {
// We found the group, and there is a running update
Wait('start');
Rest.setUrl(group.related.inventory_source);
Rest.get()
.success(function (data) {
scope.$emit('CheckCancel', data.related.last_update, data.related.current_update);
})
.error(function (data, status) {
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Call to ' + group.related.inventory_source + ' failed. GET status: ' + status
});
});
}
};
}
GroupsCancelUpdate.$inject =
[ 'Empty', 'Rest', 'ProcessErrors',
'Alert', 'Wait', 'Find'
];

View File

@ -2,37 +2,26 @@ export default
function ViewUpdateStatus($state, Rest, ProcessErrors, Alert, Wait, Empty, Find) {
return function(params) {
var scope = params.scope,
group_id = params.group_id,
group = Find({ list: scope.groups, key: 'id', val: group_id });
inventory_source_id = params.inventory_source_id,
inventory_source = Find({ list: scope.inventory_sources, key: 'id', val: inventory_source_id });
if (scope.removeSourceReady) {
scope.removeSourceReady();
}
scope.removeSourceReady = scope.$on('SourceReady', function(e, source) {
// Get the ID from the correct summary field
var update_id = (source.summary_fields.current_update) ? source.summary_fields.current_update.id : source.summary_fields.last_update.id;
$state.go('inventorySyncStdout', {id: update_id});
});
if (group) {
if (Empty(group.source)) {
// do nothing
} else if (Empty(group.status) || group.status === "never updated") {
if (inventory_source) {
if (Empty(inventory_source.status) || inventory_source.status === "never updated") {
Alert('No Status Available', '<div>An inventory sync has not been performed for the selected group. Start the process by ' +
'clicking the <i class="fa fa-refresh"></i> button.</div>', 'alert-info', null, null, null, null, true);
} else {
Wait('start');
Rest.setUrl(group.related.inventory_source);
Rest.setUrl(inventory_source.url);
Rest.get()
.success(function (data) {
scope.$emit('SourceReady', data);
// Get the ID from the correct summary field
var update_id = (data.summary_fields.current_update) ? data.summary_fields.current_update.id : data.summary_fields.last_update.id;
$state.go('inventorySyncStdout', {id: update_id});
})
.error(function (data, status) {
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Failed to retrieve inventory source: ' + group.related.inventory_source +
msg: 'Failed to retrieve inventory source: ' + inventory_source.url +
' GET returned status: ' + status });
});
}

View File

@ -14,6 +14,13 @@ export default ['SourcesListDefinition', '$stateExtender', 'templateUrl', '$inje
searchPrefix: `${list.iterator}`,
name: `${formStateDefinition.name}.${list.iterator}s`,
url: `/${list.iterator}s`,
data: {
socket: {
"groups": {
"jobs": ["status_changed"]
}
}
},
ncyBreadcrumb: {
parent: `${formStateDefinition.name}`,
label: `${breadcrumbLabel}`

View File

@ -5,14 +5,14 @@
*************************************************/
export default
['$scope', '$rootScope', '$state', '$stateParams', 'SourcesListDefinition',
'InventoryUpdate', 'GroupManageService', 'GroupsCancelUpdate',
'InventoryUpdate', 'GroupManageService', 'CancelSourceUpdate',
'ViewUpdateStatus', 'rbacUiControlService', 'GetBasePath',
'GetSyncStatusMsg', 'GetHostsStatusMsg', 'Dataset', 'Find', 'QuerySet',
'GetSyncStatusMsg', 'Dataset', 'Find', 'QuerySet',
'inventoryData', '$filter', 'Prompt', 'Wait', 'SourcesService',
function($scope, $rootScope, $state, $stateParams, SourcesListDefinition,
InventoryUpdate, GroupManageService, GroupsCancelUpdate,
InventoryUpdate, GroupManageService, CancelSourceUpdate,
ViewUpdateStatus, rbacUiControlService, GetBasePath, GetSyncStatusMsg,
GetHostsStatusMsg, Dataset, Find, qs, inventoryData, $filter, Prompt,
Dataset, Find, qs, inventoryData, $filter, Prompt,
Wait, SourcesService){
let list = SourcesListDefinition;
@ -20,14 +20,14 @@
init();
function init(){
$scope.inventory_id = $stateParams.inventory_id;
$scope.canAdhoc = inventoryData.summary_fields.user_capabilities.adhoc;
$scope.canAdd = false;
$scope.inventory_id = $stateParams.inventory_id;
$scope.canAdhoc = inventoryData.summary_fields.user_capabilities.adhoc;
$scope.canAdd = false;
rbacUiControlService.canAdd(GetBasePath('inventory') + $scope.inventory_id + "/groups")
.then(function(canAdd) {
$scope.canAdd = canAdd;
});
rbacUiControlService.canAdd(GetBasePath('inventory') + $scope.inventory_id + "/groups")
.then(function(canAdd) {
$scope.canAdd = canAdd;
});
// Search init
$scope.list = list;
@ -43,6 +43,33 @@
$scope.inventory_id = $stateParams.inventory_id;
_.forEach($scope[list.name], buildStatusIndicators);
$scope.$on(`ws-jobs`, function(e, data){
var inventory_source = Find({ list: $scope.inventory_sources, key: 'id', val: data.inventory_source_id });
if (inventory_source === undefined || inventory_source === null) {
inventory_source = {};
}
if(data.status === 'failed' || data.status === 'successful'){
let path = GetBasePath('inventory') + $stateParams.inventory_id + '/inventory_sources';
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
});
inventory_source.status = data.status;
inventory_source.status_class = status.class;
inventory_source.status_tooltip = status.tooltip;
inventory_source.launch_tooltip = status.launch_tip;
inventory_source.launch_class = status.launch_class;
}
});
}
function buildStatusIndicators(inventory_source){
@ -50,27 +77,19 @@
inventory_source = {};
}
let inventory_source_status, hosts_status;
let inventory_source_status;
inventory_source_status = GetSyncStatusMsg({
status: inventory_source.status,
has_inventory_sources: inventory_source.has_inventory_sources,
source: ( (inventory_source) ? inventory_source.source : null )
});
hosts_status = GetHostsStatusMsg({
active_failures: inventory_source.hosts_with_active_failures,
total_hosts: inventory_source.total_hosts,
inventory_id: $scope.inventory_id,
// group_id: group.id
});
_.assign(inventory_source,
{status_class: inventory_source_status.class},
{status_tooltip: inventory_source_status.tooltip},
{launch_tooltip: inventory_source_status.launch_tip},
{launch_class: inventory_source_status.launch_class},
{group_schedule_tooltip: inventory_source_status.schedule_tip},
{hosts_status_tip: hosts_status.tooltip},
{hosts_status_class: hosts_status.class},
{source: inventory_source ? inventory_source.source : null},
{status: inventory_source ? inventory_source.status : null});
}
@ -114,12 +133,12 @@
};
$scope.cancelUpdate = function (id) {
GroupsCancelUpdate({ scope: $scope, id: id });
CancelSourceUpdate({ scope: $scope, id: id });
};
$scope.viewUpdateStatus = function (id) {
ViewUpdateStatus({
scope: $scope,
group_id: id
inventory_source_id: id
});
};
$scope.scheduleSource = function(id) {

View File

@ -10,6 +10,10 @@ import sourcesEdit from './edit/main';
import sourcesFormDefinition from './sources.form';
import sourcesListDefinition from './sources.list';
import service from './sources.service';
import GetSyncStatusMsg from './factories/get-sync-status-msg.factory';
import ViewUpdateStatus from './factories/view-update-status.factory';
import CancelSourceUpdate from './factories/cancel-source-update.factory';
import GetSourceTypeOptions from './factories/get-source-type-options.factory';
export default
angular.module('sources', [
@ -19,4 +23,8 @@ export default
])
.value('SourcesFormDefinition', sourcesFormDefinition)
.value('SourcesListDefinition', sourcesListDefinition)
.factory('GetSyncStatusMsg', GetSyncStatusMsg)
.factory('ViewUpdateStatus', ViewUpdateStatus)
.factory('CancelSourceUpdate', CancelSourceUpdate)
.factory('GetSourceTypeOptions', GetSourceTypeOptions)
.service('SourcesService', service);

View File

@ -85,15 +85,6 @@
</div>
</div>
<div class="StandardOut-detailsRow" ng-show="inventory_source_name">
<div class="StandardOut-detailsLabel col-lg-3 col-md-3 col-sm-3 col-xs-4" translate>GROUP</div>
<div class="StandardOut-detailsContent col-lg-9 col-md-9 col-sm-9 col-xs-8">
<a href="{{inv_manage_group_link}}">
{{ inventory_source_name }}
</a>
</div>
</div>
<div class="StandardOut-detailsRow" ng-show="source">
<div class="StandardOut-detailsLabel col-lg-3 col-md-3 col-sm-3 col-xs-4" translate>SOURCE</div>
<div class="StandardOut-detailsContent col-lg-9 col-md-9 col-sm-9 col-xs-8">

View File

@ -14,16 +14,11 @@
Rest.get()
.success(function(data) {
if (scope_var === 'inventory_source') {
scope[scope_var + '_name'] = data.summary_fields.group.name;
scope.inventory = data.inventory;
}
else if (!Empty(data.name)) {
if (!Empty(data.name)) {
scope[scope_var + '_name'] = data.name;
}
if (!Empty(data.group)) {
// Used for inventory_source
scope.group = data.group;
}
})
.error(function(data, status) {
if (status === 403 && params.ignore_403) {