From d421d41e16efb61fe8f6cbafc461a8abe7fd83b9 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Fri, 25 Oct 2024 13:51:12 +0200 Subject: [PATCH] plug refresh_column_filter to dedicated controller --- .../column_filter_component.html.haml | 3 ++- .../procedure_presentation_controller.rb | 13 +++++++++++++ config/routes.rb | 6 +++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/components/instructeurs/column_filter_component/column_filter_component.html.haml b/app/components/instructeurs/column_filter_component/column_filter_component.html.haml index eaf9e8902..f30f700e0 100644 --- a/app/components/instructeurs/column_filter_component/column_filter_component.html.haml +++ b/app/components/instructeurs/column_filter_component/column_filter_component.html.haml @@ -8,7 +8,8 @@ %input.hidden{ type: 'submit', - formaction: update_filter_instructeur_procedure_path(procedure), + formmethod: 'get', + formaction: url_for([:refresh_column_filter, :instructeur, @procedure_presentation]), formnovalidate: 'true', data: { autosubmit_target: 'submitter' } } diff --git a/app/controllers/instructeurs/procedure_presentation_controller.rb b/app/controllers/instructeurs/procedure_presentation_controller.rb index 56c9e4af1..1ce51e9e8 100644 --- a/app/controllers/instructeurs/procedure_presentation_controller.rb +++ b/app/controllers/instructeurs/procedure_presentation_controller.rb @@ -14,6 +14,19 @@ module Instructeurs redirect_back_or_to([:instructeur, procedure]) end + def refresh_column_filter + procedure_presentation = @procedure_presentation + statut = params[:statut] + current_filter = procedure_presentation.filters_name_for(statut) + # According to the html, the selected column is the last one + h_id = JSON.parse(params[current_filter].last[:id], symbolize_names: true) + column = procedure.find_column(h_id:) + + filter_component = Instructeurs::ColumnFilterComponent.new(procedure:, procedure_presentation:, statut:, column:) + + render turbo_stream: turbo_stream.replace('filter-component', filter_component) + end + private def procedure = @procedure_presentation.procedure diff --git a/config/routes.rb b/config/routes.rb index 2ab0614e4..b44d09de6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -461,7 +461,11 @@ Rails.application.routes.draw do end end - resources :procedure_presentation, only: [:update] + resources :procedure_presentation, only: [:update] do + member do + get 'refresh_column_filter' + end + end resources :procedures, only: [:index, :show], param: :procedure_id do member do