Serialize champ repetition for tags

closes #4272
This commit is contained in:
Paul Chavard 2019-09-11 16:04:42 +02:00
parent 1eac6beb51
commit b97cbd3402
9 changed files with 60 additions and 1 deletions

View file

@ -54,6 +54,10 @@ class Champ < ApplicationRecord
value value
end end
def for_tag
value.present? ? value.to_s : ''
end
def main_value_name def main_value_name
:value :value
end end

View file

@ -9,6 +9,10 @@ class Champs::DateChamp < Champ
value.present? ? I18n.l(Date.parse(value)) : "" value.present? ? I18n.l(Date.parse(value)) : ""
end end
def for_tag
value.present? ? I18n.l(Date.parse(value)) : ""
end
private private
def format_before_save def format_before_save

View file

@ -9,6 +9,10 @@ class Champs::DatetimeChamp < Champ
value.present? ? I18n.l(Time.zone.parse(value)) : "" value.present? ? I18n.l(Time.zone.parse(value)) : ""
end end
def for_tag
value.present? ? I18n.l(Time.zone.parse(value)) : ""
end
private private
def format_before_save def format_before_save

View file

@ -33,6 +33,10 @@ class Champs::LinkedDropDownListChamp < Champ
value.present? ? [primary_value, secondary_value].filter(&:present?).join(' / ') : "" value.present? ? [primary_value, secondary_value].filter(&:present?).join(' / ') : ""
end end
def for_tag
value.present? ? [primary_value, secondary_value].filter(&:present?).join(' / ') : ""
end
def for_export def for_export
value.present? ? "#{primary_value || ''};#{secondary_value || ''}" : nil value.present? ? "#{primary_value || ''};#{secondary_value || ''}" : nil
end end

View file

@ -13,6 +13,10 @@ class Champs::MultipleDropDownListChamp < Champ
selected_options.join(', ') selected_options.join(', ')
end end
def for_tag
selected_options.join(', ')
end
def for_export def for_export
value.present? ? selected_options.join(', ') : nil value.present? ? selected_options.join(', ') : nil
end end

View file

@ -19,6 +19,14 @@ class Champs::RepetitionChamp < Champ
# The user cannot enter any information here so it doesnt make much sense to search # The user cannot enter any information here so it doesnt make much sense to search
end end
def for_tag
([libelle] + rows.map do |champs|
champs.map do |champ|
"#{champ.libelle} : #{champ}"
end.join("\n")
end).join("\n\n")
end
def rows_for_export def rows_for_export
rows.each.with_index(1).map do |champs, index| rows.each.with_index(1).map do |champs, index|
Champs::RepetitionChamp::Row.new(index: index, dossier_id: dossier_id.to_s, champs: champs) Champs::RepetitionChamp::Row.new(index: index, dossier_id: dossier_id.to_s, champs: champs)

View file

@ -9,6 +9,10 @@ class Champs::YesNoChamp < Champ
processed_value processed_value
end end
def for_tag
processed_value
end
def for_export def for_export
processed_value processed_value
end end

View file

@ -14,7 +14,7 @@ class TypesDeChamp::TypeDeChampBase
libelle: libelle, libelle: libelle,
description: description, description: description,
lambda: -> (champs) { lambda: -> (champs) {
champs.find { |champ| champ.type_de_champ == tdc } champs.find { |champ| champ.type_de_champ == tdc }&.for_tag
} }
} }
] ]

View file

@ -114,6 +114,33 @@ describe TagsSubstitutionConcern, type: :model do
end end
end end
context 'when the procedure has a type de champ repetition' do
let(:template) { '--Répétition--' }
let(:types_de_champ) do
[
create(:type_de_champ_repetition, libelle: 'Répétition', types_de_champ: [
create(:type_de_champ_text, libelle: 'Nom'),
create(:type_de_champ_text, libelle: 'Prénom')
])
]
end
before do
repetition = dossier.champs
.find { |champ| champ.libelle == 'Répétition' }
repetition.add_row(1)
paul_champs, pierre_champs = repetition.rows
paul_champs.first.update(value: 'Paul')
paul_champs.last.update(value: 'Chavard')
pierre_champs.first.update(value: 'Pierre')
pierre_champs.last.update(value: 'de La Morinerie')
end
it { is_expected.to eq("Répétition\n\nNom : Paul\nPrénom : Chavard\n\nNom : Pierre\nPrénom : de La Morinerie") }
end
context 'when the procedure has a linked drop down menus type de champ' do context 'when the procedure has a linked drop down menus type de champ' do
let(:type_de_champ) do let(:type_de_champ) do
create(:type_de_champ_linked_drop_down_list, libelle: 'libelle') create(:type_de_champ_linked_drop_down_list, libelle: 'libelle')