extract Instructeurs::FacetTableHeaderComponent wrapping sort logic
This commit is contained in:
parent
31255b69cc
commit
743ff8c8a9
4 changed files with 51 additions and 19 deletions
40
app/components/instructeurs/column_table_header_component.rb
Normal file
40
app/components/instructeurs/column_table_header_component.rb
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
class Instructeurs::ColumnTableHeaderComponent < ApplicationComponent
|
||||||
|
attr_reader :procedure_presentation, :facet
|
||||||
|
# maybe extract a FacetSorter class?
|
||||||
|
|
||||||
|
def initialize(procedure_presentation:, facet:)
|
||||||
|
@procedure_presentation = procedure_presentation
|
||||||
|
@facet = facet
|
||||||
|
end
|
||||||
|
|
||||||
|
def sorted_by_current_facet?
|
||||||
|
procedure_presentation.sort['table'] == facet.table &&
|
||||||
|
procedure_presentation.sort['column'] == facet.column
|
||||||
|
end
|
||||||
|
|
||||||
|
def sorted_ascending?
|
||||||
|
current_sort_order == 'asc'
|
||||||
|
end
|
||||||
|
|
||||||
|
def sorted_descending?
|
||||||
|
current_sort_order == 'desc'
|
||||||
|
end
|
||||||
|
|
||||||
|
def aria_sort
|
||||||
|
if sorted_by_current_facet?
|
||||||
|
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
|
|
@ -0,0 +1,9 @@
|
||||||
|
%th{ aria_sort, scope: "col", class: facet.classname }
|
||||||
|
= link_to update_sort_instructeur_procedure_path(@procedure_presentation.procedure, table: facet.table, column: facet.column, order: @procedure_presentation.opposite_order_for(facet.table, facet.column)) do
|
||||||
|
- if sorted_by_current_facet?
|
||||||
|
- if sorted_ascending?
|
||||||
|
#{facet.label} ↑
|
||||||
|
- else
|
||||||
|
#{facet.label} ↓
|
||||||
|
- else
|
||||||
|
#{facet.label}
|
|
@ -146,23 +146,6 @@ class ProcedurePresentation < ApplicationRecord
|
||||||
slice(:filters, :sort, :displayed_fields)
|
slice(:filters, :sort, :displayed_fields)
|
||||||
end
|
end
|
||||||
|
|
||||||
def sorted_by?(facet)
|
|
||||||
sort['table'] == facet.table &&
|
|
||||||
sort['column'] == facet.column
|
|
||||||
end
|
|
||||||
|
|
||||||
def aria_sort(order, field)
|
|
||||||
if sorted_by?(field)
|
|
||||||
if order == 'asc'
|
|
||||||
{ "aria-sort": "ascending" }
|
|
||||||
elsif order == 'desc'
|
|
||||||
{ "aria-sort": "descending" }
|
|
||||||
end
|
|
||||||
else
|
|
||||||
{}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def sorted_ids(dossiers, count)
|
def sorted_ids(dossiers, count)
|
||||||
|
|
|
@ -98,8 +98,8 @@
|
||||||
%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 |field|
|
- @procedure_presentation.displayed_fields_for_headers.each do |facet|
|
||||||
= render partial: "header_field", locals: { field: field }
|
= render Instructeurs::ColumnTableHeaderComponent.new(procedure_presentation: @procedure_presentation, facet:)
|
||||||
|
|
||||||
%th.follow-col
|
%th.follow-col
|
||||||
Actions
|
Actions
|
||||||
|
|
Loading…
Reference in a new issue