Class: Admin::BaseSearchForm
- Inherits:
-
Object
- Object
- Admin::BaseSearchForm
- Includes:
- ActiveModel::Model
- Defined in:
- lib/generators/infold/templates/install/app/forms/admin/base_search_form.rb
Instance Attribute Summary collapse
-
#sort_field ⇒ Object
Returns the value of attribute sort_field.
- #sort_kind ⇒ Object
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#sort_field ⇒ Object
Returns the value of attribute sort_field.
5 6 7 |
# File 'lib/generators/infold/templates/install/app/forms/admin/base_search_form.rb', line 5 def sort_field @sort_field end |
#sort_kind ⇒ Object
44 45 46 |
# File 'lib/generators/infold/templates/install/app/forms/admin/base_search_form.rb', line 44 def sort_kind @sort_kind.to_s.downcase == 'asc' ? 'asc' : 'desc' end |
Class Method Details
.conditions ⇒ Object
13 14 15 |
# File 'lib/generators/infold/templates/install/app/forms/admin/base_search_form.rb', line 13 def conditions @conditions || [] end |
.conditions=(value) ⇒ Object
9 10 11 |
# File 'lib/generators/infold/templates/install/app/forms/admin/base_search_form.rb', line 9 def conditions=(value) @conditions = value end |
.set_condition(*condition_names) ⇒ Object
18 19 20 21 22 |
# File 'lib/generators/infold/templates/install/app/forms/admin/base_search_form.rb', line 18 def self.set_condition(*condition_names) attr_accessor *condition_names self.conditions += condition_names end |
Instance Method Details
#apply_conditions(records, page, limit, csv) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/generators/infold/templates/install/app/forms/admin/base_search_form.rb', line 24 def apply_conditions(records, page, limit, csv) if csv records = records.limit(1000) else limit ||= 50 limit = 200 if limit > 200 records = records.page(page).per(limit) end records = self.class.conditions.select{ |c| send(c).present? }.inject(records) do |_records, cond| _records.send(cond, send(cond)) end records end |
#apply_sort(records, primary_key) ⇒ Object
38 39 40 41 42 |
# File 'lib/generators/infold/templates/install/app/forms/admin/base_search_form.rb', line 38 def apply_sort(records, primary_key) records = records.order(sort_field => sort_kind) if sort_field.present? records = records.order(primary_key.to_sym) unless sort_kind.to_s == primary_key.to_s records end |