Module: Agilibox::SortingHelper
- Included in:
- AllHelpers, Sorter
- Defined in:
- app/helpers/agilibox/sorting_helper.rb
Instance Method Summary collapse
Instance Method Details
#sortable_column(name, column) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/helpers/agilibox/sorting_helper.rb', line 2 def sortable_column(name, column) unless column.is_a?(Symbol) raise ArgumentError, "invalid column, please use symbol" end current_column, current_direction = sortable_column_order if current_column == column if current_direction == :asc name = "#{name} ↓" new_sort_param = "-#{column}" end if current_direction == :desc name = "#{name} ↑" new_sort_param = column end klass = "sort #{current_direction}" else new_sort_param = column klass = "sort" end url_params = (params.try(:permit!) || params).to_h.symbolize_keys.merge(sort: new_sort_param) link_to(name, url_params, class: klass) end |
#sortable_column_order(sort_param = params[:sort]) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/helpers/agilibox/sorting_helper.rb', line 31 def sortable_column_order(sort_param = params[:sort]) sort_param = sort_param.to_s if sort_param.present? if sort_param.start_with?("-") column = sort_param[1..-1].to_sym direction = :desc else column = sort_param.to_sym direction = :asc end end if block_given? yield(column, direction) else [column, direction] end end |