Module: GoogleDataSource::Reporting::Helper
- Defined in:
- lib/reporting/helper.rb
Instance Method Summary collapse
-
#form_render_callback(reporting, options = {}) ⇒ Object
Returns callback JS code that sends the rendered form partial So validation errors can be displayed.
-
#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 theReporting
object to be displayed Have a look atgoogle_visualization
helper forurl
andoptions
parameter. -
#google_reporting_combo_table(reporting, url = nil, options = {}) ⇒ Object
Shows a combo table reporting.
-
#google_reporting_table(reporting, url = nil, options = {}) ⇒ Object
Shows a table reporting.
-
#google_reporting_timeline(reporting, url = nil, options = {}) ⇒ Object
Shows a timeline reporting.
-
#reporting_form_hooks(reporting) {|hooks| ... } ⇒ Object
Registers form subit hooks This way the standard form serialization can be overwritten.
-
#reporting_form_id(reporting) ⇒ Object
Returns the standard DOM id for reporting forms.
-
#reporting_form_partial(reporting) ⇒ Object
Returns the standard partial for reporting forms.
-
#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?.
-
#reporting_options_for_select(reporting, select_options, options = {}) ⇒ Object
Adds labels to the select options when columns are passed in.
-
#reporting_select_select(reporting, select_options, options = {}) ⇒ Object
Shows a Multiselect box for the columns to ‘select’.
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, = {}) out = "$('##{reporting_form_id(reporting)}').html(#{render([: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, = {}) # no form return google_visualization(type, url, ) unless .delete(:form) # form # default options = { :form => reporting_form_id(reporting), :autosubmit => true, :form_position => :bottom }.update() visualization_html = google_visualization(type, url, ) form_html = content_tag("form", :id => reporting_form_id(reporting), :class => 'formtastic') do render [:form_partial] || reporting_form_partial(reporting) end [: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, = {}) google_reporting('ComboTable', reporting, url, ) 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, = {}) google_reporting('Table', reporting, url, ) 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, = {}) google_reporting('TimeLine', reporting, url, ) end |
#reporting_form_hooks(reporting) {|hooks| ... } ⇒ Object
Registers form subit hooks This way the standard form serialization can be overwritten
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, , i = 1, = {}) = (reporting, , ) tag_name = "#{reporting.class.name.underscore}[groupby(#{i}i)]" current_option = (reporting.group_by.size < i) ? nil : reporting.group_by[i-1] = (, current_option) select_tag(tag_name, , ) 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, , = {}) if (.is_a?(Array)) = .collect { |column| [reporting.column_label(column), column] } .unshift('') if .delete(:include_blank) end 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, , = {}) = (reporting, , ) tag_name = "#{reporting.class.name.underscore}[select]" = (, reporting.select) select_tag(tag_name, , :multiple => true) end |