move update_displayed_fields to procedure_presentation
This commit is contained in:
parent
cbccdea8e0
commit
b7a43f3f44
2 changed files with 15 additions and 20 deletions
|
@ -138,22 +138,7 @@ module Instructeurs
|
|||
end
|
||||
|
||||
def update_displayed_fields
|
||||
values = params[:values]
|
||||
|
||||
if values.nil?
|
||||
values = []
|
||||
end
|
||||
|
||||
fields = values.map do |value|
|
||||
find_field(*value.split('/'))
|
||||
end
|
||||
|
||||
procedure_presentation.update(displayed_fields: fields)
|
||||
|
||||
current_sort = procedure_presentation.sort
|
||||
if !values.include?(field_id(current_sort))
|
||||
procedure_presentation.update(sort: Procedure.default_sort)
|
||||
end
|
||||
procedure_presentation.update_displayed_fields(params[:values])
|
||||
|
||||
redirect_back(fallback_location: instructeur_procedure_url(procedure))
|
||||
end
|
||||
|
@ -270,10 +255,6 @@ module Instructeurs
|
|||
@ods_export = Export.find_for_format_and_groupe_instructeurs(:ods, groupe_instructeurs_for_procedure)
|
||||
end
|
||||
|
||||
def find_field(table, column)
|
||||
procedure_presentation.fields.find { |c| c['table'] == table && c['column'] == column }
|
||||
end
|
||||
|
||||
def assign_to
|
||||
current_instructeur.assign_to.joins(:groupe_instructeur).find_by(groupe_instructeurs: { procedure: procedure })
|
||||
end
|
||||
|
|
|
@ -218,6 +218,20 @@ class ProcedurePresentation < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
def update_displayed_fields(values)
|
||||
if values.nil?
|
||||
values = []
|
||||
end
|
||||
|
||||
fields = values.map { |value| find_field(*value.split('/')) }
|
||||
|
||||
update!(displayed_fields: fields)
|
||||
|
||||
if !values.include?(field_id(sort))
|
||||
update!(sort: Procedure.default_sort)
|
||||
end
|
||||
end
|
||||
private
|
||||
|
||||
def field_id(field)
|
||||
|
|
Loading…
Add table
Reference in a new issue