From b5f721912f02d06712190e2193c9dab73de76fc4 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 3 Aug 2023 11:06:40 +0200 Subject: [PATCH] fix(dossier): removing options from multiselect should update conditions --- app/controllers/champs/options_controller.rb | 8 ++++++-- app/views/champs/options/remove.turbo_stream.haml | 4 +--- .../dossiers/update_annotations.turbo_stream.haml | 9 +-------- .../dossiers/_update_champs.turbo_stream.haml | 15 +++++++++++++++ app/views/users/dossiers/update.turbo_stream.haml | 15 +-------------- 5 files changed, 24 insertions(+), 27 deletions(-) create mode 100644 app/views/shared/dossiers/_update_champs.turbo_stream.haml diff --git a/app/controllers/champs/options_controller.rb b/app/controllers/champs/options_controller.rb index 4f55ce070..9629865a3 100644 --- a/app/controllers/champs/options_controller.rb +++ b/app/controllers/champs/options_controller.rb @@ -1,8 +1,12 @@ class Champs::OptionsController < ApplicationController + include TurboChampsConcern + before_action :authenticate_logged_user! def remove - @champ = policy_scope(Champ).includes(:champs).find(params[:champ_id]) - @champ.remove_option([params[:option]].compact) + champ = policy_scope(Champ).includes(:champs).find(params[:champ_id]) + champ.remove_option([params[:option]].compact) + champs = champ.private? ? champ.dossier.champs_private_all : champ.dossier.champs_public_all + @to_show, @to_hide, @to_update = champs_to_turbo_update({ params[:champ_id] => true }, champs) end end diff --git a/app/views/champs/options/remove.turbo_stream.haml b/app/views/champs/options/remove.turbo_stream.haml index b8c303ff1..679c610de 100644 --- a/app/views/champs/options/remove.turbo_stream.haml +++ b/app/views/champs/options/remove.turbo_stream.haml @@ -1,3 +1 @@ -= fields_for @champ.input_name, @champ do |form| - = turbo_stream.replace @champ.input_group_id do - = render EditableChamp::EditableChampComponent.new champ: @champ, form: += render partial: 'shared/dossiers/update_champs', locals: { to_show: @to_show, to_hide: @to_hide, to_update: @to_update } diff --git a/app/views/instructeurs/dossiers/update_annotations.turbo_stream.haml b/app/views/instructeurs/dossiers/update_annotations.turbo_stream.haml index 83ca04a5d..679c610de 100644 --- a/app/views/instructeurs/dossiers/update_annotations.turbo_stream.haml +++ b/app/views/instructeurs/dossiers/update_annotations.turbo_stream.haml @@ -1,8 +1 @@ -- if @to_show.present? - = turbo_stream.show_all(@to_show) -- if @to_hide.present? - = turbo_stream.hide_all(@to_hide) -- @to_update.each do |champ| - = fields_for champ.input_name, champ do |form| - = turbo_stream.replace champ.input_group_id do - = render EditableChamp::EditableChampComponent.new champ:, form: += render partial: 'shared/dossiers/update_champs', locals: { to_show: @to_show, to_hide: @to_hide, to_update: @to_update } diff --git a/app/views/shared/dossiers/_update_champs.turbo_stream.haml b/app/views/shared/dossiers/_update_champs.turbo_stream.haml new file mode 100644 index 000000000..f3ce3e5f2 --- /dev/null +++ b/app/views/shared/dossiers/_update_champs.turbo_stream.haml @@ -0,0 +1,15 @@ +- if to_show.present? + = turbo_stream.show_all(to_show) +- if to_hide.present? + = turbo_stream.hide_all(to_hide) +- to_update.each do |champ| + = fields_for champ.input_name, champ do |form| + - if champ.refresh_after_update? + = turbo_stream.replace champ.input_group_id do + = render EditableChamp::EditableChampComponent.new champ:, form: + - else + = turbo_stream.update champ.labelledby_id do + = render EditableChamp::ChampLabelContentComponent.new champ:, form: + += turbo_stream.remove_all(".editable-champ .spinner-removable") += turbo_stream.hide_all(".editable-champ .spinner") diff --git a/app/views/users/dossiers/update.turbo_stream.haml b/app/views/users/dossiers/update.turbo_stream.haml index e998f507c..b7c234b23 100644 --- a/app/views/users/dossiers/update.turbo_stream.haml +++ b/app/views/users/dossiers/update.turbo_stream.haml @@ -1,17 +1,4 @@ -- if @to_show.present? - = turbo_stream.show_all(@to_show) -- if @to_hide.present? - = turbo_stream.hide_all(@to_hide) -- @to_update.each do |champ| - = fields_for champ.input_name, champ do |form| - - if champ.refresh_after_update? - = turbo_stream.replace champ.input_group_id do - = render EditableChamp::EditableChampComponent.new champ:, form: - - else - = turbo_stream.update champ.labelledby_id do - = render EditableChamp::ChampLabelContentComponent.new champ:, form: += render partial: 'shared/dossiers/update_champs', locals: { to_show: @to_show, to_hide: @to_hide, to_update: @to_update, dossier: @dossier, annotation: false } -= turbo_stream.remove_all(".editable-champ .spinner-removable"); -= turbo_stream.hide_all(".editable-champ .spinner"); = turbo_stream.replace_all '.dossier-edit-sticky-footer' do = render Dossiers::EditFooterComponent.new(dossier: @dossier, annotation: false)