feat(dossier): add repetition champs to champs_for_condition

This commit is contained in:
Paul Chavard 2022-12-01 17:56:14 +01:00
parent febffc2d64
commit 6ce7064ffd
3 changed files with 4 additions and 1 deletions

View file

@ -237,7 +237,7 @@ class Champ < ApplicationRecord
private
def champs_for_condition
private? ? dossier.champs_private : dossier.champs_public
dossier.champs.filter { _1.row.nil? || _1.row == row }
end
def html_id

View file

@ -78,6 +78,7 @@ class Dossier < ApplicationRecord
has_one_attached :justificatif_motivation
has_many :champs
has_many :champs_public, -> { root.public_ordered }, class_name: 'Champ', inverse_of: false, dependent: :destroy
has_many :champs_private, -> { root.private_ordered }, class_name: 'Champ', inverse_of: false, dependent: :destroy
has_many :commentaires, inverse_of: :dossier, dependent: :destroy

View file

@ -78,6 +78,7 @@ class DossierPreloader
def load_dossier(dossier, champs, children_by_parent = {})
champs_public, champs_private = champs.partition(&:public?)
dossier.association(:champs).target = []
load_champs(dossier, :champs_public, champs_public, dossier, children_by_parent)
load_champs(dossier, :champs_private, champs_private, dossier, children_by_parent)
@ -97,6 +98,7 @@ class DossierPreloader
champ.association(:parent).target = parent
end
end
dossier.association(:champs).target += champs
parent.association(name).target = champs.sort_by do |champ|
[champ.row, positions[dossier.revision_id][champ.type_de_champ_id]]