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
|
end
|
||||||
|
|
||||||
def update_sort
|
def update_sort
|
||||||
current_sort = procedure_presentation.sort
|
procedure_presentation.update_sort(params[:table], params[:column])
|
||||||
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)
|
|
||||||
|
|
||||||
redirect_back(fallback_location: instructeur_procedure_url(procedure))
|
redirect_back(fallback_location: instructeur_procedure_url(procedure))
|
||||||
end
|
end
|
||||||
|
|
|
@ -232,6 +232,21 @@ class ProcedurePresentation < ApplicationRecord
|
||||||
update!(sort: Procedure.default_sort)
|
update!(sort: Procedure.default_sort)
|
||||||
end
|
end
|
||||||
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
|
private
|
||||||
|
|
||||||
def field_id(field)
|
def field_id(field)
|
||||||
|
|
Loading…
Reference in a new issue