Class: Filters::Configuration

Inherits:
Object
  • Object
show all
Defined in:
app/models/lotus_admin/filters/configuration.rb

Constant Summary collapse

NUMBER_PREDICATE_FILTER_OPTIONS =
[['Greater Than', 'gteq'], ['Equals', 'eq'], ['Less Than', 'lteq']].freeze
STRING_PREDICATE_FILTER_OPTIONS =
[['Contains', 'cont'], ['Equals', 'eq'], ['Starts With', 'start'], ['Ends With', 'end']].freeze
DATE_PREDICATE_FILTER_OPTIONS =
[['After', 'gteq'], ['Exactly', 'eq'], ['Before', 'lteq']].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_class, method, options = {}) ⇒ Configuration

By default, a filter type will be selected based upon the attribute type

For example, a date will get a datepicker, a datetime gets a datetime picker A string gets a text search, and a numerical field gets a number search

To provide a select dropdown, such as filtering on an association, simply provide a collection attribute (as a Proc to be evaluated in the view context)

Examples:

filter :id (numeric) filter :device_id (numeric) filter :device_id, collection: ->{ [[1, ‘device’]] } (select) filter :created_at (datetime) filter :created_at, as: :date (date) filter :name (string)



26
27
28
29
30
# File 'app/models/lotus_admin/filters/configuration.rb', line 26

def initialize(resource_class, method, options={})
  @resource_class = resource_class
  @method = method
  @options = options
end

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



3
4
5
# File 'app/models/lotus_admin/filters/configuration.rb', line 3

def method
  @method
end

#resource_classObject (readonly)

Returns the value of attribute resource_class.



3
4
5
# File 'app/models/lotus_admin/filters/configuration.rb', line 3

def resource_class
  @resource_class
end

Instance Method Details

#datepicker?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'app/models/lotus_admin/filters/configuration.rb', line 67

def datepicker?
  @options.fetch(:datepicker, false)
end

#input_options(view_ctx = nil) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/models/lotus_admin/filters/configuration.rb', line 53

def input_options(view_ctx = nil)
  input_options = {
    collection: collection(view_ctx),
    input_html: input_html_options,
    as: as,
    label: label
  }

  input_options.delete(:collection) if input_options[:collection].nil?
  input_options.merge!(@options.fetch(:input_options, {}))

  input_options
end

#labelObject



32
33
34
# File 'app/models/lotus_admin/filters/configuration.rb', line 32

def label
  @label ||= translate_label
end

#render(f) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/models/lotus_admin/filters/configuration.rb', line 36

def render(f)
  case as
  when :number
    render_number_input_group(f)
  when :select, :grouped_select
    render_collection(f)
  when :datetime
    render_date_or_time_input_group(f, true)
  when :date
    render_date_or_time_input_group(f, false)
  when :boolean
    render_boolean_input_group(f)
  when :string
    render_string_input_group(f)
  end
end