Skip to content

Commit

Permalink
Merge pull request #17133 from gtanzillo/report-hidden-cols
Browse files Browse the repository at this point in the history
Support for hidden columns in reports and views
(cherry picked from commit 2206775)
  • Loading branch information
gmcculloug authored and simaishi committed May 29, 2018
1 parent 71ffa3f commit 0a950ab
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
10 changes: 10 additions & 0 deletions app/models/miq_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ def sort_col
sortby ? col_order.index(sortby.first) : 0
end

def column_is_hidden?(col)
return false unless col_options

@hidden_cols ||= col_options.keys.each_with_object([]) do |c, a|
a << c if col_options[c][:hidden]
end

@hidden_cols.include?(col.to_s)
end

def self.from_hash(h)
new(h)
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/miq_report/generator/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def build_html_rows(clickable_rows = false)
row = 1 - row

col_order.each_with_index do |c, c_idx|
next if column_is_hidden?(c)

build_html_col(output, c, self.col_formats[c_idx], d.data)
end

Expand Down
5 changes: 4 additions & 1 deletion lib/vmdb/global_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ def report_build_html_table(report, table_body)

# table headings
unless report.headers.nil?
report.headers.each do |h|
report.headers.each_with_index do |h, i|
col = report.col_order[i]
next if report.column_is_hidden?(col)

html << "<th>" << CGI.escapeHTML(_(h.to_s)) << "</th>"
end
html << "</tr>"
Expand Down
20 changes: 20 additions & 0 deletions spec/models/miq_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,26 @@ def generate_html_row(is_even, tenant_name, formatted_values)
end
end

describe "#column_is_hidden?" do
let(:report) do
MiqReport.new(
:name => "VMs",
:title => "Virtual Machines",
:db => "Vm",
:cols => %w(name guid hostname ems_ref vendor),
:col_order => %w(name hostname vendor guid emf_ref),
:headers => %w(Name Host Vendor Guid EMS),
:col_options => {"guid" => {:hidden => true}, "ems_ref" => {:hidden => true}}
)
end

it "detects hidden columns defined in #col_options" do
expect(report.column_is_hidden?(:guid)).to be_truthy
expect(report.column_is_hidden?(:ems_ref)).to be_truthy
expect(report.column_is_hidden?(:vendor)).to be_falsey
end
end

context "chargeback reports" do
let(:hourly_rate) { 0.01 }
let(:hourly_variable_tier_rate) { {:variable_rate => hourly_rate.to_s} }
Expand Down

0 comments on commit 0a950ab

Please sign in to comment.