move update_sort
This commit is contained in:
parent
b7a43f3f44
commit
e3ee756da4
2 changed files with 16 additions and 17 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue