Add champ carte endpoint
This commit is contained in:
parent
383a14ff06
commit
99e1a20d98
8 changed files with 128 additions and 1 deletions
|
@ -37,6 +37,10 @@ class ApplicationController < ActionController::Base
|
|||
logged_user.present?
|
||||
end
|
||||
|
||||
def logged_user_ids
|
||||
logged_users.map(&:id)
|
||||
end
|
||||
|
||||
helper_method :logged_in?
|
||||
|
||||
protected
|
||||
|
|
61
app/controllers/champs/carte_controller.rb
Normal file
61
app/controllers/champs/carte_controller.rb
Normal file
|
@ -0,0 +1,61 @@
|
|||
class Champs::CarteController < ApplicationController
|
||||
before_action :authenticate_logged_user!
|
||||
|
||||
def show
|
||||
@selector = ".carte-#{params[:position]}"
|
||||
|
||||
if params[:dossier].key?(:champs_attributes)
|
||||
geo_json = params[:dossier][:champs_attributes][params[:position]][:value]
|
||||
else
|
||||
geo_json = params[:dossier][:champs_private_attributes][params[:position]][:value]
|
||||
end
|
||||
|
||||
if params[:champ_id].present?
|
||||
@champ = Champ
|
||||
.joins(:dossier)
|
||||
.where(dossiers: { user_id: logged_user_ids })
|
||||
.find_by(id: params[:champ_id])
|
||||
else
|
||||
@champ = Champs::CarteChamp.new(type_de_champ: TypeDeChamp.new(
|
||||
type_champ: TypeDeChamp.type_champs.fetch(:carte),
|
||||
options: {
|
||||
quartiers_prioritaires: true,
|
||||
cadastres: true
|
||||
}
|
||||
))
|
||||
end
|
||||
|
||||
geo_areas = []
|
||||
geo_json = JSON.parse(geo_json)
|
||||
|
||||
if geo_json.first == ["error", "TooManyPolygons"]
|
||||
@error = true
|
||||
else
|
||||
if @champ.cadastres?
|
||||
cadastres = ModuleApiCartoService.generate_cadastre(geo_json)
|
||||
geo_areas += cadastres.map do |cadastre|
|
||||
cadastre[:source] = GeoArea.sources.fetch(:cadastre)
|
||||
cadastre
|
||||
end
|
||||
end
|
||||
|
||||
if @champ.quartiers_prioritaires?
|
||||
quartiers_prioritaires = ModuleApiCartoService.generate_qp(geo_json)
|
||||
geo_areas += quartiers_prioritaires.map do |qp|
|
||||
qp[:source] = GeoArea.sources.fetch(:quartier_prioritaire)
|
||||
qp
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@champ.geo_areas = geo_areas.map do |geo_area|
|
||||
GeoArea.new(geo_area)
|
||||
end
|
||||
|
||||
@champ.value = geo_json.to_json
|
||||
|
||||
if @champ.persisted?
|
||||
@champ.save
|
||||
end
|
||||
end
|
||||
end
|
|
@ -34,4 +34,8 @@ class Champs::CarteChamp < Champ
|
|||
{ lon: lon, lat: lat, zoom: zoom }
|
||||
end
|
||||
end
|
||||
|
||||
def zones
|
||||
value.blank? ? [] : JSON.parse(value)
|
||||
end
|
||||
end
|
||||
|
|
5
app/views/champs/carte/show.js.erb
Normal file
5
app/views/champs/carte/show.js.erb
Normal file
|
@ -0,0 +1,5 @@
|
|||
<%= render_to_element("#{@selector} + .geo-areas",
|
||||
partial: 'shared/champs/carte/geo_areas',
|
||||
locals: { champ: @champ, error: @error }) %>
|
||||
|
||||
DS.drawMapData("<%= @selector %>", <%= geo_data(@champ) %>);
|
27
app/views/shared/champs/carte/_geo_areas.html.haml
Normal file
27
app/views/shared/champs/carte/_geo_areas.html.haml
Normal file
|
@ -0,0 +1,27 @@
|
|||
- if champ.quartiers_prioritaires?
|
||||
.areas-title Quartiers prioritaires
|
||||
.areas
|
||||
- if error.present?
|
||||
.error Merci de dessiner une surface plus petite afin de récupérer les quartiers prioritaires.
|
||||
- elsif champ.value.blank?
|
||||
Aucune zone tracée
|
||||
- elsif champ.quartiers_prioritaires.blank?
|
||||
= t('errors.messages.quartiers_prioritaires_empty', count: champ.zones.size)
|
||||
- else
|
||||
%ul
|
||||
- champ.quartiers_prioritaires.each do |qp|
|
||||
%li #{qp.commune} : #{qp.nom}
|
||||
|
||||
- if champ.cadastres?
|
||||
.areas-title Parcelles cadastrales
|
||||
.areas
|
||||
- if error.present?
|
||||
.error Merci de dessiner une surface plus petite afin de récupérer les parcelles cadastrales.
|
||||
- elsif champ.value.blank?
|
||||
Aucune zone tracée
|
||||
- elsif champ.cadastres.blank?
|
||||
= t('errors.messages.cadastres_empty', count: champ.zones.size)
|
||||
- else
|
||||
%ul
|
||||
- champ.cadastres.each do |pc|
|
||||
%li Parcelle n° #{pc.numero} - Feuille #{pc.code_arr} #{pc.section} #{pc.feuille}
|
|
@ -1,5 +1,24 @@
|
|||
{
|
||||
"ignored_warnings": [
|
||||
{
|
||||
"warning_type": "Cross-Site Scripting",
|
||||
"warning_code": 2,
|
||||
"fingerprint": "0d61a1267d264f1e61cc2398a2683703ac60878129dc9515542f246a80ad575b",
|
||||
"check_name": "CrossSiteScripting",
|
||||
"message": "Unescaped model attribute",
|
||||
"file": "app/views/champs/carto/show.js.erb",
|
||||
"line": 5,
|
||||
"link": "https://brakemanscanner.org/docs/warning_types/cross_site_scripting",
|
||||
"code": "geo_data((Champ.joins(:dossier).where(:dossiers => ({ :user_id => logged_user_ids })).find_by(:id => params.permit(:champ_id)) or CartoChamp.new))",
|
||||
"render_path": [{"type":"controller","class":"Champs::CartoController","method":"show","line":48,"file":"app/controllers/champs/carto_controller.rb"}],
|
||||
"location": {
|
||||
"type": "template",
|
||||
"template": "champs/carto/show"
|
||||
},
|
||||
"user_input": "Champ.joins(:dossier).where(:dossiers => ({ :user_id => logged_user_ids }))",
|
||||
"confidence": "Weak",
|
||||
"note": "Not an injection because logged_user_ids have no user input"
|
||||
},
|
||||
{
|
||||
"warning_type": "SQL Injection",
|
||||
"warning_code": 0,
|
||||
|
@ -61,6 +80,6 @@
|
|||
"note": "Not an injection because of `sanitized_column`"
|
||||
}
|
||||
],
|
||||
"updated": "2018-10-11 12:09:03 +0200",
|
||||
"updated": "2018-10-16 11:28:34 +0300",
|
||||
"brakeman_version": "4.3.1"
|
||||
}
|
||||
|
|
|
@ -177,6 +177,12 @@ fr:
|
|||
connexion: "Erreur lors de la connexion à France Connect."
|
||||
extension_white_list_error: "Le format de fichier de la pièce jointe n'est pas valide."
|
||||
procedure_archived: "Cette démarche en ligne a été fermée, il n'est plus possible de déposer de dossier."
|
||||
cadastres_empty:
|
||||
one: "Aucune parcelle cadastrale sur la zone séléctionnée"
|
||||
other: "Aucune parcelle cadastrale sur les zones séléctionnées"
|
||||
quartiers_prioritaires_empty:
|
||||
one: "Aucun quartier prioritaire sur la zone séléctionnée"
|
||||
other: "Aucun quartier prioritaire sur les zones séléctionnées"
|
||||
|
||||
date:
|
||||
abbr_day_names:
|
||||
|
|
|
@ -125,6 +125,7 @@ Rails.application.routes.draw do
|
|||
namespace :champs do
|
||||
get ':position/siret', to: 'siret#show', as: :siret
|
||||
get ':position/dossier_link', to: 'dossier_link#show', as: :dossier_link
|
||||
post ':position/carte', to: 'carte#show', as: :carte
|
||||
end
|
||||
|
||||
namespace :commencer do
|
||||
|
|
Loading…
Reference in a new issue