Module: ReportHelper

Defined in:
lib/active_warehouse/view/report_helper.rb

Overview

Helper module for rendering reports.

Instance Method Summary collapse

Instance Method Details

#render_report(report, html_options = {}) ⇒ Object

Render the report.

  • report: The report instance

  • html_options: HTML options



7
8
9
10
11
12
13
14
15
16
# File 'lib/active_warehouse/view/report_helper.rb', line 7

def render_report(report, html_options={})
  case report
  when ActiveWarehouse::Report::TableReport
    render_table_report(report, html_options)
  when ActiveWarehouse::Report::ChartReport
    render_chart_report(report, html_options)
  else
    raise "Unsupported report type: #{report.class}"
  end
end

#sortable_column_header(column_name, order_by, link_parameters = {}, attributes = {}) ⇒ Object

Create a sortable column header.

Parameters are

column_name: The column display name
order_by: The column name from the table used for sorting
link_parameters: Parameters passed to the hypertext link
attributes: Parameters passed to the <th> element

Example:

sortable_column_header('SSN','ssn')
sortable_column_header('Name','name',{:onclick => 'doSomething();'}, {:title => 'Some Title'})


304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# File 'lib/active_warehouse/view/report_helper.rb', line 304

def sortable_column_header(column_name, order_by, link_parameters={}, attributes={}) # TODO get this thing back into the mix
  order = 'desc'
  if params[:order_by].to_s == order_by.to_s
    sorted = 'sorted'
    if params[:order] == 'desc' || params[:order].nil?
      order_css_class = 'order_down'
      order = 'asc'
    elsif params[:order] == 'asc'
      order_css_class = 'order_up'
      order = 'desc'
    end
  else
    sorted = ''
  end
  
  attributes.merge!({:class => "sortable #{sorted} #{order_css_class}"})
  x.th(attributes) do |th|
    th << link_to(column_name, params.merge({:order_by => order_by, :order => order}), link_parameters)
  end
end