feat(dossier): implement refresh_after_update on champs
This commit is contained in:
parent
60e3ebd7c7
commit
f38ee8f03f
5 changed files with 41 additions and 12 deletions
|
@ -60,6 +60,10 @@ class TypesDeChampEditor::ChampComponent < ApplicationComponent
|
||||||
|
|
||||||
TypeDeChamp.type_champs
|
TypeDeChamp.type_champs
|
||||||
.keys
|
.keys
|
||||||
|
# FIXME
|
||||||
|
# We can only refresh after update champs when autosave is enabled. And it is disabled for now in private forms.
|
||||||
|
# So for new we restrict champs that require refresh after update to public forms.
|
||||||
|
.filter { type_de_champ.public? || !TypeDeChamp.refresh_after_update?(_1) }
|
||||||
.filter(&method(:filter_type_champ))
|
.filter(&method(:filter_type_champ))
|
||||||
.filter(&method(:filter_featured_type_champ))
|
.filter(&method(:filter_featured_type_champ))
|
||||||
.filter(&method(:filter_block_type_champ))
|
.filter(&method(:filter_block_type_champ))
|
||||||
|
|
|
@ -201,10 +201,7 @@ module Users
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { render :brouillon }
|
format.html { render :brouillon }
|
||||||
format.turbo_stream do
|
format.turbo_stream do
|
||||||
@to_shows, @to_hides = @dossier.champs_public_all
|
@to_show, @to_hide, @to_update = champs_to_turbo_update
|
||||||
.filter(&:conditional?)
|
|
||||||
.partition(&:visible?)
|
|
||||||
.map { |champs| champs_to_one_selector(champs) }
|
|
||||||
|
|
||||||
render(:update, layout: false)
|
render(:update, layout: false)
|
||||||
end
|
end
|
||||||
|
@ -222,10 +219,7 @@ module Users
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { render :modifier }
|
format.html { render :modifier }
|
||||||
format.turbo_stream do
|
format.turbo_stream do
|
||||||
@to_shows, @to_hides = @dossier.champs_public_all
|
@to_show, @to_hide, @to_update = champs_to_turbo_update
|
||||||
.filter(&:conditional?)
|
|
||||||
.partition(&:visible?)
|
|
||||||
.map { |champs| champs_to_one_selector(champs) }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -493,6 +487,24 @@ module Users
|
||||||
errors
|
errors
|
||||||
end
|
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!
|
def ensure_ownership!
|
||||||
if !current_user.owns?(dossier)
|
if !current_user.owns?(dossier)
|
||||||
forbidden!
|
forbidden!
|
||||||
|
|
|
@ -67,6 +67,7 @@ class Champ < ApplicationRecord
|
||||||
:stable_id,
|
:stable_id,
|
||||||
:mandatory?,
|
:mandatory?,
|
||||||
:prefillable?,
|
:prefillable?,
|
||||||
|
:refresh_after_update?,
|
||||||
to: :type_de_champ
|
to: :type_de_champ
|
||||||
|
|
||||||
scope :updated_since?, -> (date) { where('champs.updated_at > ?', date) }
|
scope :updated_since?, -> (date) { where('champs.updated_at > ?', date) }
|
||||||
|
|
|
@ -469,6 +469,14 @@ class TypeDeChamp < ApplicationRecord
|
||||||
model_name: OpenStruct.new(param_key: model_name.param_key))
|
model_name: OpenStruct.new(param_key: model_name.param_key))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def refresh_after_update?
|
||||||
|
self.class.refresh_after_update?(type_champ)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.refresh_after_update?(_type_champ)
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
DEFAULT_EMPTY = ['']
|
DEFAULT_EMPTY = ['']
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
- if @to_shows.present?
|
- if @to_show.present?
|
||||||
= turbo_stream.show_all(@to_shows)
|
= turbo_stream.show_all(@to_show)
|
||||||
- if @to_hides.present?
|
- if @to_hide.present?
|
||||||
= turbo_stream.hide_all(@to_hides)
|
= turbo_stream.hide_all(@to_hide)
|
||||||
|
- @to_update.each do |champ|
|
||||||
|
= fields_for champ.input_name, champ do |form|
|
||||||
|
= turbo_stream.morph champ.input_group_id do
|
||||||
|
= render EditableChamp::EditableChampComponent.new champ:, form:
|
||||||
|
|
Loading…
Reference in a new issue