Class: ReportsKit::ReportBuilder

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers
Defined in:
lib/reports_kit/report_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(properties) ⇒ ReportBuilder

Returns a new instance of ReportBuilder.



7
8
9
# File 'lib/reports_kit/report_builder.rb', line 7

def initialize(properties)
  self.properties = normalize_properties(properties)
end

Instance Attribute Details

#propertiesObject

Returns the value of attribute properties.



5
6
7
# File 'lib/reports_kit/report_builder.rb', line 5

def properties
  @properties
end

Instance Method Details

#check_box(filter_key, options = {}) ⇒ Object



11
12
13
14
15
# File 'lib/reports_kit/report_builder.rb', line 11

def check_box(filter_key, options={})
  filter = validate_filter!(filter_key)
  checked = filter.properties[:criteria][:operator] == 'true'
  check_box_tag(filter_key, '1', checked, options)
end

#date_range(filter_key, options = {}) ⇒ Object



17
18
19
20
21
22
# File 'lib/reports_kit/report_builder.rb', line 17

def date_range(filter_key, options={})
  filter = validate_filter!(filter_key)
  defaults = { class: 'form-control input-sm date_range_picker' }
  options = defaults.deep_merge(options)
  text_field_tag(filter_key, filter.properties[:criteria][:value], options)
end

#multi_autocomplete(filter_key, options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/reports_kit/report_builder.rb', line 24

def multi_autocomplete(filter_key, options={})
  validate_filter!(filter_key)
  reports_kit_path = Rails.application.routes.url_helpers.reports_kit_path
  path = "#{reports_kit_path}reports_kit/resources/measures/#{measure.key}/filters/#{filter_key}/autocomplete"
  scope = options.delete(:scope)
  params = {}
  params[:scope] = scope if scope.present?

  defaults = {
    class: 'form-control input-sm select2',
    multiple: 'multiple',
    data: {
      placeholder: options[:placeholder],
      path: path,
      params: params
    }
  }
  options = defaults.deep_merge(options)
  select_tag(filter_key, nil, options)
end

#string_filter(filter_key, options = {}) ⇒ Object



45
46
47
48
49
50
# File 'lib/reports_kit/report_builder.rb', line 45

def string_filter(filter_key, options={})
  filter = validate_filter!(filter_key)
  defaults = { class: 'form-control input-sm' }
  options = defaults.deep_merge(options)
  text_field_tag(filter_key, filter.properties[:criteria][:value], options)
end