From 8adb501eb82318be0fc15c7e4dedca74f78203b2 Mon Sep 17 00:00:00 2001 From: Jake McDermott Date: Mon, 12 Jun 2017 13:30:20 -0400 Subject: [PATCH] Add prompt on launch for 'verbosity' JT field (#6475) --- .../launchjob.factory.js | 4 +++ .../job-submission.controller.js | 36 +++++++++++++++++-- .../job-submission.directive.js | 5 +++ .../job-submission.partial.html | 32 ++++++++++++++--- awx/ui/client/src/shared/Utilities.js | 2 +- .../client/src/templates/job-template.form.js | 6 +++- .../job-template-add.controller.js | 1 + .../job-template-edit.controller.js | 1 + .../factories/callback-help-init.factory.js | 3 ++ 9 files changed, 81 insertions(+), 9 deletions(-) diff --git a/awx/ui/client/src/job-submission/job-submission-factories/launchjob.factory.js b/awx/ui/client/src/job-submission/job-submission-factories/launchjob.factory.js index 6179ec1b1d..fc26bf7cb2 100644 --- a/awx/ui/client/src/job-submission/job-submission-factories/launchjob.factory.js +++ b/awx/ui/client/src/job-submission/job-submission-factories/launchjob.factory.js @@ -66,6 +66,10 @@ export default job_launch_data.job_type = scope.other_prompt_data.job_type; } + if(scope.ask_verbosity_on_launch && scope.other_prompt_data && scope.other_prompt_data.verbosity) { + job_launch_data.verbosity = scope.other_prompt_data.verbosity; + } + if(scope.survey_enabled===true){ for (var i=0; i < scope.survey_questions.length; i++){ var fld = scope.survey_questions[i].variable; diff --git a/awx/ui/client/src/job-submission/job-submission.controller.js b/awx/ui/client/src/job-submission/job-submission.controller.js index 6f6e5ffd46..3c9d7791c8 100644 --- a/awx/ui/client/src/job-submission/job-submission.controller.js +++ b/awx/ui/client/src/job-submission/job-submission.controller.js @@ -172,7 +172,7 @@ export default // General catch-all for "other prompts" - used in this link function and to hide the Other Prompts tab when // it should be hidden - $scope.has_other_prompts = (data.ask_job_type_on_launch || data.ask_limit_on_launch || data.ask_tags_on_launch || data.ask_skip_tags_on_launch || data.ask_variables_on_launch) ? true : false; + $scope.has_other_prompts = (data.ask_verbosity_on_launch || data.ask_job_type_on_launch || data.ask_limit_on_launch || data.ask_tags_on_launch || data.ask_skip_tags_on_launch || data.ask_variables_on_launch) ? true : false; $scope.password_needed = data.passwords_needed_to_start && data.passwords_needed_to_start.length > 0; $scope.has_default_inventory = data.defaults && data.defaults.inventory && data.defaults.inventory.id; $scope.has_default_credential = data.defaults && data.defaults.credential && data.defaults.credential.id; @@ -180,8 +180,38 @@ export default $scope.other_prompt_data = {}; - if($scope.ask_job_type_on_launch) { - $scope.other_prompt_data.job_type = (data.defaults && data.defaults.job_type) ? data.defaults.job_type : ""; + let getChoices = (options, lookup) => { + return _.get(options, lookup, []).map(c => ({label: c[1], value: c[0]})); + }; + + let getChoiceFromValue = (choices, value) => { + return _.find(choices, item => item.value === value); + }; + + if ($scope.has_other_prompts) { + Rest.options() + .success(options => { + if ($scope.ask_job_type_on_launch) { + let choices = getChoices(options, 'actions.POST.job_type.choices'); + let initialValue = _.get(data, 'defaults.job_type'); + let initialChoice = getChoiceFromValue(choices, initialValue); + $scope.other_prompt_data.job_type_options = choices; + $scope.other_prompt_data.job_type = initialChoice; + } + if ($scope.ask_verbosity_on_launch) { + let choices = getChoices(options, 'actions.POST.verbosity.choices'); + let initialValue = _.get(data, 'defaults.verbosity'); + let initialChoice = getChoiceFromValue(choices, initialValue); + $scope.other_prompt_data.verbosity_options = choices; + $scope.other_prompt_data.verbosity = initialChoice; + } + }) + .error((err, status) => { + ProcessErrors($scope, err, status, null, { + hdr: 'Error!', + msg: `Failed to get ${launch_url}. OPTIONS status: ${status}` + }); + }); } if($scope.ask_limit_on_launch) { diff --git a/awx/ui/client/src/job-submission/job-submission.directive.js b/awx/ui/client/src/job-submission/job-submission.directive.js index 639afd7790..e4108124cf 100644 --- a/awx/ui/client/src/job-submission/job-submission.directive.js +++ b/awx/ui/client/src/job-submission/job-submission.directive.js @@ -50,6 +50,11 @@ export default [ 'templateUrl', 'CreateDialog', 'Wait', 'CreateSelect2', 'ParseT multiple: false }); + CreateSelect2({ + element: '#job_launch_verbosity', + multiple: false + }); + if(scope.step === 'otherprompts' && scope.ask_variables_on_launch) { ParseTypeChange({ scope: scope, diff --git a/awx/ui/client/src/job-submission/job-submission.partial.html b/awx/ui/client/src/job-submission/job-submission.partial.html index 0f32e35d3d..3cdcb2077a 100644 --- a/awx/ui/client/src/job-submission/job-submission.partial.html +++ b/awx/ui/client/src/job-submission/job-submission.partial.html @@ -144,15 +144,39 @@ +
+ +
+ +
+
- +
diff --git a/awx/ui/client/src/shared/Utilities.js b/awx/ui/client/src/shared/Utilities.js index 03fc319bc2..05edd54917 100644 --- a/awx/ui/client/src/shared/Utilities.js +++ b/awx/ui/client/src/shared/Utilities.js @@ -790,7 +790,7 @@ angular.module('Utilities', ['RestServices', 'Utilities']) .error(function(data, status) { ProcessErrors(scope, data, status, null, { hdr: 'Error!', - msg: 'Failed to get ' + url + '. GET status: ' + status + msg: 'Failed to get ' + url + '. OPTIONS status: ' + status }); }); } else { diff --git a/awx/ui/client/src/templates/job-template.form.js b/awx/ui/client/src/templates/job-template.form.js index 5431f5f0b6..a25d42eae4 100644 --- a/awx/ui/client/src/templates/job-template.form.js +++ b/awx/ui/client/src/templates/job-template.form.js @@ -241,7 +241,11 @@ function(NotificationsList, CompletedJobsList, i18n) { dataTitle: i18n._('Verbosity'), dataPlacement: 'right', dataContainer: "body", - ngDisabled: '!(job_template_obj.summary_fields.user_capabilities.edit || canAddJobTemplate)' + subCheckbox: { + variable: 'ask_verbosity_on_launch', + text: i18n._('Prompt on launch') + }, + ngDisabled: '!(job_template_obj.summary_fields.user_capabilities.edit || canAddJobTemplate)', }, instance_groups: { label: i18n._('Instance Groups'), diff --git a/awx/ui/client/src/templates/job_templates/add-job-template/job-template-add.controller.js b/awx/ui/client/src/templates/job_templates/add-job-template/job-template-add.controller.js index 01d42d05a8..06985f83f5 100644 --- a/awx/ui/client/src/templates/job_templates/add-job-template/job-template-add.controller.js +++ b/awx/ui/client/src/templates/job_templates/add-job-template/job-template-add.controller.js @@ -408,6 +408,7 @@ data.ask_skip_tags_on_launch = $scope.ask_skip_tags_on_launch ? $scope.ask_skip_tags_on_launch : false; data.ask_limit_on_launch = $scope.ask_limit_on_launch ? $scope.ask_limit_on_launch : false; data.ask_job_type_on_launch = $scope.ask_job_type_on_launch ? $scope.ask_job_type_on_launch : false; + data.ask_verbosity_on_launch = $scope.ask_verbosity_on_launch ? $scope.ask_verbosity_on_launch : false; data.ask_inventory_on_launch = $scope.ask_inventory_on_launch ? $scope.ask_inventory_on_launch : false; data.ask_variables_on_launch = $scope.ask_variables_on_launch ? $scope.ask_variables_on_launch : false; data.ask_credential_on_launch = $scope.ask_credential_on_launch ? $scope.ask_credential_on_launch : false; diff --git a/awx/ui/client/src/templates/job_templates/edit-job-template/job-template-edit.controller.js b/awx/ui/client/src/templates/job_templates/edit-job-template/job-template-edit.controller.js index 0c7c01bfc2..5f0103658a 100644 --- a/awx/ui/client/src/templates/job_templates/edit-job-template/job-template-edit.controller.js +++ b/awx/ui/client/src/templates/job_templates/edit-job-template/job-template-edit.controller.js @@ -577,6 +577,7 @@ export default data.ask_skip_tags_on_launch = $scope.ask_skip_tags_on_launch ? $scope.ask_skip_tags_on_launch : false; data.ask_limit_on_launch = $scope.ask_limit_on_launch ? $scope.ask_limit_on_launch : false; data.ask_job_type_on_launch = $scope.ask_job_type_on_launch ? $scope.ask_job_type_on_launch : false; + data.ask_verbosity_on_launch = $scope.ask_verbosity_on_launch ? $scope.ask_verbosity_on_launch : false; data.ask_inventory_on_launch = $scope.ask_inventory_on_launch ? $scope.ask_inventory_on_launch : false; data.ask_variables_on_launch = $scope.ask_variables_on_launch ? $scope.ask_variables_on_launch : false; data.ask_credential_on_launch = $scope.ask_credential_on_launch ? $scope.ask_credential_on_launch : false; diff --git a/awx/ui/client/src/templates/job_templates/factories/callback-help-init.factory.js b/awx/ui/client/src/templates/job_templates/factories/callback-help-init.factory.js index 5f7f6318d6..845216c459 100644 --- a/awx/ui/client/src/templates/job_templates/factories/callback-help-init.factory.js +++ b/awx/ui/client/src/templates/job_templates/factories/callback-help-init.factory.js @@ -103,6 +103,9 @@ export default scope.ask_variables_on_launch = (data.ask_variables_on_launch) ? true : false; master.ask_variables_on_launch = scope.ask_variables_on_launch; + scope.ask_verbosity_on_launch = (data.ask_verbosity_on_launch) ? true : false; + master.ask_verbosity_on_launch = scope.ask_verbosity_on_launch; + scope.ask_limit_on_launch = (data.ask_limit_on_launch) ? true : false; master.ask_limit_on_launch = scope.ask_limit_on_launch;