Class: Components::SortMenu

Inherits:
Base
  • Object
show all
Defined in:
app/components/sort_menu.rb

Instance Method Summary collapse

Constructor Details

#initialize(filter: {}) ⇒ SortMenu

Returns a new instance of SortMenu.



4
5
6
# File 'app/components/sort_menu.rb', line 4

def initialize(filter: {})
  @filter = filter
end

Instance Method Details

#item(icon, key, direction) ⇒ Object



35
36
37
# File 'app/components/sort_menu.rb', line 35

def item(icon, key, direction)
  DropdownItem icon: icon, label: t("components.sort_menu.%{key}" % {key: key}), path: ordered_url(key, direction), active: ordering_by?(key)
end

#ordered_url(order, direction) ⇒ Object



31
32
33
# File 'app/components/sort_menu.rb', line 31

def ordered_url(order, direction)
  url_for({order: order, direction: direction}.merge(@filter&.to_params))
end

#ordering_by?(order) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
# File 'app/components/sort_menu.rb', line 23

def ordering_by?(order)
  if current_user
    current_user.sort_order == order
  else
    session["order"] == order
  end
end

#view_template ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/components/sort_menu.rb', line 8

def view_template
  div class: "btn-group" do
    button type: "button", data: {bs_toggle: "dropdown"}, aria: {expanded: "false"}, class: "btn btn-sm dropdown-toggle" do
      Icon(icon: "sort-down")
      whitespace
      span { User.human_attribute_name(:sort_order) }
    end
    ul class: "dropdown-menu" do
      item "sort-alpha-down", "name", "asc" # i18n-tasks-use t('components.sort_menu.name')
      item "sort-numeric-down-alt", "recent", "desc" # i18n-tasks-use t('components.sort_menu.recent')
      item "sort-numeric-down-alt", "updated", "desc" # i18n-tasks-use t('components.sort_menu.updated')
    end
  end
end