diff --git a/app/models/miq_report.rb b/app/models/miq_report.rb index ab03217f1759..79caf84230fe 100644 --- a/app/models/miq_report.rb +++ b/app/models/miq_report.rb @@ -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 diff --git a/app/models/miq_report/generator/html.rb b/app/models/miq_report/generator/html.rb index 93e99798b503..605ca7a2b4de 100644 --- a/app/models/miq_report/generator/html.rb +++ b/app/models/miq_report/generator/html.rb @@ -45,7 +45,7 @@ def build_html_rows(clickable_rows = false) row = 1 - row col_order.each_with_index do |c, c_idx| - next if col_options[c].try(:has_key?, :hidden) && col_options[c][:hidden] + next if column_is_hidden?(c) build_html_col(output, c, self.col_formats[c_idx], d.data) end diff --git a/lib/vmdb/global_methods.rb b/lib/vmdb/global_methods.rb index a198cd2b1a8d..af66c0e46de3 100644 --- a/lib/vmdb/global_methods.rb +++ b/lib/vmdb/global_methods.rb @@ -94,7 +94,7 @@ def report_build_html_table(report, table_body) unless report.headers.nil? report.headers.each_with_index do |h, i| col = report.col_order[i] - next if report.col_options[col].try(:has_key?, :hidden) && report.col_options[col][:hidden] + next if report.column_is_hidden?(col) html << "" << CGI.escapeHTML(_(h.to_s)) << "" end diff --git a/spec/models/miq_report_spec.rb b/spec/models/miq_report_spec.rb index ebcf6df75bb2..975014f97282 100644 --- a/spec/models/miq_report_spec.rb +++ b/spec/models/miq_report_spec.rb @@ -847,6 +847,26 @@ def generate_html_row(is_even, tenant_name, formatted_values) end end + describe "#column_is_hidden?" do + let(:report) { + 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}} + ) + } + + 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} }