Module: Madmin::SortHelper
- Included in:
- ResourceController
- Defined in:
- app/helpers/madmin/sort_helper.rb
Instance Method Summary collapse
- #asc_icon ⇒ Object
- #default_sort_column ⇒ Object
- #default_sort_direction ⇒ Object
- #desc_icon ⇒ Object
- #sort_column ⇒ Object
- #sort_direction ⇒ Object
- #sortable(column, title, options = {}) ⇒ Object
Instance Method Details
#asc_icon ⇒ Object
32 33 34 35 36 37 38 |
# File 'app/helpers/madmin/sort_helper.rb', line 32 def asc_icon <<~SVG.html_safe <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" height="1rem" width="1rem"> <path fill-rule="evenodd" d="M11.78 9.78a.75.75 0 0 1-1.06 0L8 7.06 5.28 9.78a.75.75 0 0 1-1.06-1.06l3.25-3.25a.75.75 0 0 1 1.06 0l3.25 3.25a.75.75 0 0 1 0 1.06Z" clip-rule="evenodd" /> </svg> SVG end |
#default_sort_column ⇒ Object
24 25 26 |
# File 'app/helpers/madmin/sort_helper.rb', line 24 def default_sort_column resource.try(:default_sort_column) || (["created_at", "id", "uuid"] & resource.model.column_names).first end |
#default_sort_direction ⇒ Object
28 29 30 |
# File 'app/helpers/madmin/sort_helper.rb', line 28 def default_sort_direction resource.try(:default_sort_direction) || "desc" end |
#desc_icon ⇒ Object
40 41 42 43 44 45 46 |
# File 'app/helpers/madmin/sort_helper.rb', line 40 def desc_icon <<~SVG.html_safe <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" height="1rem" width="1rem"> <path fill-rule="evenodd" d="M4.22 6.22a.75.75 0 0 1 1.06 0L8 8.94l2.72-2.72a.75.75 0 1 1 1.06 1.06l-3.25 3.25a.75.75 0 0 1-1.06 0L4.22 7.28a.75.75 0 0 1 0-1.06Z" clip-rule="evenodd" /> </svg> SVG end |
#sort_column ⇒ Object
16 17 18 |
# File 'app/helpers/madmin/sort_helper.rb', line 16 def sort_column resource.sortable_columns.include?(params[:sort]) ? params[:sort] : default_sort_column end |
#sort_direction ⇒ Object
20 21 22 |
# File 'app/helpers/madmin/sort_helper.rb', line 20 def sort_direction ["asc", "desc"].include?(params[:direction]) ? params[:direction] : default_sort_direction end |
#sortable(column, title, options = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'app/helpers/madmin/sort_helper.rb', line 3 def sortable(column, title, = {}) matching_column = (column.to_s == sort_column) direction = (sort_direction == "asc") ? "desc" : "asc" link_to resource.index_path(sort: column, direction: direction), do concat title if matching_column concat " " concat tag.span((sort_direction == "asc") ? asc_icon : desc_icon) end end end |