refactor(champs): no need to project empty champs for tag
This commit is contained in:
parent
1ded040730
commit
5024b5b549
2 changed files with 10 additions and 5 deletions
|
@ -81,13 +81,18 @@ module DossierChampsConcern
|
||||||
|
|
||||||
def champs_for_export(types_de_champ, row_id = nil)
|
def champs_for_export(types_de_champ, row_id = nil)
|
||||||
types_de_champ.flat_map do |type_de_champ|
|
types_de_champ.flat_map do |type_de_champ|
|
||||||
champ = champ_for_export(type_de_champ, row_id)
|
champ = filled_champ(type_de_champ, row_id)
|
||||||
type_de_champ.libelles_for_export.map do |(libelle, path)|
|
type_de_champ.libelles_for_export.map do |(libelle, path)|
|
||||||
[libelle, TypeDeChamp.champ_value_for_export(type_de_champ.type_champ, champ, path)]
|
[libelle, type_de_champ.champ_value_for_export(champ, path)]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def champ_value_for_tag(type_de_champ, path = :value)
|
||||||
|
champ = filled_champ(type_de_champ, nil)
|
||||||
|
type_de_champ.champ_value_for_tag(champ, path)
|
||||||
|
end
|
||||||
|
|
||||||
def champ_for_update(type_de_champ, row_id, updated_by:)
|
def champ_for_update(type_de_champ, row_id, updated_by:)
|
||||||
champ, attributes = champ_with_attributes_for_update(type_de_champ, row_id, updated_by:)
|
champ, attributes = champ_with_attributes_for_update(type_de_champ, row_id, updated_by:)
|
||||||
champ.assign_attributes(attributes)
|
champ.assign_attributes(attributes)
|
||||||
|
@ -143,7 +148,7 @@ module DossierChampsConcern
|
||||||
@champs_by_public_id ||= champs.sort_by(&:id).index_by(&:public_id)
|
@champs_by_public_id ||= champs.sort_by(&:id).index_by(&:public_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def champ_for_export(type_de_champ, row_id)
|
def filled_champ(type_de_champ, row_id)
|
||||||
champ = champs_by_public_id[type_de_champ.public_id(row_id)]
|
champ = champs_by_public_id[type_de_champ.public_id(row_id)]
|
||||||
if champ.blank? || !champ.visible?
|
if champ.blank? || !champ.visible?
|
||||||
nil
|
nil
|
||||||
|
|
|
@ -15,12 +15,12 @@ class TypesDeChamp::TypeDeChampBase
|
||||||
end
|
end
|
||||||
|
|
||||||
def tags_for_template
|
def tags_for_template
|
||||||
tdc = @type_de_champ
|
type_de_champ = @type_de_champ
|
||||||
paths.map do |path|
|
paths.map do |path|
|
||||||
path.merge(
|
path.merge(
|
||||||
libelle: TagsSubstitutionConcern::TagsParser.normalize(path[:libelle]),
|
libelle: TagsSubstitutionConcern::TagsParser.normalize(path[:libelle]),
|
||||||
id: path[:path] == :value ? "tdc#{stable_id}" : "tdc#{stable_id}/#{path[:path]}",
|
id: path[:path] == :value ? "tdc#{stable_id}" : "tdc#{stable_id}/#{path[:path]}",
|
||||||
lambda: -> (dossier) { dossier.project_champ(tdc, nil).for_tag(path[:path]) }
|
lambda: -> (dossier) { dossier.champ_value_for_tag(type_de_champ, path[:path]) }
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue