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-08-19 14:34:36 +02:00
|
|
|
attr_reader :procedure_presentation, :column
|
|
|
|
# maybe extract a ColumnSorter class?
|
2024-07-22 11:32:07 +02:00
|
|
|
#
|
2024-07-22 09:37:15 +02:00
|
|
|
|
2024-08-19 14:34:36 +02:00
|
|
|
def initialize(procedure_presentation:, column:)
|
2024-07-22 09:37:15 +02:00
|
|
|
@procedure_presentation = procedure_presentation
|
2024-08-19 14:34:36 +02:00
|
|
|
@column = column
|
2024-07-22 09:37:15 +02:00
|
|
|
end
|
|
|
|
|
2024-08-19 14:34:36 +02:00
|
|
|
def column_id
|
|
|
|
column.id
|
2024-07-22 11:32:07 +02:00
|
|
|
end
|
|
|
|
|
2024-08-19 14:34:36 +02:00
|
|
|
def sorted_by_current_column?
|
|
|
|
procedure_presentation.sort['table'] == column.table &&
|
|
|
|
procedure_presentation.sort['column'] == column.column
|
2024-07-22 09:37:15 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def sorted_ascending?
|
|
|
|
current_sort_order == 'asc'
|
|
|
|
end
|
|
|
|
|
|
|
|
def sorted_descending?
|
|
|
|
current_sort_order == 'desc'
|
|
|
|
end
|
|
|
|
|
|
|
|
def aria_sort
|
2024-08-19 14:34:36 +02:00
|
|
|
if sorted_by_current_column?
|
2024-07-22 09:37:15 +02:00
|
|
|
if sorted_ascending?
|
|
|
|
{ "aria-sort": "ascending" }
|
|
|
|
elsif sorted_descending?
|
|
|
|
{ "aria-sort": "descending" }
|
|
|
|
end
|
|
|
|
else
|
|
|
|
{}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def current_sort_order
|
|
|
|
procedure_presentation.sort['order']
|
|
|
|
end
|
|
|
|
end
|