column_table_header compute update_sort_path

This commit is contained in:
simon lehericey 2024-09-24 15:06:12 +02:00
parent b582a2afc6
commit 22cbf725ec
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
3 changed files with 17 additions and 3 deletions

View file

@ -2,11 +2,24 @@
class Instructeurs::ColumnTableHeaderComponent < ApplicationComponent
def initialize(procedure_presentation:)
@procedure_presentation = procedure_presentation
@procedure = procedure_presentation.procedure
@columns = procedure_presentation.displayed_fields_for_headers
@sorted_column = procedure_presentation.sorted_column
end
private
def update_sort_path(column)
column_id = column.id
order = opposite_order_for(column)
update_sort_instructeur_procedure_path(@procedure, column_id:, order:)
end
def opposite_order_for(column)
@sorted_column.column == column ? @sorted_column.opposite_order : 'asc'
end
def label_and_arrow(column)
return column.label if @sorted_column.column != column

View file

@ -1,4 +1,3 @@
- @columns.each do |column|
%th{ aria_sort(column), scope: "col", class: column.classname }
= link_to update_sort_instructeur_procedure_path(@procedure_presentation.procedure, column_id: column.id, order: @procedure_presentation.opposite_order_for(column.table, column.column)) do
= label_and_arrow(column)
= link_to label_and_arrow(column), update_sort_path(column)

View file

@ -10,6 +10,8 @@ class SortedColumn
def ascending? = @order == 'asc'
def opposite_order = ascending? ? 'desc' : 'asc'
def ==(other)
other&.column == column && other.order == order
end