Module: GoogleDataSource::Reporting::Helper

Defined in:
lib/reporting/helper.rb

Instance Method Summary collapse

Instance Method Details

#form_render_callback(reporting, options = {}) ⇒ Object

Returns callback JS code that sends the rendered form partial So validation errors can be displayed



48
49
50
51
52
# File 'lib/reporting/helper.rb', line 48

def form_render_callback(reporting, options = {})
  out = "$('##{reporting_form_id(reporting)}').html(#{render(options[:form_partial] || reporting_form_partial(reporting), :reporting => reporting).to_json});"
  out << '$(document).trigger("formRendered");'
  out
end

#google_reporting(type, reporting, url = nil, options = {}) ⇒ Object

Shows a reporting consisting of a visualization and a form for configuration type can be either

  • ‘Table’

  • ‘TimeLine’

reporting is the Reporting object to be displayed Have a look at google_visualization helper for url and options parameter



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/reporting/helper.rb', line 10

def google_reporting(type, reporting, url = nil, options = {})
  # no form
  return google_visualization(type, url, options) unless options.delete(:form)

  # form
  # default options
  options = {
    :form          => reporting_form_id(reporting),
    :autosubmit    => true,
    :form_position => :bottom
  }.update(options)
  
  visualization_html = google_visualization(type, url, options)

  form_html = ("form", :id => reporting_form_id(reporting), :class => 'formtastic') do
    render options[:form_partial] || reporting_form_partial(reporting)
  end
  
  options[:form_position] == :bottom ? visualization_html << form_html : form_html << visualization_html
end

#google_reporting_combo_table(reporting, url = nil, options = {}) ⇒ Object

Shows a combo table reporting



42
43
44
# File 'lib/reporting/helper.rb', line 42

def google_reporting_combo_table(reporting, url = nil, options = {})
  google_reporting('ComboTable', reporting, url, options)
end

#google_reporting_table(reporting, url = nil, options = {}) ⇒ Object

Shows a table reporting



37
38
39
# File 'lib/reporting/helper.rb', line 37

def google_reporting_table(reporting, url = nil, options = {})
  google_reporting('Table', reporting, url, options)
end

#google_reporting_timeline(reporting, url = nil, options = {}) ⇒ Object

Shows a timeline reporting



32
33
34
# File 'lib/reporting/helper.rb', line 32

def google_reporting_timeline(reporting, url = nil, options = {})
  google_reporting('TimeLine', reporting, url, options)
end

#reporting_form_hooks(reporting) {|hooks| ... } ⇒ Object

Registers form subit hooks This way the standard form serialization can be overwritten

Yields:

  • (hooks)


86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/reporting/helper.rb', line 86

def reporting_form_hooks(reporting)
  hooks = OpenStruct.new
  yield(hooks)

  json = []
  %w(select).each do |hook|
    next if hooks.send(hook).nil?
    json << "#{hook}: function(){#{hooks.send hook}}"
  end
  js = "DataSource.FilterForm.setHooks(#{reporting_form_id(reporting).to_json}, {#{json.join(', ')}});"
  javascript_tag(js)
end

#reporting_form_id(reporting) ⇒ Object

Returns the standard DOM id for reporting forms



100
101
102
# File 'lib/reporting/helper.rb', line 100

def reporting_form_id(reporting)
  "#{reporting.id}_form"
end

#reporting_form_partial(reporting) ⇒ Object

Returns the standard partial for reporting forms



105
106
107
# File 'lib/reporting/helper.rb', line 105

def reporting_form_partial(reporting)
  "#{reporting.id}_form.html"
end

#reporting_group_by_select(reporting, select_options, i = 1, options = {}) ⇒ Object

Shows a select tag for grouping selection on a given reporting TODO more docu TODO really take namespace from classname?



57
58
59
60
61
62
63
64
# File 'lib/reporting/helper.rb', line 57

def reporting_group_by_select(reporting, select_options, i = 1, options = {})
 select_options = reporting_options_for_select(reporting, select_options, options)

 tag_name = "#{reporting.class.name.underscore}[groupby(#{i}i)]"
 current_option = (reporting.group_by.size < i) ? nil : reporting.group_by[i-1]
 option_tags = options_for_select(select_options, current_option)
 select_tag(tag_name, option_tags, options)
end

#reporting_options_for_select(reporting, select_options, options = {}) ⇒ Object

Adds labels to the select options when columns are passed in



76
77
78
79
80
81
82
# File 'lib/reporting/helper.rb', line 76

def reporting_options_for_select(reporting, select_options, options = {})
 if (select_options.is_a?(Array))
   select_options = select_options.collect { |column| [reporting.column_label(column), column] }
   select_options.unshift('') if options.delete(:include_blank)
 end
 select_options
end

#reporting_select_select(reporting, select_options, options = {}) ⇒ Object

Shows a Multiselect box for the columns to ‘select’



67
68
69
70
71
72
73
# File 'lib/reporting/helper.rb', line 67

def reporting_select_select(reporting, select_options, options = {})
  select_options = reporting_options_for_select(reporting, select_options, options)

  tag_name = "#{reporting.class.name.underscore}[select]"
  option_tags = options_for_select(select_options, reporting.select)
  select_tag(tag_name, option_tags, :multiple => true)
end