feat(champ): expose paths

This commit is contained in:
Paul Chavard 2024-04-02 17:05:44 +02:00
parent 9c26d8486f
commit 38a703034e
40 changed files with 364 additions and 185 deletions

View file

@ -110,8 +110,8 @@ class Champ < ApplicationRecord
value.present? ? value.to_s : '' value.present? ? value.to_s : ''
end end
def for_export def for_export(path = :value)
value.presence path == :value ? value.presence : nil
end end
def for_api def for_api
@ -122,8 +122,8 @@ class Champ < ApplicationRecord
to_s to_s
end end
def for_tag def for_tag(path = :value)
value.present? ? value.to_s : '' path == :value && value.present? ? value.to_s : ''
end end
def main_value_name def main_value_name

View file

@ -42,12 +42,26 @@ class Champs::AddressChamp < Champs::TextChamp
address_label.presence || '' address_label.presence || ''
end end
def for_tag def for_tag(path = :value)
address_label case path
when :value
address_label
when :departement
departement_code_and_name || ''
when :commune
commune_name || ''
end
end end
def for_export def for_export(path = :value)
value.present? ? address_label : nil case path
when :value
value.present? ? address_label : nil
when :departement
departement_code_and_name
when :commune
commune_name
end
end end
def for_api def for_api

View file

@ -25,11 +25,11 @@ class Champs::BooleanChamp < Champ
processed_value processed_value
end end
def for_tag def for_tag(path = :value)
processed_value processed_value
end end
def for_export def for_export(path = :value)
processed_value processed_value
end end

View file

@ -79,7 +79,7 @@ class Champs::CarteChamp < Champ
nil nil
end end
def for_export def for_export(path = :value)
geo_areas.map(&:label).join("\n") geo_areas.map(&:label).join("\n")
end end

View file

@ -1,5 +1,5 @@
class Champs::CheckboxChamp < Champs::BooleanChamp class Champs::CheckboxChamp < Champs::BooleanChamp
def for_export def for_export(path = :value)
true? ? 'on' : 'off' true? ? 'on' : 'off'
end end

View file

@ -2,8 +2,26 @@ class Champs::CommuneChamp < Champs::TextChamp
store_accessor :value_json, :code_departement, :code_postal, :code_region store_accessor :value_json, :code_departement, :code_postal, :code_region
before_save :on_codes_change, if: :should_refresh_after_code_change? before_save :on_codes_change, if: :should_refresh_after_code_change?
def for_export def for_export(path = :value)
[to_s, code? ? code : '', departement? ? departement_code_and_name : ''] case path
when :value
to_s
when :departement
departement_code_and_name || ''
when :code
code || ''
end
end
def for_tag(path = :value)
case path
when :value
to_s
when :departement
departement_code_and_name || ''
when :code
code || ''
end
end end
def departement_name def departement_name

View file

@ -12,7 +12,9 @@ class Champs::DateChamp < Champ
value.presence || "" # old dossiers can have not parseable dates value.presence || "" # old dossiers can have not parseable dates
end end
alias for_tag to_s def for_tag(path = :value)
to_s if path == :value
end
private private

View file

@ -10,7 +10,7 @@ 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 def for_tag(path = :value)
value.present? ? I18n.l(Time.zone.parse(value)) : "" value.present? ? I18n.l(Time.zone.parse(value)) : ""
end end

View file

@ -16,7 +16,7 @@ class Champs::DecimalNumberChamp < Champ
} }
}, if: -> { validate_champ_value? || validation_context == :prefill } }, if: -> { validate_champ_value? || validation_context == :prefill }
def for_export def for_export(path = :value)
processed_value processed_value
end end

View file

@ -5,16 +5,26 @@ class Champs::DepartementChamp < Champs::TextChamp
validate :external_id_in_departement_codes, unless: -> { external_id.nil? } validate :external_id_in_departement_codes, unless: -> { external_id.nil? }
before_save :store_code_region before_save :store_code_region
def for_export def for_export(path = :value)
[name, code] case path
when :code
code
when :value
name
end
end end
def to_s def to_s
formatted_value formatted_value
end end
def for_tag def for_tag(path = :value)
formatted_value case path
when :code
code
when :value
formatted_value
end
end end
def for_api def for_api

View file

