move update_sort

This commit is contained in:
simon lehericey 2020-10-30 14:31:24 +01:00 committed by Paul Chavard
parent b7a43f3f44
commit e3ee756da4
2 changed files with 16 additions and 17 deletions

View file

@ -144,23 +144,7 @@ module Instructeurs
end
def update_sort
current_sort = procedure_presentation.sort
table = params[:table]
column = params[:column]
if table == current_sort['table'] && column == current_sort['column']
order = current_sort['order'] == 'asc' ? 'desc' : 'asc'
else
order = 'asc'
end
sort = {
'table' => table,
'column' => column,
'order' => order
}
procedure_presentation.update(sort: sort)
procedure_presentation.update_sort(params[:table], params[:column])
redirect_back(fallback_location: instructeur_procedure_url(procedure))
end

View file

@ -232,6 +232,21 @@ class ProcedurePresentation < ApplicationRecord
update!(sort: Procedure.default_sort)
end
end
def update_sort(table, column)
order = if sort.values_at('table', 'column') == [table, column]
sort['order'] == 'asc' ? 'desc' : 'asc'
else
'asc'
end
update!(sort: {
'table' => table,
'column' => column,
'order' => order
})
end
private
def field_id(field)