From 5a7cbd90c670e3ca767daf948fc9d156d02c4761 Mon Sep 17 00:00:00 2001 From: Michael Abashian Date: Thu, 16 Jun 2016 13:47:51 -0400 Subject: [PATCH] Fixed bug where labels that matched existing labels appeared to be getting combined on JT create/edit --- .../job-templates/add/job-templates-add.controller.js | 11 +++++++++++ .../edit/job-templates-edit.controller.js | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/awx/ui/client/src/job-templates/add/job-templates-add.controller.js b/awx/ui/client/src/job-templates/add/job-templates-add.controller.js index bc754fa77e..2b96c0c5e9 100644 --- a/awx/ui/client/src/job-templates/add/job-templates-add.controller.js +++ b/awx/ui/client/src/job-templates/add/job-templates-add.controller.js @@ -513,8 +513,19 @@ data.survey_enabled = ($scope.survey_enabled && $scope.survey_exists) ? $scope.survey_enabled : false; + // The idea here is that we want to find the new option elements that also have a label that exists in the dom + $("#job_templates_labels > option").filter("[data-select2-tag=true]").each(function(optionIndex, option) { + $("#job_templates_labels").siblings(".select2").first().find(".select2-selection__choice").each(function(labelIndex, label) { + if($(option).text() === $(label).attr('title')) { + // Mark that the option has a label present so that we can filter by that down below + $(option).attr('data-label-is-present', true); + } + }); + }); + $scope.newLabels = $("#job_templates_labels > option") .filter("[data-select2-tag=true]") + .filter("[data-label-is-present=true]") .map((i, val) => ({name: $(val).text()})); Rest.setUrl(defaultUrl); diff --git a/awx/ui/client/src/job-templates/edit/job-templates-edit.controller.js b/awx/ui/client/src/job-templates/edit/job-templates-edit.controller.js index d1d488d15b..dc76b353b5 100644 --- a/awx/ui/client/src/job-templates/edit/job-templates-edit.controller.js +++ b/awx/ui/client/src/job-templates/edit/job-templates-edit.controller.js @@ -630,8 +630,19 @@ export default data.survey_enabled = ($scope.survey_enabled && $scope.survey_exists) ? $scope.survey_enabled : false; + // The idea here is that we want to find the new option elements that also have a label that exists in the dom + $("#job_templates_labels > option").filter("[data-select2-tag=true]").each(function(optionIndex, option) { + $("#job_templates_labels").siblings(".select2").first().find(".select2-selection__choice").each(function(labelIndex, label) { + if($(option).text() === $(label).attr('title')) { + // Mark that the option has a label present so that we can filter by that down below + $(option).attr('data-label-is-present', true); + } + }); + }); + $scope.newLabels = $("#job_templates_labels > option") .filter("[data-select2-tag=true]") + .filter("[data-label-is-present=true]") .map((i, val) => ({name: $(val).text()})); Rest.setUrl(defaultUrl + $state.params.id);