From 16b00e486797b4cb18d0f030ab481a7482e2b35b Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Tue, 22 May 2018 15:35:21 -0700 Subject: [PATCH] Validates extra vars before moving to next step in prompt workflow --- .../src/templates/prompt/prompt.controller.js | 17 +++++++++++++++++ .../src/templates/prompt/prompt.partial.html | 2 +- .../prompt-other-prompts.controller.js | 9 ++++++++- .../prompt-other-prompts.directive.js | 3 ++- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/awx/ui/client/src/templates/prompt/prompt.controller.js b/awx/ui/client/src/templates/prompt/prompt.controller.js index 362e1223fe..2f7baae551 100644 --- a/awx/ui/client/src/templates/prompt/prompt.controller.js +++ b/awx/ui/client/src/templates/prompt/prompt.controller.js @@ -158,6 +158,13 @@ export default [ 'Rest', 'GetBasePath', 'ProcessErrors', 'CredentialTypeModel', order: order }; order++; + + let codemirror = () => { + return { + validate:{} + }; + }; + vm.codeMirror = new codemirror(); } if(vm.promptDataClone.launchConf.survey_enabled) { vm.steps.survey.includeStep = true; @@ -189,6 +196,16 @@ export default [ 'Rest', 'GetBasePath', 'ProcessErrors', 'CredentialTypeModel', }; vm.next = (currentTab) => { + if(_.has(vm.steps.other_prompts, 'tab._active') && vm.steps.other_prompts.tab._active === true){ + try { + if (vm.codeMirror.validate) { + vm.codeMirror.validate(); + } + } catch (err) { + event.preventDefault(); + return; + } + } Object.keys(vm.steps).forEach(step => { if(vm.steps[step].tab) { if(vm.steps[step].tab.order === currentTab.order) { diff --git a/awx/ui/client/src/templates/prompt/prompt.partial.html b/awx/ui/client/src/templates/prompt/prompt.partial.html index 820ea8553d..e336f35744 100644 --- a/awx/ui/client/src/templates/prompt/prompt.partial.html +++ b/awx/ui/client/src/templates/prompt/prompt.partial.html @@ -19,7 +19,7 @@
- +
diff --git a/awx/ui/client/src/templates/prompt/steps/other-prompts/prompt-other-prompts.controller.js b/awx/ui/client/src/templates/prompt/steps/other-prompts/prompt-other-prompts.controller.js index 96a087218d..71af177f87 100644 --- a/awx/ui/client/src/templates/prompt/steps/other-prompts/prompt-other-prompts.controller.js +++ b/awx/ui/client/src/templates/prompt/steps/other-prompts/prompt-other-prompts.controller.js @@ -5,7 +5,7 @@ *************************************************/ export default - ['ParseTypeChange', 'CreateSelect2', 'TemplatesStrings', '$timeout', function(ParseTypeChange, CreateSelect2, strings, $timeout) { + ['ParseTypeChange', 'CreateSelect2', 'TemplatesStrings', '$timeout', 'ToJSON', function(ParseTypeChange, CreateSelect2, strings, $timeout, ToJSON) { const vm = this; vm.strings = strings; @@ -79,8 +79,15 @@ export default codemirrorExtraVars(); } }); + + function validate () { + return ToJSON(scope.parseType, scope.extraVariables, true); + } + scope.validate = validate; }; + + vm.toggleDiff = () => { scope.promptData.prompts.diffMode.value = !scope.promptData.prompts.diffMode.value; }; diff --git a/awx/ui/client/src/templates/prompt/steps/other-prompts/prompt-other-prompts.directive.js b/awx/ui/client/src/templates/prompt/steps/other-prompts/prompt-other-prompts.directive.js index c551fc8bd7..3a4990ae10 100644 --- a/awx/ui/client/src/templates/prompt/steps/other-prompts/prompt-other-prompts.directive.js +++ b/awx/ui/client/src/templates/prompt/steps/other-prompts/prompt-other-prompts.directive.js @@ -12,7 +12,8 @@ export default [ 'templateUrl', scope: { promptData: '=', otherPromptsForm: '=', - isActiveStep: '=' + isActiveStep: '=', + validate: '=' }, templateUrl: templateUrl('templates/prompt/steps/other-prompts/prompt-other-prompts'), controller: promptOtherPrompts,