column_table_header compute update_sort_path
This commit is contained in:
parent
b582a2afc6
commit
22cbf725ec
3 changed files with 17 additions and 3 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue