notified_toggle_component use sorted_column
This commit is contained in:
parent
22cbf725ec
commit
7349dd183a
4 changed files with 15 additions and 35 deletions
|
@ -3,37 +3,6 @@
|
||||||
class Dossiers::NotifiedToggleComponent < ApplicationComponent
|
class Dossiers::NotifiedToggleComponent < ApplicationComponent
|
||||||
def initialize(procedure:, procedure_presentation:)
|
def initialize(procedure:, procedure_presentation:)
|
||||||
@procedure = procedure
|
@procedure = procedure
|
||||||
@procedure_presentation = procedure_presentation
|
@sorted_column = procedure_presentation.sorted_column
|
||||||
@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'
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -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-fieldset__element.fr-m-0
|
||||||
.fr-checkbox-group.fr-checkbox-group--sm
|
.fr-checkbox-group.fr-checkbox-group--sm
|
||||||
= check_box_tag :order, opposite_order, active?
|
= hidden_field_tag 'column_id', @procedure.notifications_column.id
|
||||||
= label_tag :order, t('.show_notified_first'), class: 'fr-label'
|
= 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'
|
= submit_tag t('.show_notified_first'), data: {"checkbox-target": 'submit' }, class: 'visually-hidden'
|
||||||
|
|
|
@ -28,6 +28,10 @@ class Column
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def notifications?
|
||||||
|
table == 'notifications' && column == 'notifications'
|
||||||
|
end
|
||||||
|
|
||||||
def self.find(h_id)
|
def self.find(h_id)
|
||||||
Procedure.with_discarded.find(h_id[:procedure_id]).find_column(h_id:)
|
Procedure.with_discarded.find(h_id[:procedure_id]).find_column(h_id:)
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,4 +15,8 @@ class SortedColumn
|
||||||
def ==(other)
|
def ==(other)
|
||||||
other&.column == column && other.order == order
|
other&.column == column && other.order == order
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sort_by_notifications?
|
||||||
|
@column.notifications? && @order == 'desc'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue