Class: Katalyst::Tables::Sortable::SortableHeaderComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Katalyst::Tables::Sortable::SortableHeaderComponent
- Includes:
- HtmlAttributes
- Defined in:
- app/components/concerns/katalyst/tables/sortable.rb
Instance Attribute Summary collapse
-
#cell ⇒ Object
readonly
Returns the value of attribute cell.
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
Instance Method Summary collapse
- #call ⇒ Object
- #default_html_attributes ⇒ Object
-
#initialize(collection:, cell:) ⇒ SortableHeaderComponent
constructor
A new instance of SortableHeaderComponent.
-
#sort_url ⇒ Object
Generates a url for applying/toggling sort for the given column.
Constructor Details
#initialize(collection:, cell:) ⇒ SortableHeaderComponent
Returns a new instance of SortableHeaderComponent.
32 33 34 35 36 37 |
# File 'app/components/concerns/katalyst/tables/sortable.rb', line 32 def initialize(collection:, cell:, **) super(**) @collection = collection @cell = cell end |
Instance Attribute Details
#cell ⇒ Object (readonly)
Returns the value of attribute cell.
28 29 30 |
# File 'app/components/concerns/katalyst/tables/sortable.rb', line 28 def cell @cell end |
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
28 29 30 |
# File 'app/components/concerns/katalyst/tables/sortable.rb', line 28 def collection @collection end |
Instance Method Details
#call ⇒ Object
39 40 41 |
# File 'app/components/concerns/katalyst/tables/sortable.rb', line 39 def call link_to(content, sort_url, **html_attributes) end |
#default_html_attributes ⇒ Object
60 61 62 |
# File 'app/components/concerns/katalyst/tables/sortable.rb', line 60 def default_html_attributes { data: { turbo_action: "replace" } } end |
#sort_url ⇒ Object
Generates a url for applying/toggling sort for the given column.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/components/concerns/katalyst/tables/sortable.rb', line 44 def sort_url # rubocop:disable Metrics/AbcSize # Implementation inspired by pagy's `pagy_url_for` helper. # Preserve any existing GET parameters # CAUTION: these parameters are not sanitised sort = column && collection.toggle_sort(column) params = if sort && !sort.eql?(collection.default_sort) request.GET.merge("sort" => sort).except("page") else request.GET.except("page", "sort") end query_string = params.empty? ? "" : "?#{Rack::Utils.build_nested_query(params)}" "#{request.path}#{query_string}" end |