notified_toggle_component use sorted_column

This commit is contained in:
simon lehericey 2024-10-08 19:40:19 +02:00
parent 22cbf725ec
commit 7349dd183a
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
4 changed files with 15 additions and 35 deletions

View file

@ -3,37 +3,6 @@
class Dossiers::NotifiedToggleComponent < ApplicationComponent
def initialize(procedure:, procedure_presentation:)
@procedure = procedure
@procedure_presentation = procedure_presentation
@current_sort = procedure_presentation.sort
end
private
def opposite_order
@procedure_presentation.opposite_order_for(current_table, current_column)
end
def active?
sorted_by_notifications? && order_desc?
end
def order_desc?
current_order == 'desc'
end
def current_order
@current_sort['order']
end
def current_table
@current_sort['table']
end
def current_column
@current_sort['column']
end
def sorted_by_notifications?
current_table == 'notifications' && current_column == 'notifications'
@sorted_column = procedure_presentation.sorted_column
end
end

View file

@ -1,6 +1,9 @@
= form_tag update_sort_instructeur_procedure_path(procedure_id: @procedure.id, column_id: @procedure.notifications_column.id, order: opposite_order), method: :get, data: { controller: 'autosubmit' } do
= form_tag update_sort_instructeur_procedure_path(@procedure),
method: :get, data: { controller: 'autosubmit' } do
.fr-fieldset__element.fr-m-0
.fr-checkbox-group.fr-checkbox-group--sm
= check_box_tag :order, opposite_order, active?
= label_tag :order, t('.show_notified_first'), class: 'fr-label'
= hidden_field_tag 'column_id', @procedure.notifications_column.id
= hidden_field_tag 'order', 'asc', id: nil
= check_box_tag 'order', 'desc', @sorted_column.sort_by_notifications?
= label_tag 'order', t('.show_notified_first'), class: 'fr-label'
= submit_tag t('.show_notified_first'), data: {"checkbox-target": 'submit' }, class: 'visually-hidden'

View file

@ -28,6 +28,10 @@ class Column
}
end
def notifications?
table == 'notifications' && column == 'notifications'
end
def self.find(h_id)
Procedure.with_discarded.find(h_id[:procedure_id]).find_column(h_id:)
end

View file

@ -15,4 +15,8 @@ class SortedColumn
def ==(other)
other&.column == column && other.order == order
end
def sort_by_notifications?
@column.notifications? && @order == 'desc'
end
end