@ -8,8 +8,26 @@ class Champs::EpciChamp < Champs::TextChamp
validate :external_id_in_departement_epci_codes, unless: -> { code_departement.nil? || external_id.nil? } validate :external_id_in_departement_epci_codes, unless: -> { code_departement.nil? || external_id.nil? }
validate :value_in_departement_epci_names, unless: -> { code_departement.nil? || external_id.nil? || value.nil? } validate :value_in_departement_epci_names, unless: -> { code_departement.nil? || external_id.nil? || value.nil? }
def for_export def for_export(path = :value)
[value, code, "#{code_departement} #{departement_name}"] case path
when :value
value
when :code
code
when :departement
departement_code_and_name
end
end
def for_tag(path = :value)
case path
when :value
value
when :code
code
when :departement
departement_code_and_name
end
end end
def departement_name def departement_name
@ -62,6 +80,12 @@ class Champs::EpciChamp < Champs::TextChamp
end end
end end
def departement_code_and_name
if departement?
"#{code_departement} #{departement_name}"
end
end
def code_departement_input_id def code_departement_input_id
"#{input_id}-code_departement" "#{input_id}-code_departement"
end end

View file

@ -9,7 +9,7 @@ class Champs::IntegerNumberChamp < Champ
} }
}, if: -> { validate_champ_value? || validation_context == :prefill } }, if: -> { validate_champ_value? || validation_context == :prefill }
def for_export def for_export(path = :value)
processed_value processed_value
end end

View file

@ -41,12 +41,26 @@ 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 def for_tag(path = :value)
value.present? ? [primary_value, secondary_value].filter(&:present?).join(' / ') : "" case path
when :primary
primary_value
when :secondary
secondary_value
when :value
value.present? ? [primary_value, secondary_value].filter(&:present?).join(' / ') : ""
end
end end
def for_export def for_export(path = :value)
value.present? ? "#{primary_value || ''};#{secondary_value || ''}" : nil case path
when :primary
primary_value
when :secondary
secondary_value
when :value
value.present? ? "#{primary_value || ''};#{secondary_value || ''}" : nil
end
end end
def for_api def for_api

View file

@ -24,11 +24,11 @@ class Champs::MultipleDropDownListChamp < Champ
selected_options.join(', ') selected_options.join(', ')
end end
def for_tag def for_tag(path = :value)
selected_options.join(', ') selected_options.join(', ')
end end
def for_export def for_export(path = :value)
value.present? ? selected_options.join(', ') : nil value.present? ? selected_options.join(', ') : nil
end end

View file

@ -11,16 +11,26 @@ class Champs::PaysChamp < Champs::TextChamp
validates :value, inclusion: APIGeoService.countries.pluck(:name), allow_nil: false, allow_blank: false validates :value, inclusion: APIGeoService.countries.pluck(:name), allow_nil: false, allow_blank: false
end end
def for_export def for_export(path = :value)
[name, code] case path
when :code
code
when :value
name
end
end end
def to_s def to_s
name name
end end
def for_tag def for_tag(path = :value)
name case path
when :code
code
when :value
name
end
end end
def selected def selected

View file

@ -26,7 +26,7 @@ class Champs::PieceJustificativeChamp < Champ
piece_justificative_file.blank? piece_justificative_file.blank?
end end
def for_export def for_export(path = :value)
piece_justificative_file.map { _1.filename.to_s }.join(', ') piece_justificative_file.map { _1.filename.to_s }.join(', ')
end end

View file

@ -3,8 +3,22 @@ class Champs::RegionChamp < Champs::TextChamp
validate :value_in_region_names, unless: -> { value.nil? } validate :value_in_region_names, unless: -> { value.nil? }
validate :external_id_in_region_codes, unless: -> { external_id.nil? } validate :external_id_in_region_codes, unless: -> { external_id.nil? }
def for_export def for_export(path = :value)
[name, code] case path
when :value
name
when :code
code
end
end
def for_tag(path = :value)
case path
when :value
name
when :code
code
end
end end
def selected def selected

View file

