feat(annotations): activate autosave

This commit is contained in:
Paul Chavard 2023-03-01 18:30:10 +01:00
parent ff10a03ffe
commit cbaa77fca7
24 changed files with 147 additions and 117 deletions

View file

@ -1,6 +1,7 @@
module Users
class DossiersController < UserController
include DossierHelper
include TurboChampsConcern
layout 'procedure_context', only: [:identite, :update_identite, :siret, :update_siret]
@ -198,7 +199,7 @@ module Users
respond_to do |format|
format.html { render :brouillon }
format.turbo_stream do
@to_show, @to_hide, @to_update = champs_to_turbo_update
@to_show, @to_hide, @to_update = champs_to_turbo_update(champs_public_params.fetch(:champs_public_all_attributes), dossier.champs_public_all)
render(:update, layout: false)
end
@ -216,7 +217,7 @@ module Users
respond_to do |format|
format.html { render :modifier }
format.turbo_stream do
@to_show, @to_hide, @to_update = champs_to_turbo_update
@to_show, @to_hide, @to_update = champs_to_turbo_update(champs_public_params.fetch(:champs_public_all_attributes), dossier.champs_public_all)
end
end
end
@ -483,24 +484,6 @@ module Users
errors
end
def champs_to_turbo_update
champ_ids = champs_public_params
.fetch(:champs_public_all_attributes)
.keys
.map(&:to_i)
to_update = dossier
.champs_public_all
.filter { _1.id.in?(champ_ids) && _1.refresh_after_update? }
to_show, to_hide = dossier
.champs_public_all
.filter(&:conditional?)
.partition(&:visible?)
.map { champs_to_one_selector(_1 - to_update) }
return to_show, to_hide, to_update
end
def ensure_ownership!
if !current_user.owns?(dossier)
forbidden!
@ -561,12 +544,5 @@ module Users
submit_validation_options
end
end
def champs_to_one_selector(champs)
champs
.map(&:input_group_id)
.map { |id| "##{id}" }
.join(',')
end
end
end