Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for hidden columns in reports and views #17133

Merged
merged 2 commits into from
Mar 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -847,6 +847,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