refactor(user dossier): move ruby logic to controller

This commit is contained in:
simon lehericey 2022-10-11 10:57:14 +02:00 committed by LeSim
parent 32e01b13ef
commit 97529ab6af
2 changed files with 27 additions and 8 deletions

View file

@ -181,7 +181,14 @@ module Users
respond_to do |format|
format.html { render :brouillon }
format.turbo_stream { render(:update, layout: false) }
format.turbo_stream do
@to_shows, @to_hides = @dossier.champs
.filter(&:conditional?)
.partition(&:visible?)
.map { |champs| champs_to_one_selector(champs) }
render(:update, layout: false)
end
end
end
@ -205,7 +212,14 @@ module Users
respond_to do |format|
format.html { render :modifier }
format.turbo_stream { render layout: false }
format.turbo_stream do
@to_shows, @to_hides = @dossier.champs
.filter(&:conditional?)
.partition(&:visible?)
.map { |champs| champs_to_one_selector(champs) }
render layout: false
end
end
end
@ -521,5 +535,12 @@ module Users
# rubocop:enable Lint/BooleanSymbol
end
end
def champs_to_one_selector(champs)
champs
.map(&:input_group_id)
.map { |id| "##{id}" }
.join(',')
end
end
end

View file

@ -1,6 +1,4 @@
- to_shows, to_hides = @dossier.champs.filter(&:conditional?).partition(&:visible?)
- if to_shows.present?
= turbo_stream.show_all(to_shows.map { "##{_1.input_group_id}" }.join(','))
- if to_hides.present?
= turbo_stream.hide_all(to_hides.map { "##{_1.input_group_id}" }.join(','))
- if @to_shows.present?
= turbo_stream.show_all(@to_shows)
- if @to_hides.present?
= turbo_stream.hide_all(@to_hides)