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

71 lines
2.1 KiB
Ruby
Raw Normal View History

class Users::CarteController < UsersController
include DossierConcern
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.all.map(&:destroy)
unless params[:json_latlngs] == '' || params[:json_latlngs] == '[]'
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.new(qp).save
end
end
dossier.update_attributes(json_latlngs: params[:json_latlngs])
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 = {
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
}
commentaire = Commentaire.new commentaire_params
commentaire.save
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
tmp_position = Carto::Geocodeur.convert_adresse_to_point(current_user_dossier.etablissement.adresse.gsub("\r\n", ' '))
2015-08-10 11:05:06 +02: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
qp = generate_qp JSON.parse(params[:coordinates])
2015-11-25 10:26:55 +01:00
render json: {quartier_prioritaires: qp}
end
private
def generate_qp coordinates
qp = {}
coordinates.each_with_index do |coordinate, index|
coordinate = coordinates[index].map { |latlng| [latlng['lng'], latlng['lat']] }
qp = qp.merge CARTO::SGMAP::QuartierPrioritaireAdapter.new(coordinate).to_params
end
qp
end
2015-08-20 16:34:14 +02:00
end