@ -1,6 +1,5 @@
class Champs::RepetitionChamp < Champ class Champs::RepetitionChamp < Champ
accepts_nested_attributes_for :champs accepts_nested_attributes_for :champs
delegate :libelle_for_export, to: :type_de_champ
def rows def rows
dossier dossier
@ -34,7 +33,7 @@ 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 def for_tag(path = :value)
([libelle] + rows.map do |champs| ([libelle] + rows.map do |champs|
champs.map do |champ| champs.map do |champ|
"#{champ.libelle} : #{champ}" "#{champ.libelle} : #{champ}"

View file

@ -16,7 +16,7 @@ class Champs::RNAChamp < Champ
title.present? ? "#{value} (#{title})" : value title.present? ? "#{value} (#{title})" : value
end end
def for_export def for_export(path = :value)
identifier identifier
end end

View file

@ -25,11 +25,33 @@ class Champs::RNFChamp < Champ
rnf_id.blank? rnf_id.blank?
end end
def for_export def for_export(path = :value)
if address.present? case path
[rnf_id, title, address['label'], address['cityCode'], departement_code_and_name] when :value
else rnf_id
[rnf_id, nil, nil, nil, nil] when :departement
departement_code_and_name
when :code_insee
commune&.fetch(:code)
when :address
full_address
when :nom
title
end
end
def for_tag(path = :value)
case path
when :value
rnf_id
when :departement
departement_code_and_name || ''
when :code_insee
commune&.fetch(:code) || ''
when :address
full_address || ''
when :nom
title || ''
end end
end end
@ -59,7 +81,7 @@ class Champs::RNFChamp < Champ
def commune_name def commune_name
if departement? if departement?
"#{APIGeoService.commune_name(department_code, address['cityCode'])} (#{address['postalCode']})" "#{APIGeoService.commune_name(code_departement, address['cityCode'])} (#{address['postalCode']})"
end end
end end
@ -69,8 +91,8 @@ class Champs::RNFChamp < Champ
city_name = address['cityName'] city_name = address['cityName']
postal_code = address['postalCode'] postal_code = address['postalCode']
commune_name = APIGeoService.commune_name(department_code, city_code) commune_name = APIGeoService.commune_name(code_departement, city_code)
commune_code = APIGeoService.commune_code(department_code, city_name) commune_code = APIGeoService.commune_code(code_departement, city_name)
if commune_name.present? if commune_name.present?
{ {

View file

@ -1,5 +1,5 @@
class Champs::TextareaChamp < Champs::TextChamp class Champs::TextareaChamp < Champs::TextChamp
def for_export def for_export(path = :value)
value.present? ? ActionView::Base.full_sanitizer.sanitize(value) : nil value.present? ? ActionView::Base.full_sanitizer.sanitize(value) : nil
end end

View file

@ -20,7 +20,7 @@ class Champs::TitreIdentiteChamp < Champ
piece_justificative_file.blank? piece_justificative_file.blank?
end end
def for_export def for_export(path = :value)
piece_justificative_file.attached? ? "présent" : "absent" piece_justificative_file.attached? ? "présent" : "absent"
end end

View file

@ -451,8 +451,8 @@ module TagsSubstitutionConcern
def tags_and_datas_list(dossier) def tags_and_datas_list(dossier)
[ [
[champ_public_tags(dossier:), dossier.champs_public], [champ_public_tags(dossier:), dossier],
[champ_private_tags(dossier:), dossier.champs_private], [champ_private_tags(dossier:), dossier],
[dossier_tags, dossier], [dossier_tags, dossier],
[ROUTAGE_TAGS, dossier], [ROUTAGE_TAGS, dossier],
[INDIVIDUAL_TAGS, dossier.individual], [INDIVIDUAL_TAGS, dossier.individual],

View file

@ -1047,14 +1047,8 @@ class Dossier < ApplicationRecord
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 = champ_for_export(type_de_champ, row_id)
type_de_champ.libelles_for_export.map do |(libelle, path)|
# nil => [nil] [libelle, champ&.for_export(path)]
# text => [text]
# [commune, insee, departement] => [commune, insee, departement]
wrapped_exported_values = [champ.for_export].flatten
wrapped_exported_values.map.with_index do |champ_value, index|
[type_de_champ.libelle_for_export(index), champ_value]
end end
end end
end end
@ -1184,11 +1178,8 @@ class Dossier < ApplicationRecord
def champ_for_export(type_de_champ, row_id) def champ_for_export(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.nil? || !champ.visible? if champ.blank? || !champ.visible?
# some champs export multiple columns nil
# ex: commune.for_export => [commune, insee, departement]
# so we build a fake champ to have the right export
type_de_champ.build_champ(dossier: self, row_id:)
else else
champ champ
end end

View file

@ -145,7 +145,7 @@ class TypeDeChamp < ApplicationRecord
has_one :revision, through: :revision_type_de_champ has_one :revision, through: :revision_type_de_champ
has_one :procedure, through: :revision has_one :procedure, through: :revision
delegate :estimated_fill_duration, :estimated_read_duration, :tags_for_template, :libelle_for_export, :primary_options, :secondary_options, to: :dynamic_type delegate :estimated_fill_duration, :estimated_read_duration, :tags_for_template, :libelles_for_export, :libelle_for_export, :primary_options, :secondary_options, to: :dynamic_type
delegate :used_by_routing_rules?, to: :revision_type_de_champ delegate :used_by_routing_rules?, to: :revision_type_de_champ
class WithIndifferentAccess class WithIndifferentAccess

View file

@ -1,21 +1,25 @@
class TypesDeChamp::AddressTypeDeChamp < TypesDeChamp::TextTypeDeChamp class TypesDeChamp::AddressTypeDeChamp < TypesDeChamp::TextTypeDeChamp
def tags_for_template def libelles_for_export
tags = super path = paths.first
stable_id = @type_de_champ.stable_id [[path[:libelle], path[:path]]]
tags.push( end
private
def paths
paths = super
paths.push(
{ {
libelle: "#{TagsSubstitutionConcern::TagsParser.normalize(libelle)} (Département)", libelle: "#{libelle} (Département)",
id: "tdc#{stable_id}/departement", path: :departement,
description: "#{description} (Département)", description: "#{description} (Département)"
lambda: -> (champs) { champs.find { _1.stable_id == stable_id }&.departement_code_and_name }
}, },
{ {
libelle: "#{TagsSubstitutionConcern::TagsParser.normalize(libelle)} (Commune)", libelle: "#{libelle} (Commune)",
id: "tdc#{stable_id}/commune", path: :commune,
description: "#{description} (Commune)", description: "#{description} (Commune)"
lambda: -> (champs) { champs.find { _1.stable_id == stable_id }&.commune_name }
} }
) )
tags paths
end end
end end

View file

@ -1,19 +1,20 @@
class TypesDeChamp::CommuneTypeDeChamp < TypesDeChamp::TypeDeChampBase class TypesDeChamp::CommuneTypeDeChamp < TypesDeChamp::TypeDeChampBase
def libelle_for_export(index) private
[libelle, "#{libelle} (Code insee)", "#{libelle} (Département)"][index]
end
def tags_for_template def paths
tags = super paths = super
stable_id = @type_de_champ.stable_id paths.push({
tags.push( libelle: "#{libelle} (Code INSEE)",
{ description: "#{description} (Code INSEE)",
libelle: "#{TagsSubstitutionConcern::TagsParser.normalize(libelle)} (Département)", path: :code,
id: "tdc#{stable_id}/departement", maybe_null: public? && !mandatory?
description: "#{description} (Département)", })
lambda: -> (champs) { champs.find { _1.stable_id == stable_id }&.departement_code_and_name } paths.push({
} libelle: "#{libelle} (Département)",
) description: "#{description} (Département)",
tags path: :departement,
maybe_null: public? && !mandatory?
})
paths
end end
end end

View file

@ -1,9 +1,18 @@
class TypesDeChamp::DepartementTypeDeChamp < TypesDeChamp::TextTypeDeChamp class TypesDeChamp::DepartementTypeDeChamp < TypesDeChamp::TextTypeDeChamp
def libelle_for_export(index)
[libelle, "#{libelle} (Code)"][index]
end
def filter_to_human(filter_value) def filter_to_human(filter_value)
APIGeoService.departement_name(filter_value).presence || filter_value APIGeoService.departement_name(filter_value).presence || filter_value
end end
private
def paths
paths = super
paths.push({
libelle: "#{libelle} (Code)",
description: "#{description} (Code)",
path: :code,
maybe_null: public? && !mandatory?
})
paths
end
end end

View file

@ -1,5 +1,20 @@
class TypesDeChamp::EpciTypeDeChamp < TypesDeChamp::TextTypeDeChamp class TypesDeChamp::EpciTypeDeChamp < TypesDeChamp::TextTypeDeChamp
def libelle_for_export(index) private
[libelle, "#{libelle} (Code)", "#{libelle} (Département)"][index]
def paths
paths = super
paths.push({
libelle: "#{libelle} (Code)",
description: "#{description} (Code)",
path: :code,
maybe_null: public? && !mandatory?
})
paths.push({
libelle: "#{libelle} (Département)",
description: "#{description} (Département)",
path: :departement,
maybe_null: public? && !mandatory?
})
paths
end end
end end

View file

@ -4,30 +4,9 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas
delegate :drop_down_list_options, to: :@type_de_champ delegate :drop_down_list_options, to: :@type_de_champ
validate :check_presence_of_primary_options validate :check_presence_of_primary_options
def tags_for_template def libelles_for_export
tags = super path = paths.first
stable_id = @type_de_champ.stable_id [[path[:libelle], path[:path]]]
tags.push(
{
libelle: "#{TagsSubstitutionConcern::TagsParser.normalize(libelle)}/primaire",
id: "tdc#{stable_id}/primaire",
description: "#{description} (menu primaire)",
lambda: -> (champs) {
champs.find { |champ| champ.stable_id == stable_id }&.primary_value
}
}
)
tags.push(
{
libelle: "#{TagsSubstitutionConcern::TagsParser.normalize(libelle)}/secondaire",
id: "tdc#{stable_id}/secondaire",
description: "#{description} (menu secondaire)",
lambda: -> (champs) {
champs.find { |champ| champ.stable_id == stable_id }&.secondary_value
}
}
)
tags
end end
def add_blank_option_when_not_mandatory(options) def add_blank_option_when_not_mandatory(options)
@ -53,6 +32,23 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas
private private
def paths
paths = super
paths.push({
libelle: "#{libelle}/primaire",
description: "#{description} (Primaire)",
path: :primary,
maybe_null: public? && !mandatory?
})
paths.push({
libelle: "#{libelle}/secondaire",
description: "#{description} (Secondaire)",
path: :secondary,
maybe_null: public? && !mandatory?
})
paths
end
def unpack_options def unpack_options
_, *options = drop_down_list_options _, *options = drop_down_list_options
chunked = options.slice_before(PRIMARY_PATTERN) chunked = options.slice_before(PRIMARY_PATTERN)

View file

@ -1,5 +1,14 @@
class TypesDeChamp::PaysTypeDeChamp < TypesDeChamp::TextTypeDeChamp class TypesDeChamp::PaysTypeDeChamp < TypesDeChamp::TextTypeDeChamp
def libelle_for_export(index) private
[libelle, "#{libelle} (Code)"][index]
def paths
paths = super
paths.push({
libelle: "#{libelle} (Code)",
description: "#{description} (Code)",
path: :code,
maybe_null: public? && !mandatory?
})
paths
end end
end end

View file

@ -1,9 +1,18 @@
class TypesDeChamp::RegionTypeDeChamp < TypesDeChamp::TextTypeDeChamp class TypesDeChamp::RegionTypeDeChamp < TypesDeChamp::TextTypeDeChamp
def libelle_for_export(index)
[libelle, "#{libelle} (Code)"][index]
end
def filter_to_human(filter_value) def filter_to_human(filter_value)
APIGeoService.region_name(filter_value).presence || filter_value APIGeoService.region_name(filter_value).presence || filter_value
end end
private
def paths
paths = super
paths.push({
libelle: "#{libelle} (Code)",
description: "#{description} (Code)",
path: :code,
maybe_null: public? && !mandatory?
})
paths
end
end end

View file

@ -12,7 +12,7 @@ class TypesDeChamp::RepetitionTypeDeChamp < TypesDeChamp::TypeDeChampBase
end end
# We have to truncate the label here as spreadsheets have a (30 char) limit on length. # We have to truncate the label here as spreadsheets have a (30 char) limit on length.
def libelle_for_export(index = 0) def libelle_for_export
str = "(#{stable_id}) #{libelle}" str = "(#{stable_id}) #{libelle}"
# /\*?[] are invalid Excel worksheet characters # /\*?[] are invalid Excel worksheet characters
ActiveStorage::Filename.new(str.delete('[]*?')).sanitized ActiveStorage::Filename.new(str.delete('[]*?')).sanitized

View file

@ -1,25 +1,32 @@
class TypesDeChamp::RNFTypeDeChamp < TypesDeChamp::TextTypeDeChamp class TypesDeChamp::RNFTypeDeChamp < TypesDeChamp::TextTypeDeChamp
def libelle_for_export(index) private
[libelle, "#{libelle} (Nom)", "#{libelle} (Adresse)", "#{libelle} (Code insee Ville)", "#{libelle} (Département)"][index]
end
def tags_for_template def paths
tags = super paths = super
stable_id = @type_de_champ.stable_id paths.push({
tags.push( libelle: "#{libelle} (Nom)",
{ description: "#{description} (Nom)",
libelle: "#{TagsSubstitutionConcern::TagsParser.normalize(libelle)} (Département)", path: :nom,
id: "tdc#{stable_id}/departement", maybe_null: public? && !mandatory?
description: "#{description} (Département)", })
lambda: -> (champs) { champs.find { _1.stable_id == stable_id }&.departement_code_and_name } paths.push({
}, libelle: "#{libelle} (Adresse)",
{ description: "#{description} (Adresse)",
libelle: "#{TagsSubstitutionConcern::TagsParser.normalize(libelle)} (Commune)", path: :address,
id: "tdc#{stable_id}/commune", maybe_null: public? && !mandatory?
description: "#{description} (Commune)", })
lambda: -> (champs) { champs.find { _1.stable_id == stable_id }&.commune_name } paths.push({
} libelle: "#{libelle} (Code INSEE Ville)",
) description: "#{description} (Code INSEE Ville)",
tags path: :code_insee,
maybe_null: public? && !mandatory?
})
paths.push({
libelle: "#{libelle} (Département)",
description: "#{description} (Département)",
path: :departement,
maybe_null: public? && !mandatory?
})
paths
end end
end end

View file

@ -13,22 +13,18 @@ class TypesDeChamp::TypeDeChampBase
end end
def tags_for_template def tags_for_template
stable_id = self.stable_id tdc = @type_de_champ
[ paths.map do |path|
{ path.merge(
libelle: TagsSubstitutionConcern::TagsParser.normalize(libelle), libelle: TagsSubstitutionConcern::TagsParser.normalize(path[:libelle]),
id: "tdc#{stable_id}", id: path[:path] == :value ? "tdc#{stable_id}" : "tdc#{stable_id}/#{path[:path]}",
description: description, lambda: -> (dossier) { dossier.project_champ(tdc, nil).for_tag(path[:path]) }
maybe_null: public? && !mandatory?, )
lambda: -> (champs) { end
champs.find { |champ| champ.stable_id == stable_id }&.for_tag
}
}
]
end end
def libelle_for_export(index = 0) def libelles_for_export
libelle paths.map { [_1[:libelle], _1[:path]] }
end end
# Default estimated duration to fill the champ in a form, in seconds. # Default estimated duration to fill the champ in a form, in seconds.
@ -59,4 +55,17 @@ class TypesDeChamp::TypeDeChampBase
def human_to_filter(human_value) def human_to_filter(human_value)
human_value human_value
end end
private
def paths
[
{
libelle:,
path: :value,
description:,
maybe_null: public? && !mandatory?
}
]
end
end end

View file

@ -12,7 +12,9 @@ describe Champs::CommuneChamp do
expect(champ.code).to eq(code_insee) expect(champ.code).to eq(code_insee)
expect(champ.code_departement).to eq(code_departement) expect(champ.code_departement).to eq(code_departement)
expect(champ.code_postal).to eq(code_postal) expect(champ.code_postal).to eq(code_postal)
expect(champ.for_export).to eq(['Châteldon (63290)', '63102', '63 Puy-de-Dôme']) expect(champ.for_export(:value)).to eq 'Châteldon (63290)'
expect(champ.for_export(:code)).to eq '63102'
expect(champ.for_export(:departement)).to eq '63 Puy-de-Dôme'
expect(champ.communes.size).to eq(8) expect(champ.communes.size).to eq(8)
end end
end end

View file

@ -86,7 +86,11 @@ describe Champs::RNFChamp, type: :model do
describe 'for_export' do describe 'for_export' do
let(:champ) { build(:champ_rnf, external_id:, data: JSON.parse(body)) } let(:champ) { build(:champ_rnf, external_id:, data: JSON.parse(body)) }
it do it do
expect(champ.for_export).to eq(['075-FDD-00003-01', 'Fondation SFR', '16 Rue du Général de Boissieu 75015 Paris', '75115', '75 Paris']) expect(champ.for_export(:value)).to eq '075-FDD-00003-01'
expect(champ.for_export(:nom)).to eq 'Fondation SFR'
expect(champ.for_export(:address)).to eq '16 Rue du Général de Boissieu 75015 Paris'
expect(champ.for_export(:code_insee)).to eq '75115'
expect(champ.for_export(:departement)).to eq '75 Paris'
end end
end end
end end

View file

@ -1907,7 +1907,6 @@ describe Dossier, type: :model do
let(:dossier_second_revision) { create(:dossier, procedure: procedure) } let(:dossier_second_revision) { create(:dossier, procedure: procedure) }
let(:dossier_champs_for_export) { dossier.champs_for_export(procedure.types_de_champ_for_procedure_presentation.not_repetition) } let(:dossier_champs_for_export) { dossier.champs_for_export(procedure.types_de_champ_for_procedure_presentation.not_repetition) }
let(:dossier_second_revision_champs_for_export) { dossier_second_revision.champs_for_export(procedure.types_de_champ_for_procedure_presentation.not_repetition) } let(:dossier_second_revision_champs_for_export) { dossier_second_revision.champs_for_export(procedure.types_de_champ_for_procedure_presentation.not_repetition) }
let(:repetition_second_revision_champs_for_export) { dossier.champs_for_export(procedure.types_de_champ_for_procedure_presentation.repetition) }
context "when procedure published" do context "when procedure published" do
before do before do
@ -1926,10 +1925,8 @@ describe Dossier, type: :model do
it "should have champs from all revisions" do it "should have champs from all revisions" do
expect(dossier.types_de_champ.map(&:libelle)).to eq([text_type_de_champ.libelle, datetime_type_de_champ.libelle, "Yes/no", explication_type_de_champ.libelle, commune_type_de_champ.libelle, repetition_type_de_champ.libelle]) expect(dossier.types_de_champ.map(&:libelle)).to eq([text_type_de_champ.libelle, datetime_type_de_champ.libelle, "Yes/no", explication_type_de_champ.libelle, commune_type_de_champ.libelle, repetition_type_de_champ.libelle])
expect(dossier_second_revision.types_de_champ.map(&:libelle)).to eq([datetime_type_de_champ.libelle, "Updated yes/no", explication_type_de_champ.libelle, 'Commune de naissance', "Repetition", "New text field"]) expect(dossier_second_revision.types_de_champ.map(&:libelle)).to eq([datetime_type_de_champ.libelle, "Updated yes/no", explication_type_de_champ.libelle, 'Commune de naissance', "Repetition", "New text field"])
expect(dossier_champs_for_export.map { |(libelle)| libelle }).to eq([datetime_type_de_champ.libelle, text_type_de_champ.libelle, "Updated yes/no", "Commune de naissance", "Commune de naissance (Code insee)", "Commune de naissance (Département)", "New text field"]) expect(dossier_champs_for_export.map { |(libelle)| libelle }).to eq([datetime_type_de_champ.libelle, text_type_de_champ.libelle, "Updated yes/no", "Commune de naissance", "Commune de naissance (Code INSEE)", "Commune de naissance (Département)", "New text field"])
expect(dossier_champs_for_export).to eq(dossier_second_revision_champs_for_export) expect(dossier_champs_for_export).to eq(dossier_second_revision_champs_for_export)
expect(repetition_second_revision_champs_for_export.map { |(libelle)| libelle }).to eq(procedure.types_de_champ_for_procedure_presentation.repetition.map(&:libelle_for_export))
expect(repetition_second_revision_champs_for_export.first.size).to eq(2)
end end
context 'within a repetition having a type de champs commune (multiple values for export)' do context 'within a repetition having a type de champs commune (multiple values for export)' do
@ -1999,9 +1996,9 @@ describe Dossier, type: :model do
[ [
[yes_no_tdc.libelle, "Oui"], [yes_no_tdc.libelle, "Oui"],
[text_tdc.libelle, "text"], [text_tdc.libelle, "text"],
["commune", ''], ["commune", nil],
["commune (Code insee)", ''], ["commune (Code INSEE)", nil],
["commune (Département)", ""] ["commune (Département)", nil]
] ]
end end

View file

@ -1,6 +1,5 @@
describe TypesDeChamp::CommuneTypeDeChamp do describe TypesDeChamp::CommuneTypeDeChamp do
let(:subject) { create(:type_de_champ_communes, libelle: 'Ma commune') } let(:subject) { create(:type_de_champ_communes, libelle: 'Ma commune') }
it { expect(subject.libelle_for_export(0)).to eq('Ma commune') } it { expect(subject.libelles_for_export).to match_array([['Ma commune', :value], ['Ma commune (Code INSEE)', :code], ['Ma commune (Département)', :departement]]) }
it { expect(subject.libelle_for_export(1)).to eq('Ma commune (Code insee)') }
end end

View file

@ -71,7 +71,7 @@ describe ProcedureExportService do
"multiple_drop_down_list", "multiple_drop_down_list",
"linked_drop_down_list", "linked_drop_down_list",
"communes", "communes",
"communes (Code insee)", "communes (Code INSEE)",
"communes (Département)", "communes (Département)",
"departements", "departements",
"departements (Code)", "departements (Code)",
@ -100,7 +100,7 @@ describe ProcedureExportService do
"rnf", "rnf",
"rnf (Nom)", "rnf (Nom)",
"rnf (Adresse)", "rnf (Adresse)",
"rnf (Code insee Ville)", "rnf (Code INSEE Ville)",
"rnf (Département)", "rnf (Département)",
"engagement_juridique" "engagement_juridique"
] ]
@ -206,7 +206,7 @@ describe ProcedureExportService do
"multiple_drop_down_list", "multiple_drop_down_list",
"linked_drop_down_list", "linked_drop_down_list",
"communes", "communes",
"communes (Code insee)", "communes (Code INSEE)",
"communes (Département)", "communes (Département)",
"departements", "departements",
"departements (Code)", "departements (Code)",
@ -235,7 +235,7 @@ describe ProcedureExportService do
"rnf", "rnf",
"rnf (Nom)", "rnf (Nom)",
"rnf (Adresse)", "rnf (Adresse)",
"rnf (Code insee Ville)", "rnf (Code INSEE Ville)",
"rnf (Département)", "rnf (Département)",
"engagement_juridique" "engagement_juridique"
] ]
@ -309,7 +309,7 @@ describe ProcedureExportService do
"multiple_drop_down_list", "multiple_drop_down_list",
"linked_drop_down_list", "linked_drop_down_list",
"communes", "communes",
"communes (Code insee)", "communes (Code INSEE)",
"communes (Département)", "communes (Département)",
"departements", "departements",
"departements (Code)", "departements (Code)",
@ -338,7 +338,7 @@ describe ProcedureExportService do
"rnf", "rnf",
"rnf (Nom)", "rnf (Nom)",
"rnf (Adresse)", "rnf (Adresse)",
"rnf (Code insee Ville)", "rnf (Code INSEE Ville)",
"rnf (Département)", "rnf (Département)",
"engagement_juridique" "engagement_juridique"
] ]
@ -433,7 +433,7 @@ describe ProcedureExportService do
let(:champ_repetition) { dossiers.first.champs_public.find { |champ| champ.type_champ == 'repetition' } } let(:champ_repetition) { dossiers.first.champs_public.find { |champ| champ.type_champ == 'repetition' } }
it 'should have sheets' do it 'should have sheets' do
expect(subject.sheets.map(&:name)).to eq(['Dossiers', 'Etablissements', 'Avis', champ_repetition.libelle_for_export]) expect(subject.sheets.map(&:name)).to eq(['Dossiers', 'Etablissements', 'Avis', champ_repetition.type_de_champ.libelle_for_export])
end end
context 'with cloned procedure' do context 'with cloned procedure' do
@ -489,7 +489,7 @@ describe ProcedureExportService do
let!(:another_champ_repetition) { create(:champ_repetition, type_de_champ: type_de_champ_repetition, dossier: dossier) } let!(:another_champ_repetition) { create(:champ_repetition, type_de_champ: type_de_champ_repetition, dossier: dossier) }
it 'should have sheets' do it 'should have sheets' do
expect(subject.sheets.map(&:name)).to eq(['Dossiers', 'Etablissements', 'Avis', another_champ_repetition.libelle_for_export, champ_repetition.libelle_for_export]) expect(subject.sheets.map(&:name)).to eq(['Dossiers', 'Etablissements', 'Avis', another_champ_repetition.type_de_champ.libelle_for_export, champ_repetition.type_de_champ.libelle_for_export])
end end
end end