- QP not research if module_api_carto have not activated quartiers_prioritaires
- Carte page is not accessible if module_api_cart have not activated use_api_carto
This commit is contained in:
parent
0e3bec7f9f
commit
11596ade65
9 changed files with 95 additions and 34 deletions
|
@ -17,10 +17,7 @@ function initCarto() {
|
|||
layers: [OSM]
|
||||
});
|
||||
|
||||
freeDraw = new L.FreeDraw({
|
||||
//mode: L.FreeDraw.MODES.CREATE
|
||||
});
|
||||
|
||||
freeDraw = new L.FreeDraw();
|
||||
map.addLayer(freeDraw);
|
||||
|
||||
if ($("#json_latlngs").val() != '' && $("#json_latlngs").val() != '[]') {
|
||||
|
@ -35,13 +32,16 @@ function initCarto() {
|
|||
|
||||
add_event_freeDraw();
|
||||
|
||||
display_qp(JSON.parse($("#quartier_prioritaires").val()));
|
||||
if (qp_active())
|
||||
display_qp(JSON.parse($("#quartier_prioritaires").val()));
|
||||
}
|
||||
|
||||
function add_event_freeDraw() {
|
||||
freeDraw.on('markers', function (e) {
|
||||
$("#json_latlngs").val(JSON.stringify(e.latLngs));
|
||||
display_qp(get_qp(e.latLngs)['quartier_prioritaires']);
|
||||
|
||||
if (qp_active())
|
||||
display_qp(get_qp(e.latLngs));
|
||||
});
|
||||
|
||||
$("#new").on('click', function (e) {
|
||||
|
@ -71,7 +71,14 @@ function get_position() {
|
|||
return position;
|
||||
}
|
||||
|
||||
function qp_active() {
|
||||
return $("#map.qp").length > 0
|
||||
}
|
||||
|
||||
function get_qp(coordinates) {
|
||||
if (!qp_active())
|
||||
return;
|
||||
|
||||
var qp;
|
||||
|
||||
$.ajax({
|
||||
|
@ -84,10 +91,13 @@ function get_qp(coordinates) {
|
|||
qp = data
|
||||
});
|
||||
|
||||
return qp;
|
||||
return qp['quartier_prioritaires'];
|
||||
}
|
||||
|
||||
function display_qp(qp_list) {
|
||||
if (!qp_active())
|
||||
return;
|
||||
|
||||
qp_array = jsObject_to_array(qp_list);
|
||||
|
||||
$("#qp_list ul").html('');
|
||||
|
|
|
@ -3,6 +3,12 @@ class Users::CarteController < UsersController
|
|||
|
||||
def show
|
||||
@dossier = current_user_dossier
|
||||
|
||||
unless @dossier.procedure.module_api_carto.use_api_carto
|
||||
flash.alert = t('errors.messages.dossier_map_not_activated')
|
||||
redirect_to url_for(root_path)
|
||||
end
|
||||
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
flash.alert = t('errors.messages.dossier_not_found')
|
||||
redirect_to url_for(root_path)
|
||||
|
|
|
@ -23,5 +23,8 @@
|
|||
Quartiers Prioritaires
|
||||
%li
|
||||
%label
|
||||
= ff.check_box :cadastre
|
||||
= ff.check_box :cadastre, disabled: :disabled
|
||||
Cadastre
|
||||
%i
|
||||
%strong
|
||||
(bientôt disponible)
|
||||
|
|
|
@ -12,10 +12,13 @@
|
|||
%br
|
||||
%br
|
||||
.row
|
||||
#map.qp
|
||||
#qp_list
|
||||
%h3 Quartiers prioritaites
|
||||
%ul
|
||||
- if @dossier.procedure.module_api_carto.quartiers_prioritaires
|
||||
#map.qp
|
||||
#qp_list
|
||||
%h3 Quartiers prioritaites
|
||||
%ul
|
||||
-else
|
||||
#map
|
||||
|
||||
= form_tag(url_for({controller: :carte, action: :save, dossier_id: @dossier.id}), class: 'form-inline', method: 'POST') do
|
||||
%br
|
||||
|
|
|
@ -91,6 +91,7 @@ fr:
|
|||
one: "1 erreur a empêché ce(tte) %{resource} d'être sauvegardé(e) :"
|
||||
other: "%{count} erreurs ont empêché ce(tte) %{resource} d'être sauvegardé(e) :"
|
||||
dossier_not_found: "Le dossier n'existe pas ou vous n'y avez pas accès."
|
||||
dossier_map_not_activated: "Le dossier n'a pas accès à la cartographie."
|
||||
invalid_siret: "Le siret est incorrect"
|
||||
france_connect:
|
||||
connexion: "Erreur lors de la connexion à France Connect."
|
||||
|
|
|
@ -3,7 +3,10 @@ require 'spec_helper'
|
|||
RSpec.describe Users::CarteController, type: :controller do
|
||||
let(:bad_adresse) { 'babouba' }
|
||||
|
||||
let(:dossier) { create(:dossier, :with_user, :with_procedure) }
|
||||
let(:procedure) { create(:procedure, :with_api_carto) }
|
||||
let(:dossier) { create(:dossier, :with_user, procedure: procedure) }
|
||||
|
||||
let(:dossier_with_no_carto) { create(:dossier, :with_user, :with_procedure) }
|
||||
let!(:entreprise) { create(:entreprise, dossier: dossier) }
|
||||
let!(:etablissement) { create(:etablissement, dossier: dossier) }
|
||||
let(:bad_dossier_id) { Dossier.count + 1000 }
|
||||
|
@ -25,14 +28,23 @@ RSpec.describe Users::CarteController, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
it 'returns http success if carto is activated' do
|
||||
get :show, dossier_id: dossier.id
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
it 'redirection vers la liste des dossiers du user si dossier ID n\'existe pas' do
|
||||
get :show, dossier_id: bad_dossier_id
|
||||
expect(response).to redirect_to(root_path)
|
||||
context 'when procedure not have activate api carto' do
|
||||
it 'redirection on user dossier list' do
|
||||
get :show, dossier_id: dossier_with_no_carto.id
|
||||
expect(response).to redirect_to(root_path)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when dossier id not exist' do
|
||||
it 'redirection on user dossier list' do
|
||||
get :show, dossier_id: bad_dossier_id
|
||||
expect(response).to redirect_to(root_path)
|
||||
end
|
||||
end
|
||||
|
||||
it_behaves_like "not owner of dossier", :show
|
||||
|
|
|
@ -8,7 +8,7 @@ FactoryGirl.define do
|
|||
use_api_carto true
|
||||
end
|
||||
|
||||
trait :with_qp do
|
||||
trait :with_quartiers_prioritaires do
|
||||
use_api_carto true
|
||||
quartiers_prioritaires true
|
||||
end
|
||||
|
|
|
@ -5,8 +5,10 @@ FactoryGirl.define do
|
|||
description "Demande de subvention à l'intention des associations"
|
||||
|
||||
after(:build) do |procedure, _evaluator|
|
||||
module_api_carto = create(:module_api_carto)
|
||||
procedure.module_api_carto = module_api_carto
|
||||
if procedure.module_api_carto.nil?
|
||||
module_api_carto = create(:module_api_carto)
|
||||
procedure.module_api_carto = module_api_carto
|
||||
end
|
||||
end
|
||||
|
||||
trait :with_api_carto do
|
||||
|
|
|
@ -2,7 +2,9 @@ require 'spec_helper'
|
|||
|
||||
feature 'drawing a zone with freedraw' do
|
||||
let(:user) { create(:user) }
|
||||
let(:dossier) { create(:dossier, :with_procedure, :with_entreprise, user: user) }
|
||||
let(:module_api_carto) { create(:module_api_carto, :with_api_carto) }
|
||||
let(:procedure) { create(:procedure, module_api_carto: module_api_carto) }
|
||||
let(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, user: user) }
|
||||
|
||||
context 'when user is not logged in' do
|
||||
before do
|
||||
|
@ -22,26 +24,48 @@ feature 'drawing a zone with freedraw' do
|
|||
end
|
||||
end
|
||||
|
||||
scenario 'he is redirected to carte page' do
|
||||
expect(page).to have_css('.content #map')
|
||||
context 'when procedure have api carto activated' do
|
||||
scenario 'he is redirected to carte page' do
|
||||
expect(page).to have_css('.content #map')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when draw a zone on #map', js: true do
|
||||
before do
|
||||
allow_any_instance_of(Users::CarteController).
|
||||
to receive(:generate_qp).
|
||||
and_return({"QPCODE1234" => { :code => "QPCODE1234", :nom => "Quartier de test", :commune => "Paris", :geometry => { :type=>"MultiPolygon", :coordinates=>[[[[2.38715792094576, 48.8723062632126], [2.38724851642619, 48.8721392348061]]]] }}})
|
||||
context 'when procedure does not have api carto activated' do
|
||||
let(:module_api_carto) { create(:module_api_carto) }
|
||||
|
||||
page.execute_script('freeDraw.fire("markers", {latLngs: []});')
|
||||
wait_for_ajax
|
||||
scenario 'he is redirect to user dossiers index' do
|
||||
expect(page).to have_css('#users_index')
|
||||
end
|
||||
|
||||
scenario 'QP name is present on page' do
|
||||
expect(page).to have_content('Quartier de test')
|
||||
scenario 'alert message is present' do
|
||||
expect(page).to have_content('Le dossier n\'a pas accès à la cartographie')
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'Commune is present on page' do
|
||||
expect(page).to have_content('Paris')
|
||||
context 'when draw a zone on #map', js: true do
|
||||
context 'when module quartiers prioritaires is activated' do
|
||||
let(:module_api_carto) { create(:module_api_carto, :with_quartiers_prioritaires) }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(Users::CarteController).
|
||||
to receive(:generate_qp).
|
||||
and_return({"QPCODE1234" => {:code => "QPCODE1234", :nom => "Quartier de test", :commune => "Paris", :geometry => {:type => "MultiPolygon", :coordinates => [[[[2.38715792094576, 48.8723062632126], [2.38724851642619, 48.8721392348061]]]]}}})
|
||||
|
||||
page.execute_script('freeDraw.fire("markers", {latLngs: []});')
|
||||
wait_for_ajax
|
||||
end
|
||||
|
||||
scenario 'div #map .qp is present' do
|
||||
expect(page).to have_css('.content #map.qp')
|
||||
end
|
||||
|
||||
scenario 'QP name is present on page' do
|
||||
expect(page).to have_content('Quartier de test')
|
||||
end
|
||||
|
||||
scenario 'Commune is present on page' do
|
||||
expect(page).to have_content('Paris')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue