Class: Admin::SortableComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Admin::SortableComponent
- Defined in:
- lib/generators/infold/templates/install/app/components/admin/sortable_component.rb
Instance Method Summary collapse
- #current_field? ⇒ Boolean
- #dataset ⇒ Object
-
#initialize(search, field, label: nil) ⇒ SortableComponent
constructor
A new instance of SortableComponent.
- #name ⇒ Object
- #sort_kind ⇒ Object
- #sort_status_icon ⇒ Object
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
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 |
#dataset ⇒ Object
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 |
#name ⇒ Object
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_kind ⇒ Object
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_icon ⇒ Object
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 |