Module: SourceMonitor::TableSortHelper
- Included in:
- ApplicationHelper
- Defined in:
- app/helpers/source_monitor/table_sort_helper.rb
Instance Method Summary collapse
- #table_sort_aria(search_object, attribute) ⇒ Object
- #table_sort_arrow(search_object, attribute, default: nil) ⇒ Object
- #table_sort_direction(search_object, attribute) ⇒ Object
- #table_sort_link(search_object, attribute, label, frame:, default_order:, secondary: [], html_options: {}) ⇒ Object
Instance Method Details
#table_sort_aria(search_object, attribute) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/helpers/source_monitor/table_sort_helper.rb', line 25 def table_sort_aria(search_object, attribute) direction = table_sort_direction(search_object, attribute) case direction when "asc" "ascending" when "desc" "descending" else "none" end end |
#table_sort_arrow(search_object, attribute, default: nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/helpers/source_monitor/table_sort_helper.rb', line 12 def table_sort_arrow(search_object, attribute, default: nil) direction = table_sort_direction(search_object, attribute) || default&.to_s case direction when "asc" "▲" when "desc" "▼" else "↕" end end |
#table_sort_direction(search_object, attribute) ⇒ Object
5 6 7 8 9 10 |
# File 'app/helpers/source_monitor/table_sort_helper.rb', line 5 def table_sort_direction(search_object, attribute) return unless search_object.respond_to?(:sorts) sort = search_object.sorts.detect { |s| s && s.name == attribute.to_s } sort&.dir end |
#table_sort_link(search_object, attribute, label, frame:, default_order:, secondary: [], html_options: {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/helpers/source_monitor/table_sort_helper.rb', line 38 def table_sort_link(search_object, attribute, label, frame:, default_order:, secondary: [], html_options: {}) sort_targets = [ attribute, *Array(secondary) ] = { default_order: default_order, hide_indicator: true }.merge() [:data] = ([:data] || {}).merge(turbo_frame: frame) [:data][:turbo_action] ||= "advance" sort_link(search_object, attribute, sort_targets, ) do tag.span(label, class: "inline-flex items-center gap-1") end end |