Class: Rails::AddOns::TableHelper::SortLink

Inherits:
Object
  • Object
show all
Defined in:
app/helpers/rails/add_ons/table_helper.rb

Constant Summary collapse

ARROW_UP =
'▲'
ARROW_DOWN =
'▼'

Instance Method Summary collapse

Constructor Details

#initialize(view_context, column_name, title, options) ⇒ SortLink


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/helpers/rails/add_ons/table_helper.rb', line 31

def initialize(view_context, column_name, title, options)
  default_options = {}

  if options === true
    @options = default_options
  else
    @options = options.reverse_merge(default_options)
  end

  @view_context = view_context
  @column_name  = @options[:column_name] || column_name
  @title        = title

  if h.params[:sort_direction].present?
    @sort_direction = sorted_ascending? ? :desc : :asc
  else
    @sort_direction = :asc
  end

  if sorted_by_this_column?
    if sorted_ascending?
      @title_with_arrow = add_arrow_up(@title)
    else
      @title_with_arrow = add_arrow_down(@title)
    end
  else
    @title_with_arrow = @title
  end
end

Instance Method Details

#performObject


61
62
63
# File 'app/helpers/rails/add_ons/table_helper.rb', line 61

def perform
  h.link_to(@title_with_arrow, h.url_for(h.request.query_parameters.merge(sort_by: @column_name, sort_direction: @sort_direction)))
end