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
|
# File 'app/helpers/easy_admin/resources_helper.rb', line 3
def sort_link(field, label = nil)
label ||= field[:label]
field_name = field[:name]
is_active = @current_sort_field == field_name.to_s
current_direction = @current_sort_direction if is_active
next_direction = is_active && current_direction == 'asc' ? 'desc' : 'asc'
params_hash = params.permit(:search).to_h
params_hash[:sort] = field_name
params_hash[:direction] = next_direction
css_class = "ea-sort-pill"
css_class += " ea-sort-pill--active" if is_active
link_to easy_admin.resources_path(@resource_class.route_key, params_hash),
class: css_class do
content = label.dup
if is_active
content += " #{current_direction == 'asc' ? '↑' : '↓'}"
end
content.html_safe
end
end
|