feat(champ.rnf/rna/siret): render normalized address the same way
This commit is contained in:
parent
8cdd7ef4df
commit
fdff699d51
12 changed files with 103 additions and 39 deletions
55
app/models/address_proxy.rb
Normal file
55
app/models/address_proxy.rb
Normal file
|
@ -0,0 +1,55 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddressProxy
|
||||
ADDRESS_PARTS = [
|
||||
:street_address,
|
||||
:city_name,
|
||||
:postal_code,
|
||||
:city_code,
|
||||
:departement_name,
|
||||
:departement_code,
|
||||
:region_name,
|
||||
:region_code
|
||||
]
|
||||
|
||||
class ChampAddressPresenter
|
||||
ADDRESS_PARTS.each do |address_part|
|
||||
define_method(address_part) do
|
||||
@data[address_part]
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(champ)
|
||||
@data = champ.value_json.with_indifferent_access
|
||||
end
|
||||
end
|
||||
|
||||
class EtablissementAddressPresenter
|
||||
attr_reader(*ADDRESS_PARTS)
|
||||
|
||||
def initialize(etablissement)
|
||||
@street_address = [etablissement.numero_voie, etablissement.type_voie, etablissement.nom_voie].compact.join(" ")
|
||||
@city_name = etablissement.localite
|
||||
@postal_code = etablissement.code_postal
|
||||
@city_code = etablissement.code_insee_localite
|
||||
@departement_name = APIGeoService.departement_name_by_postal_code(@postal_code)
|
||||
@departement_code = APIGeoService.departement_code(@departement_name)
|
||||
@region_code = APIGeoService.region_code_by_departement(@departement_code)
|
||||
@region_name = APIGeoService.region_name(@region_code)
|
||||
end
|
||||
end
|
||||
|
||||
delegate(*ADDRESS_PARTS, to: :@presenter)
|
||||
|
||||
def initialize(champs_or_etablissement)
|
||||
@presenter = make(champ_or_etablissement)
|
||||
end
|
||||
|
||||
def make(champ_or_etablissement)
|
||||
case champ_or_etablissement
|
||||
when Champ then ChampAddressPresenter.new(champ_or_etablissement)
|
||||
when Etablissement then EtablissementAddressPresenter.new(champ_or_etablissement)
|
||||
else raise NotImplementedError("Unsupported address from #{champ_or_etablissement.class.name}")
|
||||
end
|
||||
end
|
||||
end
|
|
@ -47,6 +47,10 @@ class APIGeoService
|
|||
departements.find { _1[:code] == code }&.dig(:name)
|
||||
end
|
||||
|
||||
def departement_name_by_postal_code(postal_code)
|
||||
APIGeoService.departement_name(postal_code[0..2]) || APIGeoService.departement_name(postal_code[0..1])
|
||||
end
|
||||
|
||||
def departement_code(name)
|
||||
return if name.nil?
|
||||
departements.find { _1[:name] == name }&.dig(:code)
|
||||
|
|
|
@ -22,13 +22,4 @@
|
|||
- c.with_value do
|
||||
%p= l(champ.data[scope].to_date)
|
||||
|
||||
- if champ.data['address'].present?
|
||||
= render Dossiers::RowShowComponent.new(label: t("activemodel.attributes.rna_champ.data.address")) do |c|
|
||||
- c.with_value do
|
||||
%p= champ.full_address
|
||||
|
||||
- ['code_insee', 'code_postal'].each do |scope|
|
||||
- if champ.data['address'][scope].present?
|
||||
= render Dossiers::RowShowComponent.new(label: t("activemodel.attributes.rna_champ.data.#{scope}")) do |c|
|
||||
- c.with_value do
|
||||
%p= champ.data['address'][scope]
|
||||
= render partial: "shared/dossiers/normalized_address", locals: { address: AddressProxy.new(champ) }
|
||||
|
|
|
@ -19,12 +19,4 @@
|
|||
= render Dossiers::RowShowComponent.new(label: t("activemodel.attributes.rnf_champ.data.#{scope}")) do |c|
|
||||
- c.with_value do
|
||||
%p= l(champ.data[scope].to_date)
|
||||
|
||||
- if champ.data['address'].present?
|
||||
- ['label', 'cityCode', 'postalCode'].each do |scope|
|
||||
= render Dossiers::RowShowComponent.new(label: t("activemodel.attributes.rnf_champ.data.#{scope}")) do |c|
|
||||
- c.with_value do
|
||||
%p= champ.data['address'][scope]
|
||||
= render Dossiers::RowShowComponent.new(label: t("activemodel.attributes.rnf_champ.data.department")) do |c|
|
||||
- c.with_value do
|
||||
%p= "#{champ.data['address']['departmentCode']} – #{champ.data['address']['departmentName']}"
|
||||
= render partial: "shared/dossiers/normalized_address", locals: { address: AddressProxy.new(champ) }
|
||||
|
|
|
@ -73,12 +73,7 @@
|
|||
- c.with_value do
|
||||
%p= etablissement.entreprise.numero_tva_intracommunautaire
|
||||
|
||||
= render Dossiers::RowShowComponent.new(label: "Adresse") do |c|
|
||||
- c.with_value do
|
||||
%p
|
||||
- etablissement.adresse.split("\n").compact_blank.each do |line|
|
||||
= line
|
||||
%br
|
||||
= render partial: "shared/dossiers/normalized_address", locals: { address: AddressProxy.new(etablissement)}
|
||||
|
||||
= render Dossiers::RowShowComponent.new(label: "Capital social") do |c|
|
||||
- c.with_value do
|
||||
|
|
23
app/views/shared/dossiers/_normalized_address.html.haml
Normal file
23
app/views/shared/dossiers/_normalized_address.html.haml
Normal file
|
@ -0,0 +1,23 @@
|
|||
= render Dossiers::RowShowComponent.new(label: t("activemodel.attributes.normalized_address.full_address")) do |c|
|
||||
- c.with_value do
|
||||
%p
|
||||
= address.street_address
|
||||
%br
|
||||
= [address.city_name, address.postal_code].join(" ")
|
||||
|
||||
|
||||
- ['city_code', 'postal_code'].each do |scope|
|
||||
- if address.public_send(scope).present?
|
||||
= render Dossiers::RowShowComponent.new(label: t("activemodel.attributes.normalized_address.#{scope}")) do |c|
|
||||
- c.with_value do
|
||||
%p= address.public_send(scope)
|
||||
|
||||
- if address.departement_name.present?
|
||||
= render Dossiers::RowShowComponent.new(label: t("activemodel.attributes.normalized_address.department")) do |c|
|
||||
- c.with_value do
|
||||
%p= "#{address.departement_name} – #{address.departement_code}"
|
||||
|
||||
- if address.region_name.present?
|
||||
= render Dossiers::RowShowComponent.new(label: t("activemodel.attributes.normalized_address.region")) do |c|
|
||||
- c.with_value do
|
||||
%p= "#{address.region_name} – #{address.region_code}"
|
9
config/locales/models/champs/normalized_address/en.yml
Normal file
9
config/locales/models/champs/normalized_address/en.yml
Normal file
|
@ -0,0 +1,9 @@
|
|||
en:
|
||||
activemodel:
|
||||
attributes:
|
||||
normalized_address:
|
||||
full_address: Address
|
||||
city_code: INSEE code
|
||||
postal_code: Postal code
|
||||
department: Department
|
||||
region: Region & region code
|
9
config/locales/models/champs/normalized_address/fr.yml
Normal file
9
config/locales/models/champs/normalized_address/fr.yml
Normal file
|
@ -0,0 +1,9 @@
|
|||
fr:
|
||||
activemodel:
|
||||
attributes:
|
||||
normalized_address:
|
||||
full_address: Adresse
|
||||
city_code: Code INSEE
|
||||
postal_code: Code postal
|
||||
department: Département
|
||||
region: Région & code région
|
|
@ -9,9 +9,6 @@ en:
|
|||
association_date_creation: Creation date
|
||||
association_date_declaration: Declaration date
|
||||
association_date_publication: Publication date
|
||||
address: Address
|
||||
code_insee: INSEE code
|
||||
code_postal: Postal code
|
||||
paste: Copy the RNA to the clipboard
|
||||
paste_success: The RNA has been copied to the clipboard
|
||||
activerecord:
|
||||
|
|
|
@ -9,9 +9,6 @@ fr:
|
|||
association_date_creation: Date de création
|
||||
association_date_declaration: Date de déclaration
|
||||
association_date_publication: Date de publication
|
||||
address: Adresse
|
||||
code_insee: Code INSEE
|
||||
code_postal: Code postal
|
||||
paste: Copier le RNA dans le presse-papier
|
||||
paste_success: Le RNA a été copié dans le presse-papier
|
||||
activerecord:
|
||||
|
|
|
@ -12,10 +12,6 @@ en:
|
|||
dissolvedAt: Dissolved at
|
||||
address: Address
|
||||
status: Status
|
||||
cityCode: City code
|
||||
postalCode: Postal code
|
||||
department: Department
|
||||
label: Address
|
||||
paste: Copy the RNF to the clipboard
|
||||
paste_success: The RNF has been copied to the clipboard
|
||||
activerecord:
|
||||
|
|
|
@ -12,10 +12,6 @@ fr:
|
|||
dissolvedAt: Dissoute le
|
||||
address: Adresse
|
||||
status: Statut
|
||||
cityCode: Code INSEE
|
||||
postalCode: Code postal
|
||||
department: Département
|
||||
label: Adresse
|
||||
paste: Copier le RNF dans le presse-papier
|
||||
paste_success: Le RNF a été copié dans le presse-papier
|
||||
activerecord:
|
||||
|
|
Loading…
Reference in a new issue