demarches-normaliennes/app/controllers/users/carte_controller.rb

66 lines
1.6 KiB
Ruby
Raw Normal View History

class Users::CarteController < UsersController
2016-01-26 15:52:05 +01:00
before_action only: [:show] do
authorized_routes? self.class
end
2015-08-10 11:05:06 +02:00
def show
@dossier = current_user_dossier
2015-08-18 10:43:22 +02:00
rescue ActiveRecord::RecordNotFound
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
def save
dossier = current_user_dossier
dossier.quartier_prioritaires.each(&:destroy)
dossier.cadastres.each(&:destroy)
2018-01-11 19:04:39 +01:00
if params[:json_latlngs].present?
ModuleApiCartoService.save_qp! dossier, params[:json_latlngs]
ModuleApiCartoService.save_cadastre! dossier, params[:json_latlngs]
end
dossier.update_attributes(json_latlngs: params[:json_latlngs])
redirect_to modifier_dossier_path(dossier)
2015-08-10 11:05:06 +02:00
end
def get_position
begin
etablissement = current_user_dossier.etablissement
rescue ActiveRecord::RecordNotFound
etablissement = nil
end
2018-01-11 19:04:39 +01:00
point = Carto::Geocodeur.convert_adresse_to_point(etablissement.geo_adresse) if etablissement.present?
lon = '2.428462'
lat = '46.538192'
zoom = '13'
2015-08-10 11:05:06 +02:00
2018-01-11 19:04:39 +01:00
if point.present?
lon = point.x.to_s
lat = point.y.to_s
2015-08-10 11:05:06 +02:00
end
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
render json: { quartier_prioritaires: ModuleApiCartoService.generate_qp(JSON.parse(params[:coordinates])) }
2015-11-25 10:26:55 +01:00
end
def get_cadastre
render json: { cadastres: ModuleApiCartoService.generate_cadastre(JSON.parse(params[:coordinates])) }
end
2016-01-26 15:52:05 +01:00
def self.route_authorization
{
2018-01-15 19:02:12 +01:00
states: [:brouillon, :en_construction],
api_carto: true
2016-01-26 15:52:05 +01:00
}
end
2015-08-20 16:34:14 +02:00
end