Skip to content
Browse files

Improved HTML table helper method.

  • Loading branch information...
1 parent ebb2d89 commit 8cd504a380ac370bd4bad715393d783eed4d1914 @wvanbergen committed
Showing with 26 additions and 15 deletions.
  1. +26 −15 lib/active_olap/helpers/table_helper.rb
View
41 lib/active_olap/helpers/table_helper.rb
@@ -10,37 +10,48 @@ def active_olap_matrix(cube, options = {}, html_options = {})
raise "Only suitable for 2D cubes" unless cube.depth == 2
raise "Only 1 aggregate supported" if cube.aggregates.length > 1
+ options[:strings] ||= {}
- html = content_tag(:table, html_options.merge(:class => "active-olap table 2d")) do
+ content_tag(:table, html_options.merge(:class => "active-olap table 2d")) do
content_tag(:thead) do
content_tag(:tr, :class => 'category') do
- content_tag(:th, ' ') + "\n\t" +
+ header_html = content_tag(:th, ' ') + "\n\t" +
cube.dimensions[1].categories.map do |category|
content_tag(:th, show_active_olap_category(category, :for => :matrix), :class => 'column', :id => "category-#{category.label}")
end.join
+
+ if options[:totals]
+ header_html << content_tag(:th, '&nbsp;', :class => 'column total', :id => "category-total")
+ end
+ header_html
end
end << "\n" <<
content_tag(:tbody) do
- cube.map do |category, sub_cube|
- content_tag(:tr) do
- "\t\n" + content_tag(:th, show_active_olap_category(category, :class => 'category row', :id => "category-#{category.label}", :for => :matrix)) +
+ body_html = cube.map do |category, sub_cube|
+ content_tag(:tr, :class => 'row') do
+ row_html = "\t\n" + content_tag(:th, show_active_olap_category(category, :class => 'category row', :id => "category-#{category.label}", :for => :matrix)) +
sub_cube.map do |category, value|
content_tag(:td, show_active_olap_value(category, cube.aggregates.first, value, :for => :matrix), :class => 'value')
end.join
+ if options[:totals]
+ row_html << content_tag(:td, show_active_olap_value(category, sub_cube.aggregates.first, sub_cube.sum, :for => :matrix), :class => 'value')
+ end
+ row_html
end
end
+
+ if options[:totals]
+ body_html << content_tag(:tr, :class => 'totals') do
+ "\t\n" + content_tag(:th, '&nbsp;', :class => 'row total') +
+ cube.transpose.map do |category, sub_cube|
+ content_tag(:td, show_active_olap_value(category, sub_cube.aggregates.first, sub_cube.sum, :for => :matrix), :class => 'value')
+ end.join +
+ content_tag(:td, cube.sum, :class => 'value')
+ end
+ end
+ body_html
end
end
-
- if options[:totals]
- html << content_tag(:tr, :class => 'totals') do
- "\t\n" + content_tag(:th, '&nbsp;') +
- cube.map do |sub_cube, value|
- content_tag(:td, show_active_olap_value(sub_cube.category, cube.aggregates.first, cube.sum, :for => :matrix), :class => 'value')
- end.join
- end
-
- end
end
def active_olap_table(cube, options = {}, html_options = {})

0 comments on commit 8cd504a

Please sign in to comment.
Something went wrong with that request. Please try again.