Merge pull request #2842 from tchak/carto-champ-models

Add carte champ model
This commit is contained in:
gregoirenovel 2018-10-16 13:05:51 +02:00 committed by GitHub
commit 3786a718ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 94 additions and 3 deletions

View file

@ -2,7 +2,8 @@ module TypeDeChampHelper
TOGGLES = { TOGGLES = {
TypeDeChamp.type_champs.fetch(:piece_justificative) => :champ_pj?, TypeDeChamp.type_champs.fetch(:piece_justificative) => :champ_pj?,
TypeDeChamp.type_champs.fetch(:siret) => :champ_siret?, 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 def tdc_options

View 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
View 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

View file

@ -25,11 +25,14 @@ class TypeDeChamp < ApplicationRecord
explication: 'explication', explication: 'explication',
dossier_link: 'dossier_link', dossier_link: 'dossier_link',
piece_justificative: 'piece_justificative', piece_justificative: 'piece_justificative',
siret: 'siret' siret: 'siret',
carte: 'carte'
} }
belongs_to :procedure belongs_to :procedure
store :options, accessors: [:cadastres, :quartiers_prioritaires]
after_initialize :set_dynamic_type after_initialize :set_dynamic_type
attr_reader :dynamic_type attr_reader :dynamic_type

View file

@ -0,0 +1,2 @@
class TypesDeChamp::CarteTypeDeChamp < TypesDeChamp::TypeDeChampBase
end

View file

@ -13,6 +13,8 @@ Flipflop.configure do
title: "Champ SIRET" title: "Champ SIRET"
feature :champ_linked_dropdown, feature :champ_linked_dropdown,
title: "Champ double menu déroulant" title: "Champ double menu déroulant"
feature :champ_carte,
title: "Champ Carte"
end end
feature :web_hook feature :web_hook

View file

@ -0,0 +1,14 @@
class CreateGeoAreas < ActiveRecord::Migration[5.2]
def change
create_table :geo_areas do |t|
t.string :source, index: true
t.jsonb :geometry
t.jsonb :properties
t.references :champ, foreign_key: true, index: true
end
add_column :types_de_champ, :options, :jsonb
end
end

View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2018_10_10_070424) do ActiveRecord::Schema.define(version: 2018_10_10_183331) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -342,6 +342,15 @@ ActiveRecord::Schema.define(version: 2018_10_10_070424) do
t.index ["user_id"], name: "index_france_connect_informations_on_user_id" t.index ["user_id"], name: "index_france_connect_informations_on_user_id"
end end
create_table "geo_areas", force: :cascade do |t|
t.string "source"
t.jsonb "geometry"
t.jsonb "properties"
t.bigint "champ_id"
t.index ["champ_id"], name: "index_geo_areas_on_champ_id"
t.index ["source"], name: "index_geo_areas_on_source"
end
create_table "gestionnaires", id: :serial, force: :cascade do |t| create_table "gestionnaires", id: :serial, force: :cascade do |t|
t.string "email", default: "", null: false t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false t.string "encrypted_password", default: "", null: false
@ -544,6 +553,7 @@ ActiveRecord::Schema.define(version: 2018_10_10_070424) do
t.boolean "private", default: false, null: false t.boolean "private", default: false, null: false
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.jsonb "options"
t.index ["private"], name: "index_types_de_champ_on_private" t.index ["private"], name: "index_types_de_champ_on_private"
end end
@ -608,6 +618,7 @@ ActiveRecord::Schema.define(version: 2018_10_10_070424) do
add_foreign_key "commentaires", "dossiers" add_foreign_key "commentaires", "dossiers"
add_foreign_key "dossiers", "users" add_foreign_key "dossiers", "users"
add_foreign_key "feedbacks", "users" add_foreign_key "feedbacks", "users"
add_foreign_key "geo_areas", "champs"
add_foreign_key "initiated_mails", "procedures" add_foreign_key "initiated_mails", "procedures"
add_foreign_key "procedure_paths", "administrateurs" add_foreign_key "procedure_paths", "administrateurs"
add_foreign_key "procedure_paths", "procedures" add_foreign_key "procedure_paths", "procedures"

View file

@ -84,6 +84,9 @@ FactoryBot.define do
factory :type_de_champ_siret do factory :type_de_champ_siret do
type_champ { TypeDeChamp.type_champs.fetch(:siret) } type_champ { TypeDeChamp.type_champs.fetch(:siret) }
end end
factory :type_de_champ_carte do
type_champ { TypeDeChamp.type_champs.fetch(:carte) }
end
trait :private do trait :private do
private { true } private { true }