Class: ReportsKit::FormBuilder
- Inherits:
-
Object
- Object
- ReportsKit::FormBuilder
- Includes:
- ActionView::Helpers
- Defined in:
- lib/reports_kit/form_builder.rb
Constant Summary collapse
- DEFAULT_DATE_RANGE_VALUE =
['-2M', 'now']
Instance Attribute Summary collapse
-
#additional_params ⇒ Object
Returns the value of attribute additional_params.
-
#context_record ⇒ Object
Returns the value of attribute context_record.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#properties_to_filter ⇒ Object
Returns the value of attribute properties_to_filter.
Instance Method Summary collapse
- #check_box(filter_key, options = {}) ⇒ Object
- #date_range(filter_key, options = {}) ⇒ Object
-
#initialize(properties, additional_params: nil, context_record: nil) ⇒ FormBuilder
constructor
A new instance of FormBuilder.
- #multi_autocomplete(filter_key, options = {}) ⇒ Object
- #string_filter(filter_key, options = {}) ⇒ Object
Constructor Details
#initialize(properties, additional_params: nil, context_record: nil) ⇒ FormBuilder
Returns a new instance of FormBuilder.
9 10 11 12 13 14 |
# File 'lib/reports_kit/form_builder.rb', line 9 def initialize(properties, additional_params: nil, context_record: nil) self.properties = properties.deep_symbolize_keys self.additional_params = additional_params self.context_record = context_record self.properties_to_filter = Reports::PropertiesToFilter.new(properties, context_record: context_record) end |
Instance Attribute Details
#additional_params ⇒ Object
Returns the value of attribute additional_params.
7 8 9 |
# File 'lib/reports_kit/form_builder.rb', line 7 def additional_params @additional_params end |
#context_record ⇒ Object
Returns the value of attribute context_record.
7 8 9 |
# File 'lib/reports_kit/form_builder.rb', line 7 def context_record @context_record end |
#properties ⇒ Object
Returns the value of attribute properties.
7 8 9 |
# File 'lib/reports_kit/form_builder.rb', line 7 def properties @properties end |
#properties_to_filter ⇒ Object
Returns the value of attribute properties_to_filter.
7 8 9 |
# File 'lib/reports_kit/form_builder.rb', line 7 def properties_to_filter @properties_to_filter end |
Instance Method Details
#check_box(filter_key, options = {}) ⇒ Object
16 17 18 19 20 |
# File 'lib/reports_kit/form_builder.rb', line 16 def check_box(filter_key, = {}) filter = properties_to_filter.perform(filter_key) checked = filter.normalized_properties[:criteria][:value] == 'true' check_box_tag(filter_key, '1', checked, ) end |
#date_range(filter_key, options = {}) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/reports_kit/form_builder.rb', line 22 def date_range(filter_key, = {}) filter = properties_to_filter.perform(filter_key) defaults = { class: 'form-control input-sm date_range_picker' } = defaults.deep_merge() value = filter.normalized_properties[:criteria][:value].presence value ||= default_date_range_value text_field_tag(filter_key, value, ) end |
#multi_autocomplete(filter_key, options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/reports_kit/form_builder.rb', line 31 def multi_autocomplete(filter_key, = {}) filter = properties_to_filter.perform(filter_key) reports_kit_path = Rails.application.routes.url_helpers.reports_kit_path path = "#{reports_kit_path}reports_kit/filters/#{filter_key}/autocomplete?" path += additional_params.to_query if additional_params.present? defaults = { class: 'form-control input-sm select2', multiple: 'multiple', data: { placeholder: [:placeholder], path: path } } = defaults.deep_merge() select_tag(filter_key, nil, ) end |
#string_filter(filter_key, options = {}) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/reports_kit/form_builder.rb', line 49 def string_filter(filter_key, = {}) filter = properties_to_filter.perform(filter_key) defaults = { class: 'form-control input-sm' } = defaults.deep_merge() text_field_tag(filter_key, filter.normalized_properties[:criteria][:value], ) end |