diff --git a/awx/ui/client/src/templates/prompt/prompt.controller.js b/awx/ui/client/src/templates/prompt/prompt.controller.js index cf92af6258..53a8370a0c 100644 --- a/awx/ui/client/src/templates/prompt/prompt.controller.js +++ b/awx/ui/client/src/templates/prompt/prompt.controller.js @@ -233,6 +233,38 @@ export default [ 'ProcessErrors', 'CredentialTypeModel', 'TemplatesStrings', '$f }, true); }; + function getSelectedTags(tagId) { + const selectedTags = []; + const choiceElements = $(tagId).siblings(".select2").first() + .find(".select2-selection__choice"); + choiceElements.each((index, option) => { + selectedTags.push({ + value: option.title, + name: option.title, + label: option.title + }); + }); + return selectedTags; + } + + function consolidateTags (tags, otherTags) { + const seen = []; + const consolidated = []; + tags.forEach(tag => { + if (!seen.includes(tag.value)) { + seen.push(tag.value); + consolidated.push(tag); + } + }); + otherTags.forEach(tag => { + if (!seen.includes(tag.value)) { + seen.push(tag.value); + consolidated.push(tag); + } + }); + return consolidated; + } + vm.next = (currentTab) => { if(_.has(vm, 'steps.other_prompts.tab._active') && vm.steps.other_prompts.tab._active === true){ try { @@ -243,6 +275,22 @@ export default [ 'ProcessErrors', 'CredentialTypeModel', 'TemplatesStrings', '$f event.preventDefault(); return; } + + // The current tag input state lives somewhere in the associated select2 + // widgetry and isn't directly tied to the vm, so extract the tag values + // and update the vm to keep it in sync. + if (vm.promptDataClone.launchConf.ask_tags_on_launch) { + vm.promptDataClone.prompts.tags.value = consolidateTags( + angular.copy(vm.promptDataClone.prompts.tags.value), + getSelectedTags("#job_launch_job_tags") + ); + } + if (vm.promptDataClone.launchConf.ask_skip_tags_on_launch) { + vm.promptDataClone.prompts.skipTags.value = consolidateTags( + angular.copy(vm.promptDataClone.prompts.skipTags.value), + getSelectedTags("#job_launch_skip_tags") + ); + } } let nextStep; diff --git a/awx/ui/client/src/templates/prompt/steps/preview/prompt-preview.controller.js b/awx/ui/client/src/templates/prompt/steps/preview/prompt-preview.controller.js index 0895994041..94c5dd8b9f 100644 --- a/awx/ui/client/src/templates/prompt/steps/preview/prompt-preview.controller.js +++ b/awx/ui/client/src/templates/prompt/steps/preview/prompt-preview.controller.js @@ -12,19 +12,6 @@ export default let scope; - let consolidateTags = (tagModel, tagId) => { - let tags = angular.copy(tagModel); - $(tagId).siblings(".select2").first().find(".select2-selection__choice").each((optionIndex, option) => { - tags.push({ - value: option.title, - name: option.title, - label: option.title - }); - }); - - return [...tags.reduce((map, tag) => map.has(tag.value) ? map : map.set(tag.value, tag), new Map()).values()]; - }; - vm.init = (_scope_) => { scope = _scope_; @@ -35,14 +22,6 @@ export default const surveyPasswords = {}; - if (scope.promptData.launchConf.ask_tags_on_launch) { - scope.promptData.prompts.tags.value = consolidateTags(scope.promptData.prompts.tags.value, "#job_launch_job_tags"); - } - - if (scope.promptData.launchConf.ask_skip_tags_on_launch) { - scope.promptData.prompts.skipTags.value = consolidateTags(scope.promptData.prompts.skipTags.value, "#job_launch_skip_tags"); - } - if (scope.promptData.launchConf.survey_enabled){ scope.promptData.extraVars = ToJSON(scope.parseType, scope.promptData.prompts.variables.value, false); scope.promptData.surveyQuestions.forEach(surveyQuestion => {