Class: Admin::SortableComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
lib/generators/infold/templates/install/app/components/admin/sortable_component.rb

Instance Method Summary collapse

Constructor Details

#initialize(search, field, label: nil) ⇒ SortableComponent

Returns a new instance of SortableComponent.



5
6
7
8
9
# File 'lib/generators/infold/templates/install/app/components/admin/sortable_component.rb', line 5

def initialize(search, field, label: nil)
  @search = search
  @field = field.to_s
  @label = label
end

Instance Method Details

#current_field?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/generators/infold/templates/install/app/components/admin/sortable_component.rb', line 23

def current_field?
  @search.sort_field.to_s == @field
end

#datasetObject



11
12
13
14
15
16
17
# File 'lib/generators/infold/templates/install/app/components/admin/sortable_component.rb', line 11

def dataset
  {
    action: 'index-page#sortChange',
    sort_field: @field,
    sort_kind: current_field? && sort_kind == 'desc' ? 'asc' : 'desc'
  }
end

#nameObject



19
20
21
# File 'lib/generators/infold/templates/install/app/components/admin/sortable_component.rb', line 19

def name
  @label.presence || @search.class.human_attribute_name(@field)
end

#sort_kindObject



27
28
29
# File 'lib/generators/infold/templates/install/app/components/admin/sortable_component.rb', line 27

def sort_kind
  @search.sort_kind.to_s
end

#sort_status_iconObject



31
32
33
# File 'lib/generators/infold/templates/install/app/components/admin/sortable_component.rb', line 31

def sort_status_icon
  "<i class=\"ms-1 bi bi-chevron-#{sort_kind == 'desc' ? 'down' : 'up'}\"></i>".html_safe if current_field?
end