remove use of repetition.types_de_champ (except rebase)

This commit is contained in:
simon lehericey 2022-05-18 14:49:49 +02:00
parent e976336612
commit 8bd3de2050
6 changed files with 14 additions and 11 deletions

View file

@ -3,7 +3,7 @@ class Champs::RepetitionController < ApplicationController
def add
@champ = policy_scope(Champ).includes(:champs).find(params[:champ_id])
@champs = @champ.add_row
@champs = @champ.add_row(@champ.dossier.revision)
end
def remove

View file

@ -27,11 +27,11 @@ class Champs::RepetitionChamp < Champ
champs.group_by(&:row).values
end
def add_row
def add_row(revision)
added_champs = []
transaction do
row = (blank? ? -1 : champs.last.row) + 1
type_de_champ.types_de_champ.each do |type_de_champ|
revision.children_of(type_de_champ).each do |type_de_champ|
added_champs << type_de_champ.champ.build(row: row)
end
self.champs << added_champs

View file

@ -31,11 +31,11 @@ class ProcedureRevision < ApplicationRecord
scope :ordered, -> { order(:created_at) }
def build_champs
types_de_champ_public.map(&:build_champ)
types_de_champ_public.map { |tdc| tdc.build_champ(revision: self) }
end
def build_champs_private
types_de_champ_private.map(&:build_champ)
types_de_champ_private.map { |tdc| tdc.build_champ(revision: self) }
end
def add_type_de_champ(params)

View file

@ -102,10 +102,12 @@ class TypeDeChamp < ApplicationRecord
has_many :champ, inverse_of: :type_de_champ, dependent: :destroy do
def build(params = {})
params.delete(:revision)
super(params.merge(proxy_association.owner.params_for_champ))
end
def create(params = {})
params.delete(:revision)
super(params.merge(proxy_association.owner.params_for_champ))
end
end
@ -153,8 +155,8 @@ class TypeDeChamp < ApplicationRecord
}
end
def build_champ
dynamic_type.build_champ
def build_champ(params)
dynamic_type.build_champ(params)
end
def check_mandatory

View file

@ -1,7 +1,8 @@
class TypesDeChamp::RepetitionTypeDeChamp < TypesDeChamp::TypeDeChampBase
def build_champ
def build_champ(params)
revision = params[:revision]
champ = super
champ.add_row
champ.add_row(revision)
champ
end

View file

@ -25,8 +25,8 @@ class TypesDeChamp::TypeDeChampBase
libelle
end
def build_champ
@type_de_champ.champ.build
def build_champ(params)
@type_de_champ.champ.build(params)
end
def filter_to_human(filter_value)