From 55af06792c9a5de556b41e0ac26bf53377ab51f6 Mon Sep 17 00:00:00 2001 From: nimrodshn Date: Thu, 28 Dec 2017 17:47:11 +0200 Subject: [PATCH] adding default image labels to chargback assignment. fix-minor mistakes missing default options freeze constant removing popover and adding comments --- app/controllers/chargeback_controller.rb | 9 ++++++++- app/views/chargeback/_cb_assignments.html.haml | 10 ++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/controllers/chargeback_controller.rb b/app/controllers/chargeback_controller.rb index 6a434544e36..9f3794a7ab5 100644 --- a/app/controllers/chargeback_controller.rb +++ b/app/controllers/chargeback_controller.rb @@ -747,10 +747,17 @@ def get_tags_all(category) classification.entries.each { |e| @edit[:cb_assign][:tags][e.id.to_s] = e.description } if classification end + DEFAULT_CHARGEBACK_LABELS = ["com.redhat.component"].freeze + def get_docker_labels_all_keys @edit[:cb_assign][:docker_label_keys] = {} + @edit[:cb_assign][:docker_label_default_keys] = {} CustomAttribute.where(:section => "docker_labels").pluck(:id, :name).uniq(&:second).each do |label| - @edit[:cb_assign][:docker_label_keys][label.first.to_s] = label.second + if DEFAULT_CHARGEBACK_LABELS.include?(label.second) + @edit[:cb_assign][:docker_label_default_keys][label.first.to_s] = label.second + else + @edit[:cb_assign][:docker_label_keys][label.first.to_s] = label.second + end end end diff --git a/app/views/chargeback/_cb_assignments.html.haml b/app/views/chargeback/_cb_assignments.html.haml index 0442ad4885d..6f352e0edb2 100644 --- a/app/views/chargeback/_cb_assignments.html.haml +++ b/app/views/chargeback/_cb_assignments.html.haml @@ -15,7 +15,12 @@ "data-miq_sparkle_on" => true, "data-miq_sparkle_off" => true, :class => "selectpicker") :javascript miqInitSelectPicker(); - miqSelectPickerEvent("cbshow_typ", "#{url}") + miqSelectPickerEvent("cbshow_typ", "#{url}", {callback: function() { + if ($('#cbshow_typ').val() == "container_image-labels") { + // trigger dropdown change for when container_image-labels is picked so that the default image will be loaded to the view. + $("#cblabel_key").trigger('change'); + } + }}); - if !@edit[:new][:cbshow_typ].blank? && @edit[:new][:cbshow_typ].ends_with?("-tags") .form-group %label.col-md-2.control-label @@ -32,8 +37,9 @@ %label.col-md-2.control-label = _('Image Labels') .col-md-8 + - default_options = Array(@edit[:cb_assign][:docker_label_default_keys].invert).sort_by { |a| a.first.downcase } - options = Array(@edit[:cb_assign][:docker_label_keys].invert).sort_by { |a| a.first.downcase } - = select_tag("cblabel_key", options_for_select([["<#{_('Choose a Label')}>", ""]] + options, @edit[:new][:cblabel_key].to_s), + = select_tag("cblabel_key", options_for_select(default_options + options, @edit[:new][:cblabel_key].to_s), "data-miq_sparkle_on" => true, "data-miq_sparkle_off" => true, :class => "selectpicker") :javascript miqInitSelectPicker();