2019-01-30 16:14:15 +01:00
|
|
|
class Champs::RepetitionController < ApplicationController
|
|
|
|
before_action :authenticate_logged_user!
|
|
|
|
|
2022-05-03 16:40:09 +02:00
|
|
|
def add
|
2024-03-14 15:13:13 +01:00
|
|
|
@champ = find_champ
|
2023-11-28 17:33:29 +01:00
|
|
|
row = @champ.add_row(@champ.dossier.revision)
|
|
|
|
@first_champ_id = row.map(&:focusable_input_id).compact.first
|
|
|
|
@row_id = row.first&.row_id
|
2024-03-14 15:13:13 +01:00
|
|
|
@row_number = @champ.row_ids.find_index(@row_id) + 1
|
2019-01-30 16:14:15 +01:00
|
|
|
end
|
2022-05-03 16:40:09 +02:00
|
|
|
|
|
|
|
def remove
|
2024-03-14 15:13:13 +01:00
|
|
|
@champ = find_champ
|
2023-03-31 08:49:21 +02:00
|
|
|
@champ.champs.where(row_id: params[:row_id]).destroy_all
|
|
|
|
@champ.reload
|
2022-05-03 16:40:09 +02:00
|
|
|
@row_id = params[:row_id]
|
|
|
|
end
|
2024-03-14 15:13:13 +01:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def find_champ
|
|
|
|
if params[:champ_id].present?
|
|
|
|
policy_scope(Champ).includes(:champs).find(params[:champ_id])
|
|
|
|
else
|
|
|
|
policy_scope(Champ)
|
|
|
|
.includes(:champs, :type_de_champ)
|
|
|
|
.find_by!(dossier_id: params[:dossier_id], type_de_champ: { stable_id: params[:stable_id] })
|
|
|
|
end
|
|
|
|
end
|
2019-01-30 16:14:15 +01:00
|
|
|
end
|