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
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Instructeurs::ColumnTableHeaderComponent < ApplicationComponent
|
class Instructeurs::ColumnTableHeaderComponent < ApplicationComponent
|
||||||
attr_reader :procedure_presentation, :column
|
def initialize(procedure_presentation:)
|
||||||
# maybe extract a ColumnSorter class?
|
|
||||||
#
|
|
||||||
|
|
||||||
def initialize(procedure_presentation:, column:)
|
|
||||||
@procedure_presentation = procedure_presentation
|
@procedure_presentation = procedure_presentation
|
||||||
@column = column
|
@columns = procedure_presentation.displayed_fields_for_headers
|
||||||
|
@sorted_column = procedure_presentation.sorted_column
|
||||||
end
|
end
|
||||||
|
|
||||||
def column_id
|
def label_and_arrow(column)
|
||||||
column.id
|
return column.label if @sorted_column.column != column
|
||||||
|
|
||||||
|
@sorted_column.ascending? ? "#{column.label} ↑" : "#{column.label} ↓"
|
||||||
end
|
end
|
||||||
|
|
||||||
def sorted_by_current_column?
|
def aria_sort(column)
|
||||||
procedure_presentation.sort['table'] == column.table &&
|
return {} if @sorted_column.column != column
|
||||||
procedure_presentation.sort['column'] == column.column
|
|
||||||
end
|
|
||||||
|
|
||||||
def sorted_ascending?
|
@sorted_column.ascending? ? { "aria-sort": "ascending" } : { "aria-sort": "descending" }
|
||||||
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']
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,4 @@
|
||||||
%th{ aria_sort, scope: "col", class: column.classname }
|
- @columns.each do |column|
|
||||||
= link_to update_sort_instructeur_procedure_path(@procedure_presentation.procedure, column_id:, order: @procedure_presentation.opposite_order_for(column.table, column.column)) do
|
%th{ aria_sort(column), scope: "col", class: column.classname }
|
||||||
- if sorted_by_current_column?
|
= 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
|
||||||
- if sorted_ascending?
|
= label_and_arrow(column)
|
||||||
#{column.label} ↑
|
|
||||||
- else
|
|
||||||
#{column.label} ↓
|
|
||||||
- else
|
|
||||||
#{column.label}
|
|
||||||
|
|
|
@ -93,8 +93,7 @@
|
||||||
%th.text-center
|
%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') } }
|
%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)
|
||||||
= render Instructeurs::ColumnTableHeaderComponent.new(procedure_presentation: @procedure_presentation, column:)
|
|
||||||
|
|
||||||
%th.follow-col
|
%th.follow-col
|
||||||
Actions
|
Actions
|
||||||
|
|
Loading…
Reference in a new issue