plug refresh_column_filter to dedicated controller

This commit is contained in:
simon lehericey 2024-10-25 13:51:12 +02:00
parent 7ed0b91351
commit d421d41e16
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
3 changed files with 20 additions and 2 deletions

View file

@ -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' }
}

View file

@ -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

View file

@ -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