2015-10-09 14:43:19 +02:00
|
|
|
class Users::CarteController < UsersController
|
2015-08-12 14:02:40 +02:00
|
|
|
include DossierConcern
|
|
|
|
|
2016-01-25 15:54:21 +01:00
|
|
|
before_action :authorized_routes?, only: [:show]
|
|
|
|
|
2015-08-10 11:05:06 +02:00
|
|
|
def show
|
2015-10-09 17:33:33 +02:00
|
|
|
@dossier = current_user_dossier
|
2015-12-08 11:18:49 +01:00
|
|
|
|
2015-08-18 10:43:22 +02:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
2015-10-09 17:33:33 +02:00
|
|
|
flash.alert = t('errors.messages.dossier_not_found')
|
2015-10-26 18:08:41 +01:00
|
|
|
redirect_to url_for(root_path)
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
|
2015-11-25 17:05:14 +01:00
|
|
|
def save
|
2015-10-09 17:33:33 +02:00
|
|
|
dossier = current_user_dossier
|
2015-11-25 17:05:14 +01:00
|
|
|
|
2015-11-30 17:03:36 +01:00
|
|
|
dossier.quartier_prioritaires.map(&:destroy)
|
2016-01-18 12:03:18 +01:00
|
|
|
dossier.cadastres.map(&:destroy)
|
2015-11-25 17:05:14 +01:00
|
|
|
|
2015-11-30 17:03:36 +01:00
|
|
|
unless params[:json_latlngs].blank?
|
2016-01-18 12:03:18 +01:00
|
|
|
if dossier.procedure.module_api_carto.quartiers_prioritaires?
|
|
|
|
qp_list = generate_qp JSON.parse(params[:json_latlngs])
|
|
|
|
|
|
|
|
qp_list.each do |key, qp|
|
|
|
|
qp.merge!({dossier_id: dossier.id})
|
|
|
|
qp[:geometry] = qp[:geometry].to_json
|
|
|
|
QuartierPrioritaire.create(qp)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if dossier.procedure.module_api_carto.cadastre?
|
|
|
|
cadastre_list = generate_cadastre JSON.parse(params[:json_latlngs])
|
2015-11-25 17:05:14 +01:00
|
|
|
|
2016-01-18 12:03:18 +01:00
|
|
|
cadastre_list.each do |cadastre|
|
|
|
|
cadastre.merge!({dossier_id: dossier.id})
|
|
|
|
cadastre[:geometry] = cadastre[:geometry].to_json
|
|
|
|
Cadastre.create(cadastre)
|
|
|
|
end
|
2015-11-25 17:05:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-12 17:34:12 +01:00
|
|
|
dossier.update_attributes(json_latlngs: params[:json_latlngs])
|
2015-09-28 18:55:16 +02:00
|
|
|
|
|
|
|
if dossier.draft?
|
2015-08-20 16:34:14 +02:00
|
|
|
redirect_to url_for(controller: :description, action: :show, dossier_id: params[:dossier_id])
|
2015-08-18 10:43:22 +02:00
|
|
|
else
|
|
|
|
commentaire_params = {
|
2015-11-02 18:56:41 +01:00
|
|
|
email: 'Modification localisation',
|
|
|
|
body: 'La localisation de la demande a été modifiée. Merci de le prendre en compte.',
|
|
|
|
dossier_id: dossier.id
|
2015-08-18 10:43:22 +02:00
|
|
|
}
|
2015-11-30 17:03:36 +01:00
|
|
|
Commentaire.create commentaire_params
|
2015-08-20 16:34:14 +02:00
|
|
|
redirect_to url_for(controller: :recapitulatif, action: :show, dossier_id: params[:dossier_id])
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_position
|
2016-01-06 15:48:06 +01:00
|
|
|
tmp_position = Carto::Geocodeur.convert_adresse_to_point(current_user_dossier.etablissement.geo_adresse)
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2015-11-02 18:56:41 +01:00
|
|
|
if !tmp_position.point.nil?
|
|
|
|
render json: {lon: tmp_position.point.x.to_s, lat: tmp_position.point.y.to_s, dossier_id: params[:dossier_id]}
|
|
|
|
else
|
|
|
|
render json: {lon: '0', lat: '0', dossier_id: params[:dossier_id]}
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
end
|
2015-11-25 10:26:55 +01:00
|
|
|
|
|
|
|
def get_qp
|
2015-11-25 17:05:14 +01:00
|
|
|
qp = generate_qp JSON.parse(params[:coordinates])
|
2015-11-25 10:26:55 +01:00
|
|
|
|
|
|
|
render json: {quartier_prioritaires: qp}
|
|
|
|
end
|
|
|
|
|
2016-01-15 11:53:00 +01:00
|
|
|
def get_cadastre
|
|
|
|
cadastres = generate_cadastre JSON.parse(params[:coordinates])
|
|
|
|
|
|
|
|
render json: {cadastres: cadastres}
|
|
|
|
end
|
|
|
|
|
2015-11-25 10:26:55 +01:00
|
|
|
private
|
|
|
|
|
|
|
|
def generate_qp coordinates
|
|
|
|
qp = {}
|
|
|
|
|
|
|
|
coordinates.each_with_index do |coordinate, index|
|
|
|
|
coordinate = coordinates[index].map { |latlng| [latlng['lng'], latlng['lat']] }
|
2015-12-08 16:02:35 +01:00
|
|
|
qp = qp.merge CARTO::SGMAP::QuartiersPrioritaires::Adapter.new(coordinate).to_params
|
2015-11-25 10:26:55 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
qp
|
|
|
|
end
|
2016-01-15 11:53:00 +01:00
|
|
|
|
|
|
|
def generate_cadastre coordinates
|
|
|
|
cadastre = []
|
|
|
|
|
2016-01-18 12:03:18 +01:00
|
|
|
coordinates.each_with_index do |coordinate, index|
|
2016-01-15 11:53:00 +01:00
|
|
|
coordinate = coordinates[index].map { |latlng| [latlng['lng'], latlng['lat']] }
|
|
|
|
cadastre << CARTO::SGMAP::Cadastre::Adapter.new(coordinate).to_params
|
|
|
|
end
|
|
|
|
|
|
|
|
cadastre.flatten
|
|
|
|
end
|
2015-08-20 16:34:14 +02:00
|
|
|
end
|