demarches-normaliennes/app/components/instructeurs/column_table_header_component.rb

48 lines
960 B
Ruby
Raw Normal View History

# frozen_string_literal: true
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-08-19 14:34:36 +02:00
def initialize(procedure_presentation:, column:)
@procedure_presentation = procedure_presentation
2024-08-19 14:34:36 +02:00
@column = column
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
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?
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