class ReportsKit::ReportBuilder
Constants
- ACTION_KEYS_METHODS
Attributes
actions[RW]
additional_params[RW]
block[RW]
context_params[RW]
form_builder[RW]
js_report_class[RW]
properties[RW]
report_params[RW]
view_context[RW]
Public Class Methods
new(report_params:, context_params: {}, actions: %w(export_csv export_xls), js_report_class: 'Report', properties:, view_context:, block: nil)
click to toggle source
# 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 context_record = ReportsKit.configuration.context_record(view_context) self.form_builder = ReportsKit::FormBuilder.new(properties, additional_params: additional_params, context_record: context_record) end
Public Instance Methods
form(&block)
click to toggle source
# File lib/reports_kit/report_builder.rb, line 36 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()
click to toggle source
# File lib/reports_kit/report_builder.rb, line 25 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
Private Instance Methods
action_elements()
click to toggle source
# File lib/reports_kit/report_builder.rb, line 77 def action_elements @action_elements ||= begin return if actions.blank? actions.map do |action| element_method = ACTION_KEYS_METHODS[action] raise ArgumentError.new("Invalid action: #{action}") unless element_method send(element_method) end.compact end end
action_elements_container()
click to toggle source
# File lib/reports_kit/report_builder.rb, line 70 def action_elements_container return if action_elements.blank? view_context.content_tag(:div, nil, class: 'reports_kit_actions') do action_elements.map { |element| view_context.concat(element) } end end
reports_data_path()
click to toggle source
# File lib/reports_kit/report_builder.rb, line 66 def reports_data_path @reports_data_path ||= view_context.reports_kit.reports_kit_reports_path({ format: 'json' }.merge(additional_params)) end