2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-07-22 09:37:15 +02:00
|
|
|
class Instructeurs::ColumnTableHeaderComponent < ApplicationComponent
|
2024-09-24 15:05:25 +02:00
|
|
|
def initialize(procedure_presentation:)
|
2024-09-24 15:06:12 +02:00
|
|
|
@procedure = procedure_presentation.procedure
|
2024-09-24 15:05:25 +02:00
|
|
|
@columns = procedure_presentation.displayed_fields_for_headers
|
|
|
|
@sorted_column = procedure_presentation.sorted_column
|
2024-07-22 09:37:15 +02:00
|
|
|
end
|
|
|
|
|
2024-09-24 15:06:12 +02:00
|
|
|
private
|
|
|
|
|
|
|
|
def update_sort_path(column)
|
2024-09-25 17:43:43 +02:00
|
|
|
id = column.id
|
2024-09-24 15:06:12 +02:00
|
|
|
order = opposite_order_for(column)
|
|
|
|
|
2024-09-25 17:43:43 +02:00
|
|
|
update_sort_instructeur_procedure_path(@procedure, sorted_column: { id:, order: })
|
2024-09-24 15:06:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def opposite_order_for(column)
|
|
|
|
@sorted_column.column == column ? @sorted_column.opposite_order : 'asc'
|
|
|
|
end
|
|
|
|
|
2024-09-24 15:05:25 +02:00
|
|
|
def label_and_arrow(column)
|
|
|
|
return column.label if @sorted_column.column != column
|
2024-07-22 09:37:15 +02:00
|
|
|
|
2024-09-24 15:05:25 +02:00
|
|
|
@sorted_column.ascending? ? "#{column.label} ↑" : "#{column.label} ↓"
|
2024-07-22 09:37:15 +02:00
|
|
|
end
|
|
|
|
|
2024-09-24 15:05:25 +02:00
|
|
|
def aria_sort(column)
|
|
|
|
return {} if @sorted_column.column != column
|
2024-07-22 09:37:15 +02:00
|
|
|
|
2024-09-24 15:05:25 +02:00
|
|
|
@sorted_column.ascending? ? { "aria-sort": "ascending" } : { "aria-sort": "descending" }
|
2024-07-22 09:37:15 +02:00
|
|
|
end
|
|
|
|
end
|