From 127a18da6b0a5d77c9a36894385c43edbf2799dd Mon Sep 17 00:00:00 2001 From: Michael Abashian Date: Wed, 7 Jun 2017 13:55:23 -0400 Subject: [PATCH] Moved Sync All Inv Sources to the inventory sources list and removed it from the inventories list --- .../inventories/inventory-manage.service.js | 7 +++ .../client/src/inventories/inventory.list.js | 9 ---- .../list/inventory-list.controller.js | 12 +---- awx/ui/client/src/inventories/main.js | 13 ++++- .../sources/edit/sources-edit.controller.js | 2 +- .../sources/list/sources-list.controller.js | 18 +++++-- .../sources/list/sources-list.route.js | 18 +++++++ .../lookup/sources-lookup-project.route.js | 50 +++++++++++++++++++ .../src/inventories/sources/sources.list.js | 9 ++++ 9 files changed, 113 insertions(+), 25 deletions(-) create mode 100644 awx/ui/client/src/inventories/sources/lookup/sources-lookup-project.route.js diff --git a/awx/ui/client/src/inventories/inventory-manage.service.js b/awx/ui/client/src/inventories/inventory-manage.service.js index 757d5392e7..ed02ce4cf1 100644 --- a/awx/ui/client/src/inventories/inventory-manage.service.js +++ b/awx/ui/client/src/inventories/inventory-manage.service.js @@ -62,6 +62,13 @@ return Rest.options() .success(this.success.bind(this)) .error(this.error.bind(this)); + }, + updateInventorySourcesGet: function(inventoryId) { + this.url = GetBasePath('inventory') + inventoryId + '/update_inventory_sources'; + Rest.setUrl(this.url); + return Rest.get() + .success(this.success.bind(this)) + .error(this.error.bind(this)); } }; }]; diff --git a/awx/ui/client/src/inventories/inventory.list.js b/awx/ui/client/src/inventories/inventory.list.js index 1969a1920d..51e50de9b5 100644 --- a/awx/ui/client/src/inventories/inventory.list.js +++ b/awx/ui/client/src/inventories/inventory.list.js @@ -91,16 +91,7 @@ export default ['i18n', function(i18n) { }, fieldActions: { - columnClass: 'col-md-2 col-sm-3 col-xs-4', - - inventory_update: { - mode: 'all', - ngClick: 'syncInventory(inventory)', - awToolTip: i18n._('Sync all inventory sources'), - ngShow: "inventory.kind === '' && inventory.has_inventory_sources", - dataPlacement: "top", - }, edit: { label: i18n._('Edit'), ngClick: 'editInventory(inventory)', diff --git a/awx/ui/client/src/inventories/list/inventory-list.controller.js b/awx/ui/client/src/inventories/list/inventory-list.controller.js index 3bcfbb83a7..3f81647145 100644 --- a/awx/ui/client/src/inventories/list/inventory-list.controller.js +++ b/awx/ui/client/src/inventories/list/inventory-list.controller.js @@ -13,7 +13,7 @@ function InventoriesList($scope, $filter, Rest, InventoryList, Prompt, ProcessErrors, GetBasePath, Wait, $state, - Dataset, InventoryUpdate, canAdd) { + Dataset, canAdd) { let list = InventoryList, defaultUrl = GetBasePath('inventory'); @@ -107,18 +107,10 @@ function InventoriesList($scope, actionText: 'DELETE' }); }; - - $scope.syncInventory = function(inventory) { - InventoryUpdate({ - scope: $scope, - url: inventory.related.update_inventory_sources, - updateAllSources: true - }); - }; } export default ['$scope', '$filter', 'Rest', 'InventoryList', 'Prompt', 'ProcessErrors', 'GetBasePath', 'Wait', - '$state', 'Dataset', 'InventoryUpdate', 'canAdd', InventoriesList + '$state', 'Dataset', 'canAdd', InventoriesList ]; diff --git a/awx/ui/client/src/inventories/main.js b/awx/ui/client/src/inventories/main.js index eff74e0fff..0ab8f7a384 100644 --- a/awx/ui/client/src/inventories/main.js +++ b/awx/ui/client/src/inventories/main.js @@ -49,6 +49,7 @@ import hostGroupsRoute from './host-groups/host-groups.route'; import hostGroupsAssociateRoute from './host-groups/host-groups-associate/host-groups-associate.route'; import inventorySourcesCredentialRoute from './sources/lookup/sources-lookup-credential.route'; import inventorySourcesInventoryScriptRoute from './sources/lookup/sources-lookup-inventory-script.route'; +import inventorySourcesProjectRoute from './sources/lookup/sources-lookup-project.route'; import SmartInventory from './smart-inventory/main'; import StandardInventory from './standard/main'; @@ -202,6 +203,14 @@ angular.module('inventory', [ editSourceCredential.name = 'inventories.edit.inventory_sources.edit.credential'; editSourceCredential.url = '/credential'; + let addSourceProject = _.cloneDeep(inventorySourcesProjectRoute); + addSourceProject.name = 'inventories.edit.inventory_sources.add.project'; + addSourceProject.url = '/project'; + + let editSourceProject = _.cloneDeep(inventorySourcesProjectRoute); + editSourceProject.name = 'inventories.edit.inventory_sources.edit.project'; + editSourceProject.url = '/project'; + let editSourceInventoryScript = _.cloneDeep(inventorySourcesInventoryScriptRoute); editSourceInventoryScript.name = 'inventories.edit.inventory_sources.edit.inventory_script'; editSourceInventoryScript.url = '/inventory_script'; @@ -271,7 +280,9 @@ angular.module('inventory', [ stateExtender.buildDefinition(addSourceCredential), stateExtender.buildDefinition(addSourceInventoryScript), stateExtender.buildDefinition(editSourceCredential), - stateExtender.buildDefinition(editSourceInventoryScript) + stateExtender.buildDefinition(editSourceInventoryScript), + stateExtender.buildDefinition(addSourceProject), + stateExtender.buildDefinition(editSourceProject) ]) }; }); diff --git a/awx/ui/client/src/inventories/sources/edit/sources-edit.controller.js b/awx/ui/client/src/inventories/sources/edit/sources-edit.controller.js index 2ea375abd9..90c7a60d9e 100644 --- a/awx/ui/client/src/inventories/sources/edit/sources-edit.controller.js +++ b/awx/ui/client/src/inventories/sources/edit/sources-edit.controller.js @@ -256,7 +256,7 @@ export default ['$state', '$stateParams', '$scope', 'ParseVariableString', function initSourceSelect() { $scope.source = _.find($scope.source_type_options, { value: inventorySourceData.source }); - var source = $scope.source.value; + var source = $scope.source && $scope.source.value ? $scope.source.value : null; CreateSelect2({ element: '#inventory_source_source', 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 1e3457bd84..363d9d315f 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 @@ -8,12 +8,13 @@ 'InventoryUpdate', 'CancelSourceUpdate', 'ViewUpdateStatus', 'rbacUiControlService', 'GetBasePath', 'GetSyncStatusMsg', 'Dataset', 'Find', 'QuerySet', - 'inventoryData', '$filter', 'Prompt', 'Wait', 'SourcesService', 'inventorySourceOptions', 'canAdd', + 'inventoryData', '$filter', 'Prompt', 'Wait', 'SourcesService', 'inventorySourceOptions', + 'canAdd', 'hasSyncableSources', function($scope, $rootScope, $state, $stateParams, SourcesListDefinition, InventoryUpdate, CancelSourceUpdate, ViewUpdateStatus, rbacUiControlService, GetBasePath, GetSyncStatusMsg, Dataset, Find, qs, inventoryData, $filter, Prompt, - Wait, SourcesService, inventorySourceOptions, canAdd){ + Wait, SourcesService, inventorySourceOptions, canAdd, hasSyncableSources){ let list = SourcesListDefinition; var inventory_source; @@ -24,6 +25,7 @@ $scope.inventory_id = $stateParams.inventory_id; $scope.canAdhoc = inventoryData.summary_fields.user_capabilities.adhoc; $scope.canAdd = canAdd; + $scope.showSyncAll = hasSyncableSources; // Search init $scope.list = list; @@ -121,8 +123,8 @@ Wait('start'); SourcesService.delete(inventory_source.id).then(() => { $('#prompt-modal').modal('hide'); - if (parseInt($state.params.source_id) === inventory_source) { - $state.go("sources", null, {reload: true}); + if (parseInt($state.params.inventory_source_id) === inventory_source.id) { + $state.go("inventories.edit.inventory_sources", {inventory_id: $scope.inventory_id}, {reload: true}); } else { $state.go($state.current.name, null, {reload: true}); } @@ -161,4 +163,12 @@ $state.go('inventories.edit.inventory_sources.edit.schedules', {inventory_source_id: id}, {reload: true}); }; + $scope.syncAllSources = function() { + InventoryUpdate({ + scope: $scope, + url: inventoryData.related.update_inventory_sources, + updateAllSources: true + }); + }; + }]; diff --git a/awx/ui/client/src/inventories/sources/list/sources-list.route.js b/awx/ui/client/src/inventories/sources/list/sources-list.route.js index 1985469b0c..5664f38ac3 100644 --- a/awx/ui/client/src/inventories/sources/list/sources-list.route.js +++ b/awx/ui/client/src/inventories/sources/list/sources-list.route.js @@ -69,6 +69,24 @@ export default { .catch(function() { return false; }); + }], + hasSyncableSources: ['InventoryManageService', '$stateParams', function(InventoryManageService, $stateParams) { + return InventoryManageService.updateInventorySourcesGet($stateParams.inventory_id) + .then(function(res) { + let canUpdateFound = false; + if(res.data && res.data.length > 0) { + res.data.forEach(function(source) { + if(source.can_update) { + canUpdateFound = true; + } + }); + } + + return canUpdateFound; + }) + .catch(function() { + return false; + }); }] } }; diff --git a/awx/ui/client/src/inventories/sources/lookup/sources-lookup-project.route.js b/awx/ui/client/src/inventories/sources/lookup/sources-lookup-project.route.js new file mode 100644 index 0000000000..14614b24d1 --- /dev/null +++ b/awx/ui/client/src/inventories/sources/lookup/sources-lookup-project.route.js @@ -0,0 +1,50 @@ +export default { + params: { + project_search: { + value: { + page_size:"5", + order_by:"name", + role_level:"use_role", + }, + dynamic:true, + squash:"" + } + }, + data: { + basePath:"projects", + formChildState:true + }, + ncyBreadcrumb: { + skip: true + }, + views: { + 'modal': { + templateProvider: function(ListDefinition, generateList) { + let list_html = generateList.build({ + mode: 'lookup', + list: ListDefinition, + input_type: 'radio' + }); + return `${list_html}`; + + } + } + }, + resolve: { + ListDefinition: ['ProjectList', function(list) { + return list; + }], + Dataset: ['ListDefinition', 'QuerySet', '$stateParams', 'GetBasePath', + (list, qs, $stateParams, GetBasePath) => { + return qs.search(GetBasePath('projects'), $stateParams[`${list.iterator}_search`]); + } + ] + }, + onExit: function($state) { + if ($state.transition) { + $('#form-modal').modal('hide'); + $('.modal-backdrop').remove(); + $('body').removeClass('modal-open'); + } + } +}; diff --git a/awx/ui/client/src/inventories/sources/sources.list.js b/awx/ui/client/src/inventories/sources/sources.list.js index c0385e3672..5fc740f298 100644 --- a/awx/ui/client/src/inventories/sources/sources.list.js +++ b/awx/ui/client/src/inventories/sources/sources.list.js @@ -52,6 +52,15 @@ export default { actionClass: 'btn List-buttonDefault', buttonContent: 'REFRESH' }, + sync_all: { + mode: 'all', + awToolTip: "Sync all inventory sources", + ngClick: "syncAllSources()", + ngShow: "showSyncAll", + actionClass: 'btn List-buttonDefault', + buttonContent: 'SYNC ALL', + dataPlacement: "top" + }, create: { mode: 'all', ngClick: "createSource()",