From 7349dd183a0c609880e86af4dd767953b7e03053 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 8 Oct 2024 19:40:19 +0200 Subject: [PATCH] notified_toggle_component use sorted_column --- .../dossiers/notified_toggle_component.rb | 33 +------------------ .../notified_toggle_component.html.haml | 9 +++-- app/models/column.rb | 4 +++ app/models/sorted_column.rb | 4 +++ 4 files changed, 15 insertions(+), 35 deletions(-) diff --git a/app/components/dossiers/notified_toggle_component.rb b/app/components/dossiers/notified_toggle_component.rb index 713afcc83..dc927958a 100644 --- a/app/components/dossiers/notified_toggle_component.rb +++ b/app/components/dossiers/notified_toggle_component.rb @@ -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 diff --git a/app/components/dossiers/notified_toggle_component/notified_toggle_component.html.haml b/app/components/dossiers/notified_toggle_component/notified_toggle_component.html.haml index 84ff21cb9..4a45874c3 100644 --- a/app/components/dossiers/notified_toggle_component/notified_toggle_component.html.haml +++ b/app/components/dossiers/notified_toggle_component/notified_toggle_component.html.haml @@ -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' diff --git a/app/models/column.rb b/app/models/column.rb index 7e7a8159c..a62b129f1 100644 --- a/app/models/column.rb +++ b/app/models/column.rb @@ -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 diff --git a/app/models/sorted_column.rb b/app/models/sorted_column.rb index 9da384002..d6bf7dade 100644 --- a/app/models/sorted_column.rb +++ b/app/models/sorted_column.rb @@ -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