Class: Filters::Configuration
- Inherits:
-
Object
- Object
- Filters::Configuration
- 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
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#resource_class ⇒ Object
readonly
Returns the value of attribute resource_class.
Instance Method Summary collapse
- #datepicker? ⇒ Boolean
-
#initialize(resource_class, method, options = {}) ⇒ Configuration
constructor
By default, a filter type will be selected based upon the attribute type.
- #input_options(view_ctx = nil) ⇒ Object
- #label ⇒ Object
- #render(f) ⇒ Object
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, ={}) @resource_class = resource_class @method = method @options = end |
Instance Attribute Details
#method ⇒ Object (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_class ⇒ Object (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
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 (view_ctx = nil) = { collection: collection(view_ctx), input_html: , as: as, label: label } .delete(:collection) if [:collection].nil? .merge!(@options.fetch(:input_options, {})) end |
#label ⇒ Object
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 |