2024-10-25 10:27:46 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Instructeurs
|
|
|
|
class ProcedurePresentationController < InstructeurController
|
2024-10-26 21:12:39 +02:00
|
|
|
before_action :set_procedure_presentation, only: [:update]
|
2024-10-25 10:27:46 +02:00
|
|
|
|
|
|
|
def update
|
|
|
|
if !@procedure_presentation.update(procedure_presentation_params)
|
|
|
|
# complicated way to display inner error messages
|
|
|
|
flash.alert = @procedure_presentation.errors
|
|
|
|
.flat_map { _1.detail[:value].flat_map { |c| c.errors.full_messages } }
|
|
|
|
end
|
|
|
|
|
|
|
|
redirect_back_or_to([:instructeur, procedure])
|
|
|
|
end
|
|
|
|
|
2024-10-25 13:51:12 +02:00
|
|
|
def refresh_column_filter
|
2024-10-26 21:12:39 +02:00
|
|
|
# According to the html, the selected filters is the last one
|
|
|
|
column = ColumnType.new.cast(params['filters'].last['id'])
|
|
|
|
component = Instructeurs::ColumnFilterValueComponent.new(column:)
|
2024-10-25 13:51:12 +02:00
|
|
|
|
2024-10-25 17:30:20 +02:00
|
|
|
render turbo_stream: turbo_stream.replace('value', component)
|
2024-10-25 13:51:12 +02:00
|
|
|
end
|
|
|
|
|
2024-10-25 10:27:46 +02:00
|
|
|
private
|
|
|
|
|
|
|
|
def procedure = @procedure_presentation.procedure
|
|
|
|
|
|
|
|
def procedure_presentation_params
|
2024-10-26 21:12:39 +02:00
|
|
|
h = params.permit(displayed_columns: [], sorted_column: [:order, :id], filters: [:id, :filter]).to_h
|
2024-10-25 17:30:20 +02:00
|
|
|
|
2024-10-26 21:12:39 +02:00
|
|
|
if params[:statut].present?
|
|
|
|
filter_name = @procedure_presentation.filters_name_for(params[:statut])
|
|
|
|
h[filter_name] = h.delete("filters") # move filters to the right key, ex: tous_filters
|
|
|
|
end
|
2024-10-25 10:27:46 +02:00
|
|
|
|
|
|
|
# React ComboBox/MultiComboBox return [''] when no value is selected
|
|
|
|
# We need to remove them
|
|
|
|
if h[:displayed_columns].present?
|
|
|
|
h[:displayed_columns] = h[:displayed_columns].reject(&:empty?)
|
|
|
|
end
|
|
|
|
|
|
|
|
h
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_procedure_presentation
|
|
|
|
@procedure_presentation = ProcedurePresentation
|
|
|
|
.includes(:assign_to)
|
|
|
|
.find_by!(id: params[:id], assign_to: { instructeur: current_instructeur })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|