diff --git a/app/models/concerns/addressable_column_concern.rb b/app/models/concerns/addressable_column_concern.rb index 7fdf75a28..b3a6edf73 100644 --- a/app/models/concerns/addressable_column_concern.rb +++ b/app/models/concerns/addressable_column_concern.rb @@ -4,8 +4,8 @@ module AddressableColumnConcern extend ActiveSupport::Concern included do - def columns(procedure:, displayable: true, prefix: nil) - addressable_columns = [ + def addressable_columns(procedure:, displayable: true, prefix: nil) + [ ["code postal (5 chiffres)", '$.postal_code', :text, []], ["commune", '$.city_name', :text, []], ["département", '$.departement_code', :enum, APIGeoService.departement_options], @@ -22,8 +22,6 @@ module AddressableColumnConcern type: ) end - - super.concat(addressable_columns) end end end diff --git a/app/models/types_de_champ/rna_type_de_champ.rb b/app/models/types_de_champ/rna_type_de_champ.rb index e60c34a89..e6c2ca915 100644 --- a/app/models/types_de_champ/rna_type_de_champ.rb +++ b/app/models/types_de_champ/rna_type_de_champ.rb @@ -10,4 +10,20 @@ class TypesDeChamp::RNATypeDeChamp < TypesDeChamp::TypeDeChampBase def champ_value_for_export(champ, path = :value) champ.identifier end + + def columns(procedure:, displayable: true, prefix: nil) + super + .concat(addressable_columns(procedure:, displayable:, prefix:)) + .concat([ + Columns::JSONPathColumn.new( + procedure_id: procedure.id, + stable_id:, + tdc_type: type_champ, + label: "#{libelle_with_prefix(prefix)} – Titre au répertoire national des associations", + type: :text, + jsonpath: '$.title', + displayable: + ) + ]) + end end diff --git a/app/models/types_de_champ/rnf_type_de_champ.rb b/app/models/types_de_champ/rnf_type_de_champ.rb index aacad9bae..e92989af3 100644 --- a/app/models/types_de_champ/rnf_type_de_champ.rb +++ b/app/models/types_de_champ/rnf_type_de_champ.rb @@ -35,6 +35,22 @@ class TypesDeChamp::RNFTypeDeChamp < TypesDeChamp::TextTypeDeChamp def champ_blank?(champ) = champ.external_id.blank? + def columns(procedure:, displayable: true, prefix: nil) + super + .concat(addressable_columns(procedure:, displayable:, prefix:)) + .concat([ + Columns::JSONPathColumn.new( + procedure_id: procedure.id, + stable_id:, + tdc_type: type_champ, + label: "#{libelle_with_prefix(prefix)} – Titre au répertoire national des fondations ", + type: :text, + jsonpath: '$.title', + displayable: + ) + ]) + end + private def paths diff --git a/app/models/types_de_champ/siret_type_de_champ.rb b/app/models/types_de_champ/siret_type_de_champ.rb index a75a091d2..5786a071f 100644 --- a/app/models/types_de_champ/siret_type_de_champ.rb +++ b/app/models/types_de_champ/siret_type_de_champ.rb @@ -8,4 +8,8 @@ class TypesDeChamp::SiretTypeDeChamp < TypesDeChamp::TypeDeChampBase end def champ_blank_or_invalid?(champ) = Siret.new(siret: champ.value).invalid? + + def columns(procedure:, displayable: true, prefix: nil) + super.concat(addressable_columns(procedure:, displayable:, prefix:)) + end end diff --git a/spec/factories/champ.rb b/spec/factories/champ.rb index 943fc5355..b84c93379 100644 --- a/spec/factories/champ.rb +++ b/spec/factories/champ.rb @@ -170,7 +170,7 @@ FactoryBot.define do factory :champ_do_not_use_rna, class: 'Champs::RNAChamp' do value { 'W173847273' } - value_json { AddressProxy::ADDRESS_PARTS.index_by(&:itself) } + value_json { AddressProxy::ADDRESS_PARTS.index_by(&:itself).merge(title: "LA PRÉVENTION ROUTIERE") } end factory :champ_do_not_use_engagement_juridique, class: 'Champs::EngagementJuridiqueChamp' do @@ -183,7 +183,7 @@ FactoryBot.define do factory :champ_do_not_use_rnf, class: 'Champs::RNFChamp' do value { '075-FDD-00003-01' } external_id { '075-FDD-00003-01' } - value_json { AddressProxy::ADDRESS_PARTS.index_by(&:itself) } + value_json { AddressProxy::ADDRESS_PARTS.index_by(&:itself).merge(title: "Fondation SFR") } end factory :champ_do_not_use_expression_reguliere, class: 'Champs::ExpressionReguliereChamp' do diff --git a/spec/models/columns/champ_column_spec.rb b/spec/models/columns/champ_column_spec.rb index ee5e0615c..a7dfa85bc 100644 --- a/spec/models/columns/champ_column_spec.rb +++ b/spec/models/columns/champ_column_spec.rb @@ -41,6 +41,8 @@ describe Columns::ChampColumn do expect_type_de_champ_values('mesri', eq([nil])) expect_type_de_champ_values('cojo', eq([nil])) expect_type_de_champ_values('expression_reguliere', eq([nil])) + expect_type_de_champ_values('rna', eq(["W173847273", "postal_code", "city_name", "departement_code", "region_name", "LA PRÉVENTION ROUTIERE"])) + expect_type_de_champ_values('rnf', eq(["075-FDD-00003-01", "postal_code", "city_name", "departement_code", "region_name", "Fondation SFR"])) end end