Skip to content

Commit

Permalink
Merge pull request #3564 from gtanzillo/report-hidden-cols-ui
Browse files Browse the repository at this point in the history
Support for hidden columns in reports and views
  • Loading branch information
Dan Clarizio authored Mar 20, 2018
2 parents a2d7a8e + bbda297 commit adb24a0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,9 @@ def view_to_hash(view, fetch_data = false)
end

view.headers.each_with_index do |h, i|
col = view.col_order[i]
next if view.column_is_hidden?(col)

align = [:fixnum, :integer, :Fixnum, :float].include?(column_type(view.db, view.col_order[i])) ? 'right' : 'left'

root[:head] << {:text => h,
Expand Down Expand Up @@ -1025,6 +1028,8 @@ def view_to_hash(view, fetch_data = false)
end

view.col_order.each_with_index do |col, col_idx|
next if view.column_is_hidden?(col)

celltext = nil

case view.col_order[col_idx]
Expand Down
6 changes: 6 additions & 0 deletions lib/report_formatter/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ def build_document_header

return if mri.headers.empty?
c = mri.headers.dup
# Remove headers of hidden columns
mri.col_order.each_with_index do |f, i|
c.delete_at(i) if mri.column_is_hidden?(f)
end
c.each_with_index do |f, i|
c[i] = f.to_s.center(@max_col_width[i])
end
Expand Down Expand Up @@ -107,6 +111,8 @@ def build_document_body
end
mri.col_formats ||= [] # Backward compat - create empty array for formats
mri.col_order.each_with_index do |f, i|
next if mri.column_is_hidden?(f)

unless ["<compare>", "<drift>"].include?(mri.db)
data = mri.format(f,
r[f],
Expand Down
37 changes: 37 additions & 0 deletions spec/controllers/host_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,43 @@
ApplicationController.handle_exceptions = true
end

it "renders index" do
get :index
expect(response.status).to eq(302)
expect(response).to redirect_to(:action => 'show_list')
end

it "renders show_list and does not include hidden column" do
allow(controller).to receive(:render)
report = FactoryGirl.create(:miq_report,
:name => 'Hosts',
:title => 'Hosts',
:cols => %w(name ipaddress v_total_vms),
:col_order => %w(name ipaddress v_total_vms),
:headers => %w(Name IP\ Address VMs),
:col_options => {"name" => {:hidden => true}})
expect(controller).to receive(:get_db_view).and_return(report)
controller.send(:report_data)
view_hash = controller.send(:view_to_hash, assigns(:view))
expect(view_hash[:head]).not_to include(:text => "Name", :sort => "str", :col_idx => 0, :align => "left")
expect(view_hash[:head]).to include(:text => "IP Address", :sort => "str", :col_idx => 1, :align => "left")
end

it "renders show_list and includes all columns" do
allow(controller).to receive(:render)
report = FactoryGirl.create(:miq_report,
:name => 'Hosts',
:title => 'Hosts',
:cols => %w(name ipaddress v_total_vms),
:col_order => %w(name ipaddress v_total_vms),
:headers => %w(Name IP\ Address VMs))
expect(controller).to receive(:get_db_view).and_return(report)
controller.send(:report_data)
view_hash = controller.send(:view_to_hash, assigns(:view))
expect(view_hash[:head]).to include(:text => "Name", :sort => "str", :col_idx => 0, :align => "left")
expect(view_hash[:head]).to include(:text => "IP Address", :sort => "str", :col_idx => 1, :align => "left")
end

it 'edit renders GTL grid with selected Host records' do
session[:host_items] = [h1.id, h2.id]
session[:settings] = {:views => {:host => 'grid'},
Expand Down

0 comments on commit adb24a0

Please sign in to comment.