Commit 0adf6b51 by Julien Jorry

Bugfix de l'installation du Kohinos

parent 810876cb
......@@ -8,61 +8,12 @@
// any CSS you require will output into a single css file (app.css in this case)
require('../css/admin.css');
require('bootstrap');
require('../js/flash-messages.js');
require('../leaflet/leaflet.js');
require('../js/geoloc.js');
// require('../leaflet/leaflet.css');
// Need jQuery? Install it with "yarn add jquery", then uncomment to require it.
$('#flash-messages').flashNotification('init');
$(document).ready(function() {
var mapMarkers = [];
$(document).on('click', '.searchLatLon', function (e) {
e.preventDefault();
var self = $(this);
$.ajax({
url : self.data('url'),
type: 'post',
data : {'adresse' : $('#'+(self.attr('id').replace('_geoloc_search', ''))+'_geoloc_adresse').val(), 'cpostal' : $('#'+(self.attr('id').replace('_geoloc_search', ''))+'_geoloc_cpostal').val(), 'ville' : $('#'+(self.attr('id').replace('_geoloc_search', ''))+'_geoloc_ville').val()},
success: function(response) {
var divid = self.attr('id').replace('_geoloc_search', '');
$('#'+divid+'_message').remove();
$('#'+divid+'_map').remove();
var marker_1 = null;
if(response.status == 'success' && response.data && response.data.lat != '' && response.data.lon != '') {
$('#'+divid+'_geoloc_lat').val(response.data.lat);
$('#'+divid+'_geoloc_lon').val(response.data.lon);
$('#'+divid+'_geoloc_lat').addClass('inputsuccess');
$('#'+divid+'_geoloc_lon').addClass('inputsuccess');
$('<p id="'+(divid+'_message')+'">Cliquez sur la carte si vous voulez affiner la géolocalisation</p><div id="'+(divid+'_map')+'" style="height: 250px;margin-top: 10px;"></div>').insertAfter('#'+self.attr('id'));
var latlon = L.latLng(parseFloat(response.data.lat), parseFloat(response.data.lon));
var mymap = L.map(divid+'_map').setView(latlon, 13);
L.tileLayer('https://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png', {maxZoom: 18, attribution: '&copy; Openstreetmap France | &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'}).addTo(mymap);
var marker_1 = L.marker(latlon).addTo(mymap);
} else {
$(this).addClass('inputerror');
$('<p id="'+(divid+'_message')+'">ADRESSE INCONNUE : Cliquez sur la carte pour définir une adresse</p><div id="'+(divid+'_map')+'" style="height: 250px;margin-top: 10px;"></div>').insertAfter('#'+self.attr('id'));
var mymap = L.map(divid+'_map').setView(JSON.parse($('#koh_map_center').val()), parseInt($('#koh_map_zoom').val()));
L.tileLayer('https://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png', {maxZoom: 18, attribution: '&copy; Openstreetmap France | &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'}).addTo(mymap);
}
mymap.on('click', function(e){
if (marker_1 != null) {
mymap.removeLayer(marker_1);
}
for(var i = 0; i < mapMarkers.length; i++){
mymap.removeLayer(mapMarkers[i]);
}
// Add marker to map at click location; add popup window
var newMarker = new L.marker(e.latlng);
newMarker.addTo(mymap);
mapMarkers.push(newMarker);
$('#'+divid+'_geoloc_lat').val(e.latlng.lat);
$('#'+divid+'_geoloc_lon').val(e.latlng.lng);
$('#'+divid+'_geoloc_lat').addClass('inputsuccess');
$('#'+divid+'_geoloc_lon').addClass('inputsuccess');
});
}
});
});
$('.editableboolean').on('click', function (e) {
e.preventDefault();
var self = $(this);
......
......@@ -32,8 +32,10 @@ require('bootstrap');
require('../leaflet/leaflet.js');
// for flash message notification
require('../js/flash-messages.js');
const mlc = require('../js/mlc.js');
// MLC js
require('../js/mlc.js');
require('../js/geoloc.js');
// can be use to sort with drag'n drop in sonata admin
// require('../../public/bundles/pixsortablebehavior/js/init.js');
......
require('../leaflet/leaflet.js');
require('../js/flash-messages.js');
$(document).ready(function() {
var mapMarkers = [];
$(document).on('click', '.searchLatLon', function (e) {
e.preventDefault();
var self = $(this);
$.ajax({
url : self.data('url'),
type: 'post',
data : {'adresse' : $('#'+(self.attr('id').replace('_geoloc_search', ''))+'_geoloc_adresse').val(), 'cpostal' : $('#'+(self.attr('id').replace('_geoloc_search', ''))+'_geoloc_cpostal').val(), 'ville' : $('#'+(self.attr('id').replace('_geoloc_search', ''))+'_geoloc_ville').val()},
success: function(response) {
var divid = self.attr('id').replace('_geoloc_search', '');
$('#'+divid+'_message').remove();
$('#'+divid+'_map').remove();
var marker_1 = null;
if(response.status == 'success' && response.data && response.data.lat != '' && response.data.lon != '') {
$('#'+divid+'_geoloc_lat').val(response.data.lat);
$('#'+divid+'_geoloc_lon').val(response.data.lon);
$('#'+divid+'_geoloc_lat').addClass('inputsuccess');
$('#'+divid+'_geoloc_lon').addClass('inputsuccess');
$('<p id="'+(divid+'_message')+'">Cliquez sur la carte si vous voulez affiner la géolocalisation</p><div id="'+(divid+'_map')+'" style="height: 250px;margin-top: 10px;"></div>').insertAfter('#'+self.attr('id'));
var latlon = L.latLng(parseFloat(response.data.lat), parseFloat(response.data.lon));
var mymap = L.map(divid+'_map').setView(latlon, 13);
L.tileLayer('https://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png', {maxZoom: 18, attribution: '&copy; Openstreetmap France | &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'}).addTo(mymap);
var marker_1 = L.marker(latlon).addTo(mymap);
} else {
$(this).addClass('inputerror');
$('<p id="'+(divid+'_message')+'">ADRESSE INCONNUE : Cliquez sur la carte pour définir une adresse</p><div id="'+(divid+'_map')+'" style="height: 250px;margin-top: 10px;"></div>').insertAfter('#'+self.attr('id'));
var mymap = L.map(divid+'_map').setView(JSON.parse($('#koh_map_center').val()), parseInt($('#koh_map_zoom').val()));
L.tileLayer('https://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png', {maxZoom: 18, attribution: '&copy; Openstreetmap France | &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'}).addTo(mymap);
}
mymap.on('click', function(e){
if (marker_1 != null) {
mymap.removeLayer(marker_1);
}
for(var i = 0; i < mapMarkers.length; i++){
mymap.removeLayer(mapMarkers[i]);
}
// Add marker to map at click location; add popup window
var newMarker = new L.marker(e.latlng);
newMarker.addTo(mymap);
mapMarkers.push(newMarker);
$('#'+divid+'_geoloc_lat').val(e.latlng.lat);
$('#'+divid+'_geoloc_lon').val(e.latlng.lng);
$('#'+divid+'_geoloc_lat').addClass('inputsuccess');
$('#'+divid+'_geoloc_lon').addClass('inputsuccess');
});
}
});
});
});
\ No newline at end of file
......@@ -3,7 +3,7 @@
"app": {
"js": [
"/build/runtime.6cf710cd.js",
"/build/app.5ceba3b7.js"
"/build/app.f9856349.js"
],
"css": [
"/build/app.f6a68444.css"
......@@ -12,7 +12,7 @@
"admin": {
"js": [
"/build/runtime.6cf710cd.js",
"/build/admin.065fe9cf.js"
"/build/admin.a7f557fb.js"
],
"css": [
"/build/admin.fecc301b.css"
......
{
"build/admin.css": "/build/admin.fecc301b.css",
"build/admin.js": "/build/admin.065fe9cf.js",
"build/admin.js": "/build/admin.a7f557fb.js",
"build/app.css": "/build/app.f6a68444.css",
"build/app.js": "/build/app.5ceba3b7.js",
"build/app.js": "/build/app.f9856349.js",
"build/runtime.js": "/build/runtime.6cf710cd.js",
"build/ckeditor/adapters/jquery.js": "/build/ckeditor/adapters/jquery.js",
"build/ckeditor/ckeditor.js": "/build/ckeditor/ckeditor.js",
......
......@@ -114,45 +114,4 @@ class AdminController extends Controller
return $response;
}
/**
* @Route("/admin/geoloc", name="geolocAdresse")
* @IsGranted("ROLE_ADMIN")
*/
public function geoLocAction(Request $request)
{
$referer = $request->headers->get('referer');
if ($referer && !$request->isXmlHttpRequest()) {
return $this->redirect($referer);
} elseif (!$request->isXmlHttpRequest()) {
return new Response('', Response::HTTP_BAD_REQUEST);
}
$status = 'success';
$return = null;
if (!empty($request->get('cpostal')) && !empty($request->get('ville'))) {
try {
// GEOCODING ADDRESS :
$httpClient = new \Http\Adapter\Guzzle6\Client();
$provider = Nominatim::withOpenStreetMapServer($httpClient, 'Mozilla/5.0');
$geocoder = new \Geocoder\StatefulGeocoder($provider, 'fr');
// Query geocoding from complete address
$result = $geocoder->geocodeQuery(GeocodeQuery::create($request->get('adresse').' '.$request->get('cpostal').' '.$request->get('ville')));
if (count($result) > 0) {
$coords = $result->first()->getCoordinates();
$return = ['lat' => $coords->getLatitude(), 'lon' => $coords->getLongitude()];
} else {
$result = $geocoder->geocodeQuery(GeocodeQuery::create($request->get('cpostal').' '.$request->get('ville')));
if (count($result) > 0) {
$coords = $result->first()->getCoordinates();
$return = ['lat' => $coords->getLatitude(), 'lon' => $coords->getLongitude()];
}
}
} catch (\Exception $e) {
$status = 'error';
}
} else {
$status = 'error';
}
return new JsonResponse(array('status' => $status, 'data' => $return));
}
}
......@@ -36,6 +36,7 @@ use Swagger\Annotations as SWG;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
......@@ -157,22 +158,23 @@ class IndexController extends AbstractController
$presta->addUser($user);
$presta->setGroupe($groupe);
$this->userManager->updateUser($user);
$this->em->persist($siege);
$this->em->persist($groupe);
$this->em->persist($comptoir);
$this->em->persist($user);
$this->userManager->updateUser($user);
$this->em->persist($presta);
foreach ($configs as $config) {
$this->em->persist($config);
}
$this->em->flush();
// Création de l'utilisateur avec ROLE_API pour le plugin Wordpress ou les applis tierces !
$userAPI = $this->userManager->createUser();
$userAPI->setEnabled(true);
$userAPI->setUsername('userapi');
$userAPI->setemail('userapi@kohinos.fr');
$userAPI->setPassword(md5(random_bytes(10)));
$userAPI->setEmail('userapi@kohinos.fr');
$userAPI->addRole('ROLE_API');
$this->em->persist($userAPI);
$this->userManager->updateUser($userAPI);
$this->em->flush();
$this->addFlash(
......@@ -255,6 +257,46 @@ class IndexController extends AbstractController
));
}
/**
* @Route("/geoloc", name="geolocAdresse")
*/
public function geoLocAction(Request $request)
{
$referer = $request->headers->get('referer');
if ($referer && !$request->isXmlHttpRequest()) {
return $this->redirect($referer);
} elseif (!$request->isXmlHttpRequest()) {
return new Response('', Response::HTTP_BAD_REQUEST);
}
$status = 'success';
$return = null;
if (!empty($request->get('cpostal')) && !empty($request->get('ville'))) {
try {
// GEOCODING ADDRESS :
$httpClient = new \Http\Adapter\Guzzle6\Client();
$provider = Nominatim::withOpenStreetMapServer($httpClient, 'Mozilla/5.0');
$geocoder = new \Geocoder\StatefulGeocoder($provider, 'fr');
// Query geocoding from complete address
$result = $geocoder->geocodeQuery(GeocodeQuery::create($request->get('adresse').' '.$request->get('cpostal').' '.$request->get('ville')));
if (count($result) > 0) {
$coords = $result->first()->getCoordinates();
$return = ['lat' => $coords->getLatitude(), 'lon' => $coords->getLongitude()];
} else {
$result = $geocoder->geocodeQuery(GeocodeQuery::create($request->get('cpostal').' '.$request->get('ville')));
if (count($result) > 0) {
$coords = $result->first()->getCoordinates();
$return = ['lat' => $coords->getLatitude(), 'lon' => $coords->getLongitude()];
}
}
} catch (\Exception $e) {
$status = 'error';
}
} else {
$status = 'error';
}
return new JsonResponse(array('status' => $status, 'data' => $return));
}
private function removeOldSessionParams()
{
$this->session->remove('_choixGroup');
......
......@@ -29,11 +29,15 @@
{{ encore_entry_link_tags('app') }}
{% endblock stylesheets %}
<link rel="stylesheet" href="/leaflet/leaflet.css">
{# POUR AJOUTER DES CSS #}
{% block css %} {% endblock css %}
</head>
<body>
<input type="hidden" name="koh_map_center" id="koh_map_center" value='{{KOH_MAP_CENTER|default('')}}' />
<input type="hidden" name="koh_map_zoom" id="koh_map_zoom" value='{{KOH_MAP_ZOOM|default('')}}' />
{% include 'common/modale_choix_groupe.html.twig' %}
<!-- HEADER -->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment