Class: CrudComponents::Presenters::Filter
- Defined in:
- lib/crud_components/presenters/filter.rb
Overview
The single ‘filter` local of the standalone filter form partial. Renders the fieldset’s filterable fields (including its ‘filters:` extension); never auto-submits — users compose several filters here.
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#structure ⇒ Object
readonly
Returns the value of attribute structure.
Attributes inherited from Base
Instance Method Summary collapse
- #fields ⇒ Object
- #form_path ⇒ Object
-
#initialize(view:, model:, fieldset: nil, query: nil, param_prefix: nil) ⇒ Filter
constructor
A new instance of Filter.
- #param_name(key) ⇒ Object
-
#preserved_params ⇒ Object
Keep sort and foreign params; our own controls resubmit themselves.
- #reset_path ⇒ Object
- #searchable? ⇒ Boolean
- #value(key) ⇒ Object
Methods inherited from Base
#ability, #config, #css, #permission_context, #render_cell, #render_filter_control
Constructor Details
#initialize(view:, model:, fieldset: nil, query: nil, param_prefix: nil) ⇒ Filter
Returns a new instance of Filter.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/crud_components/presenters/filter.rb', line 9 def initialize(view:, model:, fieldset: nil, query: nil, param_prefix: nil) super(view: view) @model = model.is_a?(Class) ? model : model.klass @structure = Structure.for(@model) @query = if query.is_a?(Query) query else Query.new(@model, view.request.query_parameters, fieldset: @structure.fieldset(fieldset || :index), ability: ability, param_prefix: param_prefix) end end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
7 8 9 |
# File 'lib/crud_components/presenters/filter.rb', line 7 def model @model end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
7 8 9 |
# File 'lib/crud_components/presenters/filter.rb', line 7 def query @query end |
#structure ⇒ Object (readonly)
Returns the value of attribute structure.
7 8 9 |
# File 'lib/crud_components/presenters/filter.rb', line 7 def structure @structure end |
Instance Method Details
#fields ⇒ Object
22 |
# File 'lib/crud_components/presenters/filter.rb', line 22 def fields = query.filter_fields |
#form_path ⇒ Object
24 |
# File 'lib/crud_components/presenters/filter.rb', line 24 def form_path = view.request.path |
#param_name(key) ⇒ Object
27 |
# File 'lib/crud_components/presenters/filter.rb', line 27 def param_name(key) = query.param_name(key) |
#preserved_params ⇒ Object
Keep sort and foreign params; our own controls resubmit themselves.
31 32 33 34 35 |
# File 'lib/crud_components/presenters/filter.rb', line 31 def preserved_params own = fields.flat_map { |f| [param_name(f.name.to_s), param_name("#{f.name}_geq"), param_name("#{f.name}_leq")] } own += [param_name('q'), param_name('page'), param_name('per')] view.request.query_parameters.reject { |key, _| own.include?(key) } end |
#reset_path ⇒ Object
25 |
# File 'lib/crud_components/presenters/filter.rb', line 25 def reset_path = view.request.path |
#searchable? ⇒ Boolean
23 |
# File 'lib/crud_components/presenters/filter.rb', line 23 def searchable? = query.searchable? |
#value(key) ⇒ Object
28 |
# File 'lib/crud_components/presenters/filter.rb', line 28 def value(key) = query.value(key) |