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
|
2018-10-10 20:02:37 +02:00
|
|
|
geo_json = clean_json_latlngs(params[:selection])
|
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
|
|
|
|
2018-10-10 20:02:37 +02:00
|
|
|
if geo_json.present?
|
2018-10-15 15:48:01 +02:00
|
|
|
ModuleApiCartoService.save_qp!(dossier, geo_json)
|
|
|
|
ModuleApiCartoService.save_cadastre!(dossier, geo_json)
|
2015-11-25 17:05:14 +01:00
|
|
|
end
|
|
|
|
|
2018-10-10 20:02:37 +02:00
|
|
|
dossier.update!(json_latlngs: geo_json)
|
2015-09-28 18:55:16 +02:00
|
|
|
|
2018-09-06 09:09:23 +02:00
|
|
|
redirect_to brouillon_dossier_path(dossier)
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
|
2018-10-10 20:01:02 +02:00
|
|
|
def zones
|
|
|
|
@dossier = current_user_dossier
|
|
|
|
@data = {}
|
|
|
|
|
2018-10-24 13:16:50 +02:00
|
|
|
geo_json = JSON.parse(params.fetch(:selection, '[]'))
|
2018-10-10 20:01:02 +02:00
|
|
|
|
|
|
|
if geo_json.first == ["error", "TooManyPolygons"]
|
|
|
|
@error = true
|
|
|
|
else
|
|
|
|
if @dossier.procedure.module_api_carto.quartiers_prioritaires?
|
2018-10-15 16:07:15 +02:00
|
|
|
quartiers_prioritaires = ModuleApiCartoService.generate_qp(geo_json)
|
2018-10-10 20:01:02 +02:00
|
|
|
@dossier.quartier_prioritaires.build(quartiers_prioritaires)
|
|
|
|
@data[:quartiersPrioritaires] = quartiers_prioritaires
|
|
|
|
end
|
|
|
|
|
|
|
|
if @dossier.procedure.module_api_carto.cadastre?
|
|
|
|
cadastres = ModuleApiCartoService.generate_cadastre(geo_json)
|
|
|
|
@dossier.cadastres.build(cadastres)
|
|
|
|
@data[:cadastres] = cadastres
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-01-15 11:53:00 +01:00
|
|
|
|
2016-01-26 15:52:05 +01:00
|
|
|
def self.route_authorization
|
|
|
|
{
|
2018-08-28 14:12:48 +02:00
|
|
|
states: [Dossier.states.fetch(:brouillon), Dossier.states.fetch(:en_construction)],
|
2018-01-15 19:02:12 +01:00
|
|
|
api_carto: true
|
2016-01-26 15:52:05 +01:00
|
|
|
}
|
|
|
|
end
|
2018-03-30 15:28:10 +02:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def clean_json_latlngs(json_latlngs)
|
|
|
|
# a polygon must contain at least 4 points
|
|
|
|
# https://tools.ietf.org/html/rfc7946#section-3.1.6
|
|
|
|
if json_latlngs.present?
|
|
|
|
multipolygone = JSON.parse(json_latlngs)
|
2018-10-22 15:37:47 +02:00
|
|
|
if multipolygone.first == ["error", "TooManyPolygons"]
|
|
|
|
[].to_json
|
|
|
|
else
|
|
|
|
multipolygone.reject! { |polygone| polygone.count < 4 }
|
|
|
|
if multipolygone.present?
|
|
|
|
multipolygone.to_json
|
|
|
|
end
|
2018-03-30 15:28:10 +02:00
|
|
|
end
|
|
|
|
end
|
2018-09-20 14:34:49 +02:00
|
|
|
end
|
2015-08-20 16:34:14 +02:00
|
|
|
end
|