Class: FlexiAdmin::Components::Shared::Table::HeaderItemComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- FlexiAdmin::Components::Shared::Table::HeaderItemComponent
- Defined in:
- lib/flexi_admin/components/shared/table/header_item_component.rb
Instance Attribute Summary collapse
-
#attr ⇒ Object
readonly
Returns the value of attribute attr.
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#justify ⇒ Object
readonly
Returns the value of attribute justify.
-
#sort_by ⇒ Object
readonly
Returns the value of attribute sort_by.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
-
#initialize(column) ⇒ HeaderItemComponent
constructor
A new instance of HeaderItemComponent.
- #justify_class ⇒ Object
- #label ⇒ Object
- #merged_classes ⇒ Object
- #order ⇒ Object
- #sort_icon ⇒ Object
- #sort_path ⇒ Object
- #width_class ⇒ Object
Constructor Details
#initialize(column) ⇒ HeaderItemComponent
Returns a new instance of HeaderItemComponent.
7 8 9 10 11 12 13 14 |
# File 'lib/flexi_admin/components/shared/table/header_item_component.rb', line 7 def initialize(column) @column = column @justify = column.[:justify] || :start @width = column.[:width] || "" @attr = column.attribute @sort_by = column.sort_by @label = column.label end |
Instance Attribute Details
#attr ⇒ Object (readonly)
Returns the value of attribute attr.
5 6 7 |
# File 'lib/flexi_admin/components/shared/table/header_item_component.rb', line 5 def attr @attr end |
#column ⇒ Object (readonly)
Returns the value of attribute column.
5 6 7 |
# File 'lib/flexi_admin/components/shared/table/header_item_component.rb', line 5 def column @column end |
#justify ⇒ Object (readonly)
Returns the value of attribute justify.
5 6 7 |
# File 'lib/flexi_admin/components/shared/table/header_item_component.rb', line 5 def justify @justify end |
#sort_by ⇒ Object (readonly)
Returns the value of attribute sort_by.
5 6 7 |
# File 'lib/flexi_admin/components/shared/table/header_item_component.rb', line 5 def sort_by @sort_by end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
5 6 7 |
# File 'lib/flexi_admin/components/shared/table/header_item_component.rb', line 5 def width @width end |
Instance Method Details
#justify_class ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/flexi_admin/components/shared/table/header_item_component.rb', line 36 def justify_class case justify.to_sym when :start "justify-content-start" when :end "justify-content-end" else "justify-content-start" end end |
#label ⇒ Object
16 17 18 |
# File 'lib/flexi_admin/components/shared/table/header_item_component.rb', line 16 def label @label || attr.to_s.humanize end |
#merged_classes ⇒ Object
28 29 30 |
# File 'lib/flexi_admin/components/shared/table/header_item_component.rb', line 28 def merged_classes [width_class, justify_class].join(" ") end |
#order ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/flexi_admin/components/shared/table/header_item_component.rb', line 60 def order # Sorting by other column, so we need to reset the order return "asc" if view_context.context.params[:sort].to_s != sort_by.to_s order = case view_context.context.params[:order] when "asc" "desc" when "desc" "default" when "default" "asc" else "asc" end order end |
#sort_icon ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/flexi_admin/components/shared/table/header_item_component.rb', line 47 def sort_icon return "bi-arrow-up-square" if view_context.context.params[:sort].to_s != sort_by.to_s case view_context.context.params[:order] when "asc" "bi-arrow-up-square-fill" when "desc" "bi-arrow-down-square-fill" else "bi-arrow-up-square" end end |
#sort_path ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/flexi_admin/components/shared/table/header_item_component.rb', line 20 def sort_path if order.blank? view_context.context.params.to_path(request.path) else view_context.context.params.merge({ sort: sort_by, order: }).to_path(request.path) end end |
#width_class ⇒ Object
32 33 34 |
# File 'lib/flexi_admin/components/shared/table/header_item_component.rb', line 32 def width_class width.present? ? "col-#{width}" : "col" end |