Module: Locomotive::Concerns::ContentType::OrderBy
- Included in:
- Locomotive::ContentType
- Defined in:
- app/models/locomotive/concerns/content_type/order_by.rb
Instance Method Summary collapse
- #order_by_attribute ⇒ Object
- #order_by_definition(reverse_order = false) ⇒ Object
- #order_manually? ⇒ Boolean
- #sortable_column ⇒ Object
Instance Method Details
#order_by_attribute ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'app/models/locomotive/concerns/content_type/order_by.rb', line 20 def order_by_attribute case self.order_by when '_position' self.sortable_column when 'created_at', 'updated_at' self.order_by else self.entries_custom_fields.find(self.order_by).name rescue 'created_at' end end |
#order_by_definition(reverse_order = false) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'app/models/locomotive/concerns/content_type/order_by.rb', line 10 def order_by_definition(reverse_order = false) direction = self.order_manually? ? 'asc' : self.order_direction || 'asc' if reverse_order direction = (direction == 'asc' ? 'desc' : 'asc') end [order_by_attribute, direction] end |
#order_manually? ⇒ Boolean
6 7 8 |
# File 'app/models/locomotive/concerns/content_type/order_by.rb', line 6 def order_manually? self.order_by == '_position' end |
#sortable_column ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'app/models/locomotive/concerns/content_type/order_by.rb', line 31 def sortable_column # only the belongs_to field has a special column for relative positionning # that's why we don't call groupable? if self.group_by_field.try(:type) == 'belongs_to' && self.order_manually? "position_in_#{self.group_by_field.name}" else '_position' end end |