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-10-25 10:34:58 +02:00
|
|
|
@procedure_presentation = procedure_presentation
|
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
|
|
|
|
|
2024-10-09 09:51:47 +02:00
|
|
|
def classname(column)
|
|
|
|
return 'status-col' if column.dossier_state?
|
|
|
|
return 'number-col' if column.type == :number
|
|
|
|
return 'sva-col' if column.column == 'sva_svr_decision_on'
|
|
|
|
end
|
|
|
|
|
2024-10-25 10:34:58 +02:00
|
|
|
def column_header(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-10-25 10:34:58 +02:00
|
|
|
button_to(
|
|
|
|
label_and_arrow(column),
|
|
|
|
[:instructeur, @procedure_presentation],
|
|
|
|
params: { sorted_column: { id: id, order: order } },
|
|
|
|
class: 'fr-text--bold'
|
|
|
|
)
|
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
|