Module: Ordy::Helpers::ActionView::OrderableLinkHelper
- Defined in:
- lib/ordy/helpers/action_view/orderable_link_helper.rb
Constant Summary collapse
- ORDER_ASC =
'asc'
- ORDER_DESC =
'desc'
Instance Method Summary collapse
-
#icon(direction = nil) ⇒ String
NOTE: In case you don’t use Awesome Font override this method.
-
#order_link(title, order_by, direction = ORDER_ASC) ⇒ Object
order_link(Alert, :event, :asc).
Instance Method Details
#icon(direction = nil) ⇒ String
NOTE: In case you don’t use Awesome Font override this method
icon(‘asc’)
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ordy/helpers/action_view/orderable_link_helper.rb', line 42 def icon(direction = nil) icon, html_class = if direction.nil? [config.icon.sort, class: config.icon.inactive] else [direction == ORDER_DESC ? config.icon.up : config.icon.down, nil] end icon_class = "fa-#{icon}" "<i class=\"fa #{icon_class} #{html_class}\"></i>" end |
#order_link(title, order_by, direction = ORDER_ASC) ⇒ Object
order_link(Alert, :event, :asc)
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ordy/helpers/action_view/orderable_link_helper.rb', line 15 def order_link(title, order_by, direction = ORDER_ASC) current_orderable, current_direction = request_params.values_at(:order_by, :direction) direction = if current_direction.present? current_direction == ORDER_ASC ? ORDER_DESC : ORDER_ASC else direction end icon_html = if current_orderable.present? && order_by.to_s == current_orderable icon(direction) else icon(nil) end title = "#{title} #{icon_html}".html_safe url_params = request_params.merge(order_by: "#{order_by}-#{direction}") link_to(title, url_params) end |