Add carte champ and geo area models
This commit is contained in:
parent
202e055b7b
commit
93ba94a9e6
7 changed files with 68 additions and 2 deletions
|
@ -2,7 +2,8 @@ module TypeDeChampHelper
|
|||
TOGGLES = {
|
||||
TypeDeChamp.type_champs.fetch(:piece_justificative) => :champ_pj?,
|
||||
TypeDeChamp.type_champs.fetch(:siret) => :champ_siret?,
|
||||
TypeDeChamp.type_champs.fetch(:linked_drop_down_list) => :champ_linked_dropdown?
|
||||
TypeDeChamp.type_champs.fetch(:linked_drop_down_list) => :champ_linked_dropdown?,
|
||||
TypeDeChamp.type_champs.fetch(:carte) => :champ_carte?
|
||||
}
|
||||
|
||||
def tdc_options
|
||||
|
|
29
app/models/champs/carte_champ.rb
Normal file
29
app/models/champs/carte_champ.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
class Champs::CarteChamp < Champ
|
||||
has_many :geo_areas, dependent: :destroy
|
||||
|
||||
# We are not using scopes here as we want to access
|
||||
# the following collections on unsaved records.
|
||||
def cadastres
|
||||
geo_areas.select do |area|
|
||||
area.source == GeoArea.sources.fetch(:cadastre)
|
||||
end
|
||||
end
|
||||
|
||||
def quartiers_prioritaires
|
||||
geo_areas.select do |area|
|
||||
area.source == GeoArea.sources.fetch(:quartier_prioritaire)
|
||||
end
|
||||
end
|
||||
|
||||
def position
|
||||
if dossier.present?
|
||||
dossier.geo_position
|
||||
else
|
||||
lon = "2.428462"
|
||||
lat = "46.538192"
|
||||
zoom = "13"
|
||||
|
||||
{ lon: lon, lat: lat, zoom: zoom }
|
||||
end
|
||||
end
|
||||
end
|
26
app/models/geo_area.rb
Normal file
26
app/models/geo_area.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
class GeoArea < ApplicationRecord
|
||||
belongs_to :champ
|
||||
|
||||
store :properties, accessors: [
|
||||
:surface_intersection,
|
||||
:surface_parcelle,
|
||||
:numero,
|
||||
:feuille,
|
||||
:section,
|
||||
:code_dep,
|
||||
:nom_com,
|
||||
:code_com,
|
||||
:code_arr,
|
||||
:code,
|
||||
:nom,
|
||||
:commune
|
||||
]
|
||||
|
||||
enum source: {
|
||||
quartier_prioritaire: 'quartier_prioritaire',
|
||||
cadastre: 'cadastre'
|
||||
}
|
||||
|
||||
scope :quartiers_prioritaires, -> { where(source: sources.fetch(:quartier_prioritaire)) }
|
||||
scope :cadastres, -> { where(source: sources.fetch(:cadastre)) }
|
||||
end
|
|
@ -25,11 +25,14 @@ class TypeDeChamp < ApplicationRecord
|
|||
explication: 'explication',
|
||||
dossier_link: 'dossier_link',
|
||||
piece_justificative: 'piece_justificative',
|
||||
siret: 'siret'
|
||||
siret: 'siret',
|
||||
carte: 'carte'
|
||||
}
|
||||
|
||||
belongs_to :procedure
|
||||
|
||||
store :options, accessors: [:cadastres, :quartiers_prioritaires]
|
||||
|
||||
after_initialize :set_dynamic_type
|
||||
|
||||
attr_reader :dynamic_type
|
||||
|
|
2
app/models/types_de_champ/carte_type_de_champ.rb
Normal file
2
app/models/types_de_champ/carte_type_de_champ.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
class TypesDeChamp::CarteTypeDeChamp < TypesDeChamp::TypeDeChampBase
|
||||
end
|
|
@ -13,6 +13,8 @@ Flipflop.configure do
|
|||
title: "Champ SIRET"
|
||||
feature :champ_linked_dropdown,
|
||||
title: "Champ double menu déroulant"
|
||||
feature :champ_carte,
|
||||
title: "Champ Carte"
|
||||
end
|
||||
|
||||
feature :web_hook
|
||||
|
|
|
@ -84,6 +84,9 @@ FactoryBot.define do
|
|||
factory :type_de_champ_siret do
|
||||
type_champ { TypeDeChamp.type_champs.fetch(:siret) }
|
||||
end
|
||||
factory :type_de_champ_carte do
|
||||
type_champ { TypeDeChamp.type_champs.fetch(:carte) }
|
||||
end
|
||||
|
||||
trait :private do
|
||||
private { true }
|
||||
|
|
Loading…
Reference in a new issue