2015-10-09 14:43:19 +02:00
|
|
|
class Users::CarteController < UsersController
|
2016-01-26 15:52:05 +01:00
|
|
|
before_action only: [:show] do
|
|
|
|
authorized_routes? self.class
|
|
|
|
end
|
2016-01-25 15:54:21 +01:00
|
|
|
|
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
|
|
|
|
2017-04-05 10:00:15 +02:00
|
|
|
dossier.quartier_prioritaires.each(&:destroy)
|
|
|
|
dossier.cadastres.each(&:destroy)
|
2015-11-25 17:05:14 +01:00
|
|
|
|
2015-11-30 17:03:36 +01:00
|
|
|
unless params[:json_latlngs].blank?
|
2016-01-27 15:48:27 +01:00
|
|
|
ModuleApiCartoService.save_qp! dossier, params[:json_latlngs]
|
|
|
|
ModuleApiCartoService.save_cadastre! dossier, params[:json_latlngs]
|
2015-11-25 17:05:14 +01:00
|
|
|
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
|
|
|
|
2016-01-27 15:48:27 +01:00
|
|
|
controller = :recapitulatif
|
|
|
|
controller = :description if dossier.draft?
|
|
|
|
|
|
|
|
redirect_to url_for(controller: controller, action: :show, dossier_id: params[:dossier_id])
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def get_position
|
2017-11-22 16:27:47 +01:00
|
|
|
begin
|
|
|
|
etablissement = current_user_dossier.etablissement
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
etablissement = nil
|
|
|
|
end
|
|
|
|
|
2016-12-20 11:35:16 +01:00
|
|
|
point = Carto::Geocodeur.convert_adresse_to_point(etablissement.geo_adresse) unless etablissement.nil?
|
2016-01-27 15:48:27 +01:00
|
|
|
|
|
|
|
lon = '2.428462'
|
|
|
|
lat = '46.538192'
|
|
|
|
zoom = '13'
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2016-01-27 15:48:27 +01:00
|
|
|
unless point.nil?
|
|
|
|
lon = point.x.to_s
|
|
|
|
lat = point.y.to_s
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
2016-01-27 15:48:27 +01:00
|
|
|
|
|
|
|
render json: {lon: lon, lat: lat, zoom: zoom, dossier_id: params[:dossier_id]}
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
2015-11-25 10:26:55 +01:00
|
|
|
|
|
|
|
def get_qp
|
2016-01-27 15:48:27 +01:00
|
|
|
render json: {quartier_prioritaires: ModuleApiCartoService.generate_qp(JSON.parse(params[:coordinates]))}
|
2015-11-25 10:26:55 +01:00
|
|
|
end
|
|
|
|
|
2016-01-15 11:53:00 +01:00
|
|
|
def get_cadastre
|
2016-01-27 15:48:27 +01:00
|
|
|
render json: {cadastres: ModuleApiCartoService.generate_cadastre(JSON.parse(params[:coordinates]))}
|
2016-01-15 11:53:00 +01:00
|
|
|
end
|
|
|
|
|
2016-01-26 15:52:05 +01:00
|
|
|
def self.route_authorization
|
|
|
|
{
|
2017-09-22 10:28:16 +02:00
|
|
|
states: [:draft, :initiated],
|
2016-01-26 15:52:05 +01:00
|
|
|
api_carto: true
|
|
|
|
}
|
|
|
|
end
|
2015-08-20 16:34:14 +02:00
|
|
|
end
|