Module: EasyAdmin::ResourcesHelper

Defined in:
app/helpers/easy_admin/resources_helper.rb

Instance Method Summary collapse

Instance Method Details

#sort_arrow_svgObject



30
31
32
33
34
35
36
37
# File 'app/helpers/easy_admin/resources_helper.rb', line 30

def sort_arrow_svg
  <<~SVG.html_safe
    <svg width="8" height="12" viewBox="0 0 8 12" fill="none" class="ea-sort-arrow-icon">
      <path d="M4 1L1 4H7L4 1Z" fill="currentColor" class="ea-sort-up"/>
      <path d="M4 11L7 8H1L4 11Z" fill="currentColor" class="ea-sort-down"/>
    </svg>
  SVG
end


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]
  
  # Determine current sort direction and next direction
  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'
  
  # Build URL parameters
  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