diff --git a/awx/ui/client/src/inventories/groups/add/groups-add.controller.js b/awx/ui/client/src/inventories/groups/add/groups-add.controller.js index 6b5f849b40..ae37692ba1 100644 --- a/awx/ui/client/src/inventories/groups/add/groups-add.controller.js +++ b/awx/ui/client/src/inventories/groups/add/groups-add.controller.js @@ -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; diff --git a/awx/ui/client/src/inventories/groups/edit/groups-edit.controller.js b/awx/ui/client/src/inventories/groups/edit/groups-edit.controller.js index 27f444d69a..1335b4bb80 100644 --- a/awx/ui/client/src/inventories/groups/edit/groups-edit.controller.js +++ b/awx/ui/client/src/inventories/groups/edit/groups-edit.controller.js @@ -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(); diff --git a/awx/ui/client/src/inventories/groups/factories/get-source-type-options.factory.js b/awx/ui/client/src/inventories/groups/factories/get-source-type-options.factory.js deleted file mode 100644 index befef8a499..0000000000 --- a/awx/ui/client/src/inventories/groups/factories/get-source-type-options.factory.js +++ /dev/null @@ -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' - ]; diff --git a/awx/ui/client/src/inventories/groups/factories/get-sync-status-msg.factory.js b/awx/ui/client/src/inventories/groups/factories/get-sync-status-msg.factory.js deleted file mode 100644 index 2541abcc27..0000000000 --- a/awx/ui/client/src/inventories/groups/factories/get-sync-status-msg.factory.js +++ /dev/null @@ -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 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 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 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' ]; diff --git a/awx/ui/client/src/inventories/groups/factories/groups-cancel-update.factory.js b/awx/ui/client/src/inventories/groups/factories/groups-cancel-update.factory.js deleted file mode 100644 index 1447d0aa1c..0000000000 --- a/awx/ui/client/src/inventories/groups/factories/groups-cancel-update.factory.js +++ /dev/null @@ -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 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 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' - ]; diff --git a/awx/ui/client/src/inventories/groups/factories/view-update-status.factory.js b/awx/ui/client/src/inventories/groups/factories/view-update-status.factory.js deleted file mode 100644 index 1f3280b51c..0000000000 --- a/awx/ui/client/src/inventories/groups/factories/view-update-status.factory.js +++ /dev/null @@ -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', '
An inventory sync has not been performed for the selected group. Start the process by ' + - 'clicking the button.
', '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' - ]; diff --git a/awx/ui/client/src/inventories/groups/list/groups-list.controller.js b/awx/ui/client/src/inventories/groups/list/groups-list.controller.js index 68b7da4f35..7cfd4cdb01 100644 --- a/awx/ui/client/src/inventories/groups/list/groups-list.controller.js +++ b/awx/ui/client/src/inventories/groups/list/groups-list.controller.js @@ -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){ diff --git a/awx/ui/client/src/inventories/groups/main.js b/awx/ui/client/src/inventories/groups/main.js index d5a40f97ff..ab66437ace 100644 --- a/awx/ui/client/src/inventories/groups/main.js +++ b/awx/ui/client/src/inventories/groups/main.js @@ -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); diff --git a/awx/ui/client/src/inventories/groups/nested-groups/nested-groups-list.controller.js b/awx/ui/client/src/inventories/groups/nested-groups/nested-groups-list.controller.js index 3a13d3b64c..237757efa8 100644 --- a/awx/ui/client/src/inventories/groups/nested-groups/nested-groups-list.controller.js +++ b/awx/ui/client/src/inventories/groups/nested-groups/nested-groups-list.controller.js @@ -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 diff --git a/awx/ui/client/src/inventories/sources/factories/cancel-source-update.factory.js b/awx/ui/client/src/inventories/sources/factories/cancel-source-update.factory.js new file mode 100644 index 0000000000..a0fb73e7eb --- /dev/null +++ b/awx/ui/client/src/inventories/sources/factories/cancel-source-update.factory.js @@ -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 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' + ]; diff --git a/awx/ui/client/src/inventories/sources/factories/get-hosts-status-msg.factory.js b/awx/ui/client/src/inventories/sources/factories/get-hosts-status-msg.factory.js deleted file mode 100644 index 19a846c414..0000000000 --- a/awx/ui/client/src/inventories/sources/factories/get-hosts-status-msg.factory.js +++ /dev/null @@ -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 - }; - }; - } diff --git a/awx/ui/client/src/inventories/sources/factories/get-sync-status-msg.factory.js b/awx/ui/client/src/inventories/sources/factories/get-sync-status-msg.factory.js index 2541abcc27..efb393caf8 100644 --- a/awx/ui/client/src/inventories/sources/factories/get-sync-status-msg.factory.js +++ b/awx/ui/client/src/inventories/sources/factories/get-sync-status-msg.factory.js @@ -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 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 = []; diff --git a/awx/ui/client/src/inventories/sources/factories/groups-cancel-update.factory.js b/awx/ui/client/src/inventories/sources/factories/groups-cancel-update.factory.js deleted file mode 100644 index 1447d0aa1c..0000000000 --- a/awx/ui/client/src/inventories/sources/factories/groups-cancel-update.factory.js +++ /dev/null @@ -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 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 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' - ]; diff --git a/awx/ui/client/src/inventories/sources/factories/view-update-status.factory.js b/awx/ui/client/src/inventories/sources/factories/view-update-status.factory.js index 1f3280b51c..5a746aa075 100644 --- a/awx/ui/client/src/inventories/sources/factories/view-update-status.factory.js +++ b/awx/ui/client/src/inventories/sources/factories/view-update-status.factory.js @@ -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', '
An inventory sync has not been performed for the selected group. Start the process by ' + 'clicking the button.
', '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 }); }); } diff --git a/awx/ui/client/src/inventories/sources/list/build-sources-list-state.factory.js b/awx/ui/client/src/inventories/sources/list/build-sources-list-state.factory.js index eb124f2842..71792e273d 100644 --- a/awx/ui/client/src/inventories/sources/list/build-sources-list-state.factory.js +++ b/awx/ui/client/src/inventories/sources/list/build-sources-list-state.factory.js @@ -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}` diff --git a/awx/ui/client/src/inventories/sources/list/sources-list.controller.js b/awx/ui/client/src/inventories/sources/list/sources-list.controller.js index e6cfe4a51b..8e260c0590 100644 --- a/awx/ui/client/src/inventories/sources/list/sources-list.controller.js +++ b/awx/ui/client/src/inventories/sources/list/sources-list.controller.js @@ -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) { diff --git a/awx/ui/client/src/inventories/sources/main.js b/awx/ui/client/src/inventories/sources/main.js index bb515628b7..e2ca31f6a0 100644 --- a/awx/ui/client/src/inventories/sources/main.js +++ b/awx/ui/client/src/inventories/sources/main.js @@ -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); diff --git a/awx/ui/client/src/standard-out/inventory-sync/standard-out-inventory-sync.partial.html b/awx/ui/client/src/standard-out/inventory-sync/standard-out-inventory-sync.partial.html index 5df1bd84c7..e5b0b17baf 100644 --- a/awx/ui/client/src/standard-out/inventory-sync/standard-out-inventory-sync.partial.html +++ b/awx/ui/client/src/standard-out/inventory-sync/standard-out-inventory-sync.partial.html @@ -85,15 +85,6 @@ -
-
GROUP
-
- - {{ inventory_source_name }} - -
-
-
SOURCE
diff --git a/awx/ui/client/src/standard-out/standard-out-factories/lookup-name.factory.js b/awx/ui/client/src/standard-out/standard-out-factories/lookup-name.factory.js index 40d32b3f8d..319ff0916b 100644 --- a/awx/ui/client/src/standard-out/standard-out-factories/lookup-name.factory.js +++ b/awx/ui/client/src/standard-out/standard-out-factories/lookup-name.factory.js @@ -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) {