Skip to content

Commit

Permalink
adding default image labels to chargback assignment.
Browse files Browse the repository at this point in the history
fix-minor mistakes

missing default options

freeze constant
  • Loading branch information
nimrodshn committed Jan 4, 2018
1 parent bfbd12f commit 7b9c3a2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
9 changes: 8 additions & 1 deletion app/controllers/chargeback_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 15 additions & 2 deletions app/views/chargeback/_cb_assignments.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
"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") {
$("#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
Expand All @@ -31,13 +35,22 @@
.form-group
%label.col-md-2.control-label
= _('Image Labels')
%a{:"data-toggle" => "popover",
:"data-html" => "true",
:"data-content" => "Lorem ipsum dolor sit amet, vis ex zril vulputate. Nec praesent urbanitas ut.",
:"data-placement" => "top"}
%span.pf-blue-info.pficon.pficon-info
.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();
miqSelectPickerEvent("cblabel_key", "#{url}")
$(document).ready(function() {
$('[data-toggle=popover]').popovers()
});
- unless @edit[:new][:cbshow_typ].nil? || @edit[:new][:cbshow_typ] == "nil"
- show_type = @edit[:new][:cbshow_typ]
- if !(show_type.ends_with?("-tags") || show_type.ends_with?("-labels")) || @edit[:new][:cbtag_cat].present? || @edit[:new][:cblabel_key].present?
Expand Down

0 comments on commit 7b9c3a2

Please sign in to comment.