Class: ReportsKit::ReportBuilder
- Inherits:
-
Object
- Object
- ReportsKit::ReportBuilder
- Includes:
- ActionView::Helpers
- Defined in:
- lib/reports_kit/report_builder.rb
Constant Summary collapse
- ACTION_KEYS_METHODS =
{ 'export_csv' => :export_csv_button, 'export_xls' => :export_xls_button }
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#additional_params ⇒ Object
Returns the value of attribute additional_params.
-
#block ⇒ Object
Returns the value of attribute block.
-
#context_params ⇒ Object
Returns the value of attribute context_params.
-
#form_builder ⇒ Object
Returns the value of attribute form_builder.
-
#js_report_class ⇒ Object
Returns the value of attribute js_report_class.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#report_params ⇒ Object
Returns the value of attribute report_params.
-
#view_context ⇒ Object
Returns the value of attribute view_context.
Instance Method Summary collapse
- #export_button(text, format, options, &block) ⇒ Object
- #export_csv_button(text = 'Download CSV', options = {}, &block) ⇒ Object
- #export_xls_button(text = 'Download Excel', options = {}, &block) ⇒ Object
- #form(&block) ⇒ Object
-
#initialize(report_params:, context_params: {}, actions: %w(export_csv export_xls),, js_report_class: 'Report', properties:, view_context:, block: nil) ⇒ ReportBuilder
constructor
A new instance of ReportBuilder.
- #render ⇒ Object
Constructor Details
#initialize(report_params:, context_params: {}, actions: %w(export_csv export_xls),, js_report_class: 'Report', properties:, view_context:, block: nil) ⇒ ReportBuilder
Returns a new instance of ReportBuilder.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/reports_kit/report_builder.rb', line 12 def initialize(report_params:, context_params: {}, actions: %w(export_csv export_xls), js_report_class: 'Report', properties:, view_context:, block: nil) self.report_params = report_params.is_a?(String) ? { key: report_params } : report_params self.context_params = context_params self.additional_params = { context_params: context_params, report_params: self.report_params } self.actions = actions self.js_report_class = js_report_class self.view_context = view_context self.block = block self.properties = properties#view_context.instance_eval(&ReportsKit.configuration.properties_method).deep_symbolize_keys self.form_builder = ReportsKit::FormBuilder.new(properties, additional_params: additional_params) end |
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
5 6 7 |
# File 'lib/reports_kit/report_builder.rb', line 5 def actions @actions end |
#additional_params ⇒ Object
Returns the value of attribute additional_params.
5 6 7 |
# File 'lib/reports_kit/report_builder.rb', line 5 def additional_params @additional_params end |
#block ⇒ Object
Returns the value of attribute block.
5 6 7 |
# File 'lib/reports_kit/report_builder.rb', line 5 def block @block end |
#context_params ⇒ Object
Returns the value of attribute context_params.
5 6 7 |
# File 'lib/reports_kit/report_builder.rb', line 5 def context_params @context_params end |
#form_builder ⇒ Object
Returns the value of attribute form_builder.
5 6 7 |
# File 'lib/reports_kit/report_builder.rb', line 5 def form_builder @form_builder end |
#js_report_class ⇒ Object
Returns the value of attribute js_report_class.
5 6 7 |
# File 'lib/reports_kit/report_builder.rb', line 5 def js_report_class @js_report_class end |
#properties ⇒ Object
Returns the value of attribute properties.
5 6 7 |
# File 'lib/reports_kit/report_builder.rb', line 5 def properties @properties end |
#report_params ⇒ Object
Returns the value of attribute report_params.
5 6 7 |
# File 'lib/reports_kit/report_builder.rb', line 5 def report_params @report_params end |
#view_context ⇒ Object
Returns the value of attribute view_context.
5 6 7 |
# File 'lib/reports_kit/report_builder.rb', line 5 def view_context @view_context end |
Instance Method Details
#export_button(text, format, options, &block) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/reports_kit/report_builder.rb', line 50 def (text, format, , &block) data = { role: 'reports_kit_export_button', path: view_context.reports_kit.reports_kit_reports_path({ format: format }.merge(additional_params)) } = { class: 'btn btn-primary', data: data }.merge() if block_given? view_context.link_to('#', , &block) else view_context.link_to(text, '#', ) end end |
#export_csv_button(text = 'Download CSV', options = {}, &block) ⇒ Object
42 43 44 |
# File 'lib/reports_kit/report_builder.rb', line 42 def (text='Download CSV', = {}, &block) (text, 'csv', , &block) end |
#export_xls_button(text = 'Download Excel', options = {}, &block) ⇒ Object
46 47 48 |
# File 'lib/reports_kit/report_builder.rb', line 46 def (text='Download Excel', = {}, &block) (text, 'xls', , &block) end |
#form(&block) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/reports_kit/report_builder.rb', line 35 def form(&block) raise ArgumentError.new('No block given for ReportBuilder#form') unless block view_context.form_tag(reports_data_path, method: 'get', class: 'reports_kit_report_form') do view_context.capture(form_builder, &block) end end |
#render ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/reports_kit/report_builder.rb', line 24 def render data = { properties: properties.slice(:format), path: reports_data_path, report_class: js_report_class } view_context.content_tag :div, nil, class: 'reports_kit_report form-inline', data: data do elements = [] elements << view_context.capture(self, &block) if block elements << view_context.content_tag(:div, nil, class: 'reports_kit_visualization') elements << action_elements_container elements.compact.join.html_safe end end |