Module: Karafka::Web::Ui::Helpers::SortingHelper
- Included in:
- Base
- Defined in:
- lib/karafka/web/ui/helpers/sorting_helper.rb
Overview
Helpers for rendering sortable column links in data tables
Instance Method Summary collapse
-
#sort_link(name, attribute = nil, rev: false) ⇒ String
Html link for sorting with arrow when attribute sort enabled.
Instance Method Details
#sort_link(name, attribute = nil, rev: false) ⇒ String
Returns html link for sorting with arrow when attribute sort enabled.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/karafka/web/ui/helpers/sorting_helper.rb', line 40 def sort_link(name, attribute = nil, rev: false) unless attribute attribute = name if SORT_NAMES[attribute] name = SORT_NAMES[attribute] else name = attribute.to_s.tr("_", " ").tr("?", "") # Always capitalize the name name = name.split.map(&:capitalize).join(" ") end end arrow_both = "⇕" arrow_down = "▾" arrow_up = "▴" desc = "#{attribute} desc" asc = "#{attribute} asc" path = current_path(sort: desc) full_name = "#{name} #{arrow_both}" if params.current_sort == desc path = current_path(sort: asc) full_name = "#{name} #{rev ? arrow_up : arrow_down}" end if params.current_sort == asc path = current_path(sort: desc) full_name = "#{name} #{rev ? arrow_down : arrow_up}" end "<a class=\"sort\" href=\"#{path}\">#{full_name}</a>" end |