Skip to content

Commit

Permalink
Allow to save multiple tag categories in chargeback controller
Browse files Browse the repository at this point in the history
@edit[:cb_assign][:tags] as you can see in
code(@edit[:cb_assign][cb_assign_key]) is bringing
selected chargeback rates for tags in selected tag category which is
stored in @edit[:new][:cbtag_cat]

to keep selected chargeback rates for any count of tag categories
we need to extend @edit[:cb_assign][:tags]  to
@edit[:cb_assign][:tags] [category_id]  and this hash can
keep multiple chargeback rates across any count of
tag categories.

we need to update code when chargeback rate is
selected (  in method cb_assign_params_to_edit called
controller action cb_assign_field_changed) and then
when we want to save this selection of chargeback rates
in cb_assign_update.
  • Loading branch information
lpichler committed Jul 17, 2018
1 parent 9a14b33 commit 205b3ae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 11 additions & 9 deletions app/controllers/chargeback_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,8 @@ def cb_rate_set_record_vars
def cb_assign_set_record_vars
if @edit[:new][:cbshow_typ].ends_with?("-tags")
@edit[:set_assignments] = []
@edit[:cb_assign][:tags].each do |id, _tag|
assigned_rates_from_all_categories = @edit[:cb_assign][:tags].values.reduce({}, :merge)
assigned_rates_from_all_categories.each_key do |id|
key = "#{@edit[:new][:cbshow_typ]}__#{id}"
if !@edit[:new][key].nil? && @edit[:new][key] != "nil"
temp = {
Expand Down Expand Up @@ -734,9 +735,10 @@ def get_categories_all
end

def get_tags_all(category)
@edit[:cb_assign][:tags] = {}
@edit[:cb_assign][:tags] ||= {}
@edit[:cb_assign][:tags][category] ||= {}
classification = Classification.find_by_id(category.to_s)
classification.entries.each { |e| @edit[:cb_assign][:tags][e.id.to_s] = e.description } if classification
classification.entries.each { |e| @edit[:cb_assign][:tags][category][e.id.to_s] = e.description } if classification
end

DEFAULT_CHARGEBACK_LABELS = ["com.redhat.component"].freeze
Expand Down Expand Up @@ -794,16 +796,16 @@ def get_cis_all
end
end

def cb_assign_params_to_edit(cb_assign_key)
return unless @edit[:cb_assign][cb_assign_key]
def cb_assign_params_to_edit(cb_assign_key, tag_category_id = nil)
current_assingments = cb_assign_key == :tags ? @edit[:cb_assign][cb_assign_key].try(:[], tag_category_id) : @edit[:cb_assign][cb_assign_key]

@edit[:cb_assign][cb_assign_key].each do |id, _ci|
return unless current_assingments
current_assingments.each_key do |id|
key = "#{@edit[:new][:cbshow_typ]}__#{id}"
@edit[:new][key] = params[key].to_s if params[key]
end
end


# Get variables from edit form
def cb_assign_get_form_vars
@edit[:new][:cbshow_typ] = params[:cbshow_typ] if params[:cbshow_typ]
Expand All @@ -814,7 +816,7 @@ def cb_assign_get_form_vars

if @edit[:new][:cbshow_typ].ends_with?("-tags")
get_categories_all
get_tags_all(params[:cbtag_cat]) if params[:cbtag_cat]
get_tags_all(params[:cbtag_cat].to_i) if params[:cbtag_cat]
elsif @edit[:new][:cbshow_typ].ends_with?("-labels")
get_docker_labels_all_keys
get_docker_labels_all_values(params[:cblabel_key]) unless params[:cblabel_key].blank?
Expand All @@ -823,7 +825,7 @@ def cb_assign_get_form_vars
end

cb_assign_params_to_edit(:cis)
cb_assign_params_to_edit(:tags)
cb_assign_params_to_edit(:tags, @edit[:new][:cbtag_cat].try(:to_i))
cb_assign_params_to_edit(:docker_label_values)
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/chargeback/_cb_assignments.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
%th= _('Name')
%th= _('Rate')
%tbody
- @edit[:cb_assign][:tags].invert.sort_by { |a| a.first.downcase }.each do |tag, id|
- @edit[:cb_assign][:tags][@edit[:new][:cbtag_cat].to_i].invert.sort_by { |a| a.first.downcase }.each do |tag, id|
%tr
%td
= h(tag)
Expand Down

0 comments on commit 205b3ae

Please sign in to comment.