From e99e97bcb827c75508509e8e36394fff8ee49959 Mon Sep 17 00:00:00 2001 From: mabashian Date: Sun, 31 Mar 2019 13:45:24 -0400 Subject: [PATCH] Adds support for custom_virutalenv on inventory sources in the UI --- .../sources/add/sources-add.controller.js | 30 ++++++++++++------- .../related/sources/add/sources-add.route.js | 10 +++++++ .../sources/edit/sources-edit.controller.js | 13 ++++++-- .../sources/edit/sources-edit.route.js | 10 +++++++ .../related/sources/sources.form.js | 13 ++++++++ 5 files changed, 63 insertions(+), 13 deletions(-) diff --git a/awx/ui/client/src/inventories-hosts/inventories/related/sources/add/sources-add.controller.js b/awx/ui/client/src/inventories-hosts/inventories/related/sources/add/sources-add.controller.js index c4c7521859..72bdc53d5e 100644 --- a/awx/ui/client/src/inventories-hosts/inventories/related/sources/add/sources-add.controller.js +++ b/awx/ui/client/src/inventories-hosts/inventories/related/sources/add/sources-add.controller.js @@ -4,16 +4,15 @@ * All Rights Reserved *************************************************/ -export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition', - 'ParseTypeChange', 'GenerateForm', 'inventoryData', 'GroupsService', - 'GetChoices', 'GetBasePath', 'CreateSelect2', 'GetSourceTypeOptions', - 'rbacUiControlService', 'ToJSON', 'SourcesService', 'Empty', - 'Wait', 'Rest', 'Alert', 'ProcessErrors', 'inventorySourcesOptions', - '$rootScope', 'i18n', 'InventorySourceModel', 'InventoryHostsStrings', - function($state, $stateParams, $scope, SourcesFormDefinition, ParseTypeChange, - GenerateForm, inventoryData, GroupsService, GetChoices, - GetBasePath, CreateSelect2, GetSourceTypeOptions, rbacUiControlService, - ToJSON, SourcesService, Empty, Wait, Rest, Alert, ProcessErrors, +export default ['$state', 'ConfigData', '$scope', 'SourcesFormDefinition', 'ParseTypeChange', + 'GenerateForm', 'inventoryData', 'GetChoices', + 'GetBasePath', 'CreateSelect2', 'GetSourceTypeOptions', + 'SourcesService', 'Empty', 'Wait', 'Rest', 'Alert', 'ProcessErrors', + 'inventorySourcesOptions', '$rootScope', 'i18n', 'InventorySourceModel', 'InventoryHostsStrings', + function($state, ConfigData, $scope, SourcesFormDefinition, ParseTypeChange, + GenerateForm, inventoryData, GetChoices, + GetBasePath, CreateSelect2, GetSourceTypeOptions, + SourcesService, Empty, Wait, Rest, Alert, ProcessErrors, inventorySourcesOptions,$rootScope, i18n, InventorySource, InventoryHostsStrings) { let form = SourcesFormDefinition; @@ -22,6 +21,8 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition', GenerateForm.applyDefaults(form, $scope, true); $scope.canAdd = inventorySourcesOptions.actions.POST; $scope.envParseType = 'yaml'; + const virtualEnvs = ConfigData.custom_virtualenvs || []; + $scope.custom_virtualenvs_options = virtualEnvs; GetChoices({ scope: $scope, @@ -80,6 +81,12 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition', $scope.verbosity = $scope.verbosity_options[1]; + CreateSelect2({ + element: '#inventory_source_custom_virtualenv', + multiple: false, + opts: $scope.custom_virtualenvs_options + }); + GetSourceTypeOptions({ scope: $scope, variable: 'source_type_options' @@ -279,9 +286,10 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition', update_on_launch: $scope.update_on_launch, verbosity: $scope.verbosity.value, update_cache_timeout: $scope.update_cache_timeout || 0, + custom_virtualenv: $scope.custom_virtualenv || null, // comma-delimited strings group_by: SourcesService.encodeGroupBy($scope.source, $scope.group_by), - source_regions: _.map($scope.source_regions, 'value').join(',') + source_regions: _.map($scope.source_regions, 'value').join(','), }; if ($scope.source) { diff --git a/awx/ui/client/src/inventories-hosts/inventories/related/sources/add/sources-add.route.js b/awx/ui/client/src/inventories-hosts/inventories/related/sources/add/sources-add.route.js index 897a8446ba..dc53ded31a 100644 --- a/awx/ui/client/src/inventories-hosts/inventories/related/sources/add/sources-add.route.js +++ b/awx/ui/client/src/inventories-hosts/inventories/related/sources/add/sources-add.route.js @@ -25,6 +25,16 @@ export default { .then(function(res) { return res.data; }); + }], + ConfigData: ['ConfigService', 'ProcessErrors', 'i18n', (ConfigService, ProcessErrors, i18n) => { + return ConfigService.getConfig() + .then(response => response) + .catch(({data, status}) => { + ProcessErrors(null, data, status, null, { + hdr: i18n._('Error!'), + msg: i18n._('Failed to get config. GET returned status: ') + status + }); + }); }] } }; diff --git a/awx/ui/client/src/inventories-hosts/inventories/related/sources/edit/sources-edit.controller.js b/awx/ui/client/src/inventories-hosts/inventories/related/sources/edit/sources-edit.controller.js index ac1a315882..8a60e5fea3 100644 --- a/awx/ui/client/src/inventories-hosts/inventories/related/sources/edit/sources-edit.controller.js +++ b/awx/ui/client/src/inventories-hosts/inventories/related/sources/edit/sources-edit.controller.js @@ -8,18 +8,20 @@ export default ['$state', '$scope', 'ParseVariableString', 'ParseTypeChange', 'GetChoices', 'GetBasePath', 'CreateSelect2', 'GetSourceTypeOptions', 'SourcesService', 'inventoryData', 'inventorySourcesOptions', 'Empty', 'Wait', 'Rest', 'Alert', '$rootScope', 'i18n', 'InventoryHostsStrings', - 'ProcessErrors', 'inventorySource', 'isNotificationAdmin', + 'ProcessErrors', 'inventorySource', 'isNotificationAdmin', 'ConfigData', function($state, $scope, ParseVariableString, ParseTypeChange, GetChoices, GetBasePath, CreateSelect2, GetSourceTypeOptions, SourcesService, inventoryData, inventorySourcesOptions, Empty, Wait, Rest, Alert, $rootScope, i18n, InventoryHostsStrings, - ProcessErrors, inventorySource, isNotificationAdmin) { + ProcessErrors, inventorySource, isNotificationAdmin, ConfigData) { const inventorySourceData = inventorySource.get(); $scope.projectBasePath = GetBasePath('projects') + '?not__status=never updated'; $scope.canAdd = inventorySourcesOptions.actions.POST; $scope.isNotificationAdmin = isNotificationAdmin || false; + const virtualEnvs = ConfigData.custom_virtualenvs || []; + $scope.custom_virtualenvs_options = virtualEnvs; // instantiate expected $scope values from inventorySourceData _.assign($scope, {credential: inventorySourceData.credential}, @@ -157,6 +159,12 @@ export default ['$state', '$scope', 'ParseVariableString', 'ParseTypeChange', } } + CreateSelect2({ + element: '#inventory_source_custom_virtualenv', + multiple: false, + opts: $scope.custom_virtualenvs_options + }); + initVerbositySelect(); $scope.$watch('verbosity', initVerbositySelect); @@ -329,6 +337,7 @@ export default ['$state', '$scope', 'ParseVariableString', 'ParseTypeChange', update_on_launch: $scope.update_on_launch, update_cache_timeout: $scope.update_cache_timeout || 0, verbosity: $scope.verbosity.value, + custom_virtualenv: $scope.custom_virtualenv || null, // comma-delimited strings group_by: SourcesService.encodeGroupBy($scope.source, $scope.group_by), source_regions: _.map($scope.source_regions, 'value').join(',') diff --git a/awx/ui/client/src/inventories-hosts/inventories/related/sources/edit/sources-edit.route.js b/awx/ui/client/src/inventories-hosts/inventories/related/sources/edit/sources-edit.route.js index 4f3fa52a5c..e66cb0b691 100644 --- a/awx/ui/client/src/inventories-hosts/inventories/related/sources/edit/sources-edit.route.js +++ b/awx/ui/client/src/inventories-hosts/inventories/related/sources/edit/sources-edit.route.js @@ -38,6 +38,16 @@ export default { msg: i18n._('Failed to get organizations for which this user is a notification administrator. GET returned ') + status }); }); + }], + ConfigData: ['ConfigService', 'ProcessErrors', 'i18n', (ConfigService, ProcessErrors, i18n) => { + return ConfigService.getConfig() + .then(response => response) + .catch(({data, status}) => { + ProcessErrors(null, data, status, null, { + hdr: i18n._('Error!'), + msg: i18n._('Failed to get config. GET returned status: ') + status + }); + }); }] } }; diff --git a/awx/ui/client/src/inventories-hosts/inventories/related/sources/sources.form.js b/awx/ui/client/src/inventories-hosts/inventories/related/sources/sources.form.js index 2a2c01d389..132403527e 100644 --- a/awx/ui/client/src/inventories-hosts/inventories/related/sources/sources.form.js +++ b/awx/ui/client/src/inventories-hosts/inventories/related/sources/sources.form.js @@ -56,6 +56,19 @@ export default ['NotificationsList', 'i18n', function(NotificationsList, i18n){ ngModel: 'source', hasSubForm: true }, + custom_virtualenv: { + label: i18n._('Ansible Environment'), + type: 'select', + defaultText: i18n._('Use Default Environment'), + ngOptions: 'venv for venv in custom_virtualenvs_options track by venv', + + awPopOver: "

" + i18n._("Select the custom Python virtual environment for this inventory source sync to run on.") + "

", + dataTitle: i18n._('Ansible Environment'), + dataContainer: 'body', + dataPlacement: 'right', + ngDisabled: '!(inventory_source_obj.summary_fields.user_capabilities.edit || canAdd)', + ngShow: 'custom_virtualenvs_options.length > 1' + }, credential: { label: i18n._('Credential'), type: 'lookup',