chore(manager/services): show etablissement adresse & geopoint

This commit is contained in:
Colin Darie 2022-07-25 18:06:53 +02:00
parent 67cbc61e1e
commit 9d59a50cd4
5 changed files with 35 additions and 2 deletions

View file

@ -19,7 +19,9 @@ class ServiceDashboard < Administrate::BaseDashboard
telephone: Field::String,
horaires: Field::String,
adresse: Field::String,
siret: Field::String
siret: Field::String,
etablissement_adresse: Field::String,
etablissement_latlng: GeopointField
}.freeze
# COLLECTION_ATTRIBUTES
@ -46,7 +48,9 @@ class ServiceDashboard < Administrate::BaseDashboard
:telephone,
:horaires,
:adresse,
:siret
:siret,
:etablissement_adresse,
:etablissement_latlng
].freeze
# FORM_ATTRIBUTES

View file

@ -0,0 +1,11 @@
require "administrate/field/base"
class GeopointField < Administrate::Field::Base
def lat
data.first
end
def lng
data.last
end
end

View file

@ -63,6 +63,10 @@ class Service < ApplicationRecord
etablissement_infos.fetch("adresse", nil)
end
def etablissement_latlng
[etablissement_lat, etablissement_lng]
end
private
def enqueue_api_entreprise

View file

@ -0,0 +1,2 @@
- if field.data.present?
= link_to field.data.join(", "), "https://www.geoportail.gouv.fr/carte?c=#{field.lng},#{field.lat}&z=17&permalink=yes", target: '_blank', rel: 'noopener'

View file

@ -136,4 +136,16 @@ describe Service, type: :model do
end
end
end
describe 'etablissement_latlng' do
it 'without coordinates' do
service = build(:service, etablissement_lat: nil, etablissement_lng: nil)
expect(service.etablissement_latlng).to eq([nil, nil])
end
it 'with coordinates' do
service = build(:service)
expect(service.etablissement_latlng).to eq([48.87, 2.34])
end
end
end