use update(sorted_column:) and remove obsolete update_sort(column_id:, order:)
This commit is contained in:
parent
b7ecff4f0d
commit
da98aa556b
6 changed files with 19 additions and 51 deletions
|
@ -2,8 +2,8 @@
|
|||
method: :get, data: { controller: 'autosubmit' } do
|
||||
.fr-fieldset__element.fr-m-0
|
||||
.fr-checkbox-group.fr-checkbox-group--sm
|
||||
= 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'
|
||||
= hidden_field_tag 'sorted_column[id]', @procedure.notifications_column.id
|
||||
= hidden_field_tag 'sorted_column[order]', 'asc', id: nil
|
||||
= check_box_tag 'sorted_column[order]', 'desc', @sorted_column.sort_by_notifications?
|
||||
= label_tag 'sorted_column[order]', t('.show_notified_first'), class: 'fr-label'
|
||||
= submit_tag t('.show_notified_first'), data: {"checkbox-target": 'submit' }, class: 'visually-hidden'
|
||||
|
|
|
@ -10,10 +10,10 @@ class Instructeurs::ColumnTableHeaderComponent < ApplicationComponent
|
|||
private
|
||||
|
||||
def update_sort_path(column)
|
||||
column_id = column.id
|
||||
id = column.id
|
||||
order = opposite_order_for(column)
|
||||
|
||||
update_sort_instructeur_procedure_path(@procedure, column_id:, order:)
|
||||
update_sort_instructeur_procedure_path(@procedure, sorted_column: { id:, order: })
|
||||
end
|
||||
|
||||
def opposite_order_for(column)
|
||||
|
|
|
@ -141,7 +141,7 @@ module Instructeurs
|
|||
end
|
||||
|
||||
def update_sort
|
||||
procedure_presentation.update_sort(params[:column_id], params[:order])
|
||||
procedure_presentation.update!(sorted_column_params)
|
||||
|
||||
redirect_back(fallback_location: instructeur_procedure_url(procedure))
|
||||
end
|
||||
|
@ -411,5 +411,9 @@ module Instructeurs
|
|||
def cookies_export_key
|
||||
"exports_#{@procedure.id}_seen_at"
|
||||
end
|
||||
|
||||
def sorted_column_params
|
||||
params.permit(sorted_column: [:order, :id])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -153,24 +153,6 @@ class ProcedurePresentation < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def update_sort(column_id, order)
|
||||
h_id = JSON.parse(column_id, symbolize_names: true)
|
||||
column = procedure.find_column(h_id:)
|
||||
order = order.presence || opposite_order_for(column.table, column.column)
|
||||
|
||||
update!(
|
||||
sort: {
|
||||
TABLE => column.table,
|
||||
COLUMN => column.column,
|
||||
ORDER => order
|
||||
},
|
||||
sorted_column: {
|
||||
order:,
|
||||
id: h_id
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
def snapshot
|
||||
slice(:filters, :sort, :displayed_fields)
|
||||
end
|
||||
|
|
|
@ -886,11 +886,11 @@ describe Instructeurs::ProceduresController, type: :controller do
|
|||
end
|
||||
|
||||
it 'can change order' do
|
||||
column_id = procedure.find_column(label: "Nom").id
|
||||
expect { get :update_sort, params: { procedure_id: procedure.id, column_id:, order: 'asc' } }
|
||||
.to change { procedure_presentation.sort }
|
||||
.from({ "column" => "notifications", "order" => "desc", "table" => "notifications" })
|
||||
.to({ "column" => "nom", "order" => "asc", "table" => "individual" })
|
||||
column = procedure.find_column(label: "Nom")
|
||||
expect { get :update_sort, params: { procedure_id: procedure.id, sorted_column: { id: column.id, order: 'asc' } } }
|
||||
.to change { procedure_presentation.sorted_column }
|
||||
.from(procedure.default_sorted_column)
|
||||
.to(SortedColumn.new(column:, order: 'asc'))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -971,7 +971,7 @@ describe ProcedurePresentation do
|
|||
describe '#update_displayed_fields' do
|
||||
let(:procedure_presentation) do
|
||||
create(:procedure_presentation, assign_to:).tap do |pp|
|
||||
pp.update_sort(procedure.find_column(label: 'Demandeur').id, 'desc')
|
||||
pp.update(sorted_column: SortedColumn.new(column: procedure.find_column(label: 'Demandeur'), order: 'desc'))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -992,26 +992,8 @@ describe ProcedurePresentation do
|
|||
{ "column_id" => "self/updated_at", "procedure_id" => procedure.id }
|
||||
])
|
||||
|
||||
expect(procedure_presentation.sorted_column['id']).to eq("column_id" => "self/id", "procedure_id" => procedure.id)
|
||||
expect(procedure_presentation.sorted_column['order']).to eq('desc')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#update_sort' do
|
||||
let(:procedure_presentation) { create(:procedure_presentation, assign_to:) }
|
||||
|
||||
subject do
|
||||
column_id = procedure.find_column(label: 'En construction le').id
|
||||
procedure_presentation.update_sort(column_id, 'asc')
|
||||
end
|
||||
|
||||
it 'should update sort and order' do
|
||||
expect(procedure_presentation.sorted_column).to be_nil
|
||||
|
||||
subject
|
||||
|
||||
expect(procedure_presentation.sorted_column['id']).to eq("column_id" => "self/en_construction_at", "procedure_id" => procedure.id)
|
||||
expect(procedure_presentation.sorted_column['order']).to eq('asc')
|
||||
expect(procedure_presentation.sorted_column).to eq(procedure.default_sorted_column)
|
||||
expect(procedure_presentation.sorted_column.order).to eq('desc')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue