From 3119d5ed22d5a66e93432eade85591452c22170e Mon Sep 17 00:00:00 2001 From: mabashian Date: Fri, 20 Oct 2017 20:10:36 -0400 Subject: [PATCH] Delete inv source hosts before inv source --- .../sources/list/sources-list.controller.js | 50 +++++++++++++------ .../related/sources/sources.service.js | 9 ++++ 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/awx/ui/client/src/inventories-hosts/inventories/related/sources/list/sources-list.controller.js b/awx/ui/client/src/inventories-hosts/inventories/related/sources/list/sources-list.controller.js index 6561fe6fc9..e0798e714d 100644 --- a/awx/ui/client/src/inventories-hosts/inventories/related/sources/list/sources-list.controller.js +++ b/awx/ui/client/src/inventories-hosts/inventories/related/sources/list/sources-list.controller.js @@ -9,12 +9,12 @@ 'ViewUpdateStatus', 'rbacUiControlService', 'GetBasePath', 'GetSyncStatusMsg', 'Dataset', 'Find', 'QuerySet', 'inventoryData', '$filter', 'Prompt', 'Wait', 'SourcesService', 'inventorySourceOptions', - 'canAdd', 'hasSyncableSources', 'i18n', + 'canAdd', 'hasSyncableSources', 'i18n', 'ProcessErrors', function($scope, $rootScope, $state, $stateParams, SourcesListDefinition, InventoryUpdate, CancelSourceUpdate, ViewUpdateStatus, rbacUiControlService, GetBasePath, GetSyncStatusMsg, Dataset, Find, qs, inventoryData, $filter, Prompt, - Wait, SourcesService, inventorySourceOptions, canAdd, hasSyncableSources, i18n){ + Wait, SourcesService, inventorySourceOptions, canAdd, hasSyncableSources, i18n, ProcessErrors){ let list = SourcesListDefinition; var inventory_source; @@ -121,20 +121,42 @@ var action = function(){ delete $rootScope.promptActionBtnClass; Wait('start'); - SourcesService.delete(inventory_source.id).then(() => { - $('#prompt-modal').modal('hide'); - let reloadListStateParams = null; + SourcesService.deleteHosts(inventory_source.id).then(() => { + SourcesService.delete(inventory_source.id).then(() => { + $('#prompt-modal').modal('hide'); + let reloadListStateParams = null; - if($scope.inventory_sources.length === 1 && $state.params.inventory_source_search && !_.isEmpty($state.params.inventory_source_search.page) && $state.params.inventory_source_search.page !== '1') { - reloadListStateParams = _.cloneDeep($state.params); - reloadListStateParams.inventory_source_search.page = (parseInt(reloadListStateParams.inventory_source_search.page)-1).toString(); - } - if (parseInt($state.params.inventory_source_id) === inventory_source.id) { - $state.go('^', reloadListStateParams, {reload: true}); - } else { - $state.go('.', reloadListStateParams, {reload: true}); - } + if($scope.inventory_sources.length === 1 && $state.params.inventory_source_search && !_.isEmpty($state.params.inventory_source_search.page) && $state.params.inventory_source_search.page !== '1') { + reloadListStateParams = _.cloneDeep($state.params); + reloadListStateParams.inventory_source_search.page = (parseInt(reloadListStateParams.inventory_source_search.page)-1).toString(); + } + if (parseInt($state.params.inventory_source_id) === inventory_source.id) { + $state.go('^', reloadListStateParams, {reload: true}); + } else { + $state.go('.', reloadListStateParams, {reload: true}); + } + Wait('stop'); + }) + .catch(({data, status}) => { + $('#prompt-modal').modal('hide'); + Wait('stop'); + ProcessErrors($scope, data, status, null, + { + hdr: i18n._('Error!'), + msg: i18n._('There was an error deleting inventory source. Returned status: ') + + status + }); + }); + }) + .catch(({data, status}) => { + $('#prompt-modal').modal('hide'); Wait('stop'); + ProcessErrors($scope, data, status, null, + { + hdr: i18n._('Error!'), + msg: i18n._('There was an error deleting inventory source hosts. Returned status: ') + + status + }); }); }; // Prompt depends on having $rootScope.promptActionBtnClass available... diff --git a/awx/ui/client/src/inventories-hosts/inventories/related/sources/sources.service.js b/awx/ui/client/src/inventories-hosts/inventories/related/sources/sources.service.js index 8ae2d144b7..93894d7126 100644 --- a/awx/ui/client/src/inventories-hosts/inventories/related/sources/sources.service.js +++ b/awx/ui/client/src/inventories-hosts/inventories/related/sources/sources.service.js @@ -132,6 +132,15 @@ export default else { return; } + }, + deleteHosts(id) { + Wait('start'); + this.url = GetBasePath('inventory_sources') + id + '/hosts/'; + Rest.setUrl(this.url); + return Rest.destroy() + .success(this.success.bind(this)) + .error(this.error.bind(this)) + .finally(Wait('stop')); } }; }];