column_table_header_component use sorted_column
This commit is contained in:
parent
21533f91e3
commit
b582a2afc6
3 changed files with 15 additions and 47 deletions
|
@ -1,47 +1,21 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Instructeurs::ColumnTableHeaderComponent < ApplicationComponent
|
||||
attr_reader :procedure_presentation, :column
|
||||
# maybe extract a ColumnSorter class?
|
||||
#
|
||||
|
||||
def initialize(procedure_presentation:, column:)
|
||||
def initialize(procedure_presentation:)
|
||||
@procedure_presentation = procedure_presentation
|
||||
@column = column
|
||||
@columns = procedure_presentation.displayed_fields_for_headers
|
||||
@sorted_column = procedure_presentation.sorted_column
|
||||
end
|
||||
|
||||
def column_id
|
||||
column.id
|
||||
def label_and_arrow(column)
|
||||
return column.label if @sorted_column.column != column
|
||||
|
||||
@sorted_column.ascending? ? "#{column.label} ↑" : "#{column.label} ↓"
|
||||
end
|
||||
|
||||
def sorted_by_current_column?
|
||||
procedure_presentation.sort['table'] == column.table &&
|
||||
procedure_presentation.sort['column'] == column.column
|
||||
end
|
||||
def aria_sort(column)
|
||||
return {} if @sorted_column.column != column
|
||||
|
||||
def sorted_ascending?
|
||||
current_sort_order == 'asc'
|
||||
end
|
||||
|
||||
def sorted_descending?
|
||||
current_sort_order == 'desc'
|
||||
end
|
||||
|
||||
def aria_sort
|
||||
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']
|
||||
@sorted_column.ascending? ? { "aria-sort": "ascending" } : { "aria-sort": "descending" }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
%th{ aria_sort, scope: "col", class: column.classname }
|
||||
= link_to update_sort_instructeur_procedure_path(@procedure_presentation.procedure, column_id:, order: @procedure_presentation.opposite_order_for(column.table, column.column)) do
|
||||
- if sorted_by_current_column?
|
||||
- if sorted_ascending?
|
||||
#{column.label} ↑
|
||||
- else
|
||||
#{column.label} ↓
|
||||
- else
|
||||
#{column.label}
|
||||
- @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)
|
||||
|
|
|
@ -93,8 +93,7 @@
|
|||
%th.text-center
|
||||
%input{ type: "checkbox", disabled: @disable_checkbox_all, checked: @disable_checkbox_all, data: { action: "batch-operation#onCheckAll" }, id: dom_id(BatchOperation.new, :checkbox_all), aria: { label: t('views.instructeurs.dossiers.select_all') } }
|
||||
|
||||
- @procedure_presentation.displayed_fields_for_headers.each do |column|
|
||||
= render Instructeurs::ColumnTableHeaderComponent.new(procedure_presentation: @procedure_presentation, column:)
|
||||
= render Instructeurs::ColumnTableHeaderComponent.new(procedure_presentation: @procedure_presentation)
|
||||
|
||||
%th.follow-col
|
||||
Actions
|
||||
|
|
Loading…
Reference in a new issue