Commit 0b44dc0b authored by Clouard Regis's avatar Clouard Regis
Browse files

Changed preview add control point on map.

parent 3ae35e24
......@@ -6,3 +6,4 @@
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/
/commandlinetools/
......@@ -46,7 +46,6 @@
<path value="$PROJECT_DIR$/vendor/symfony/css-selector" />
<path value="$PROJECT_DIR$/vendor/symfony/phpunit-bridge" />
<path value="$PROJECT_DIR$/vendor/symfony/browser-kit" />
<path value="$PROJECT_DIR$/vendor/symfony/inflector" />
<path value="$PROJECT_DIR$/vendor/easycorp/easy-deploy-bundle" />
<path value="$PROJECT_DIR$/vendor/doctrine/event-manager" />
<path value="$PROJECT_DIR$/vendor/doctrine/reflection" />
......@@ -121,7 +120,13 @@
<path value="$PROJECT_DIR$/vendor/symfony/security-guard" />
<path value="$PROJECT_DIR$/vendor/symfony/validator" />
<path value="$PROJECT_DIR$/vendor/symfony/http-client" />
<path value="$PROJECT_DIR$/vendor/symfony/deprecation-contracts" />
</include_path>
</component>
<component name="PhpProjectSharedConfiguration" php_language_level="7.4" />
<component name="PhpUnit">
<phpunit_settings>
<PhpUnitSettings configuration_file_path="$PROJECT_DIR$/phpunit.xml.dist" custom_loader_path="$PROJECT_DIR$/vendor/autoload.php" use_configuration_file="true" />
</phpunit_settings>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PHPUnit">
<option name="directories">
<list>
<option value="$PROJECT_DIR$/tests" />
</list>
</option>
</component>
</project>
\ No newline at end of file
......@@ -5,6 +5,10 @@
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" packagePrefix="App\Tests\" />
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" packagePrefix="App\" />
<excludeFolder url="file://$MODULE_DIR$/config/secret" />
<excludeFolder url="file://$MODULE_DIR$/tmp_files" />
<excludeFolder url="file://$MODULE_DIR$/upload" />
<excludeFolder url="file://$MODULE_DIR$/var" />
<excludeFolder url="file://$MODULE_DIR$/vendor" />
<excludeFolder url="file://$MODULE_DIR$/vendor/composer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/dama/doctrine-test-bundle" />
......@@ -75,7 +79,6 @@
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/http-client-contracts" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/http-foundation" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/http-kernel" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/inflector" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/intl" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/mailer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/maker-bundle" />
......
......@@ -10,29 +10,29 @@
"doctrine/doctrine-bundle": "^2.0",
"michaeldegroot/doctrine-encrypt-bundle": "^4.0",
"sensio/framework-extra-bundle": "^5.5",
"symfony/asset": "5.0.*",
"symfony/console": "5.0.*",
"symfony/dotenv": "5.0.*",
"symfony/expression-language": "5.0.*",
"symfony/asset": "5.*.*",
"symfony/console": "5.1.*",
"symfony/dotenv": "5.1.*",
"symfony/expression-language": "5.1.*",
"symfony/flex": "^1.3.1",
"symfony/form": "5.0.*",
"symfony/framework-bundle": "5.0.*",
"symfony/http-client": "5.0.*",
"symfony/intl": "5.0.*",
"symfony/mailer": "5.0.*",
"symfony/form": "5.1.*",
"symfony/framework-bundle": "5.1.*",
"symfony/http-client": "5.1.*",
"symfony/intl": "5.1.*",
"symfony/mailer": "5.1.*",
"symfony/monolog-bundle": "^3.1",
"symfony/notifier": "5.0.*",
"symfony/notifier": "5.1.*",
"symfony/orm-pack": "^1.0",
"symfony/process": "5.0.*",
"symfony/security-bundle": "5.0.*",
"symfony/process": "5.1.*",
"symfony/security-bundle": "5.1.*",
"symfony/serializer-pack": "*",
"symfony/string": "5.0.*",
"symfony/string": "5.1.*",
"symfony/swiftmailer-bundle": "^3.4",
"symfony/translation": "5.0.*",
"symfony/translation": "5.1.*",
"symfony/twig-pack": "*",
"symfony/validator": "5.0.*",
"symfony/web-link": "5.0.*",
"symfony/yaml": "5.0.*",
"symfony/validator": "5.1.*",
"symfony/web-link": "5.1.*",
"symfony/yaml": "5.1.*",
"ext-json": "*",
"ext-pdo": "*",
"ext-dom": "*",
......@@ -44,7 +44,7 @@
"easycorp/easy-deploy-bundle": "^1.0",
"symfony/debug-pack": "*",
"symfony/maker-bundle": "^1.15",
"symfony/phpunit-bridge": "^5.0",
"symfony/phpunit-bridge": "^5.1",
"symfony/profiler-pack": "^1.0",
"symfony/test-pack": "*"
},
......@@ -91,7 +91,7 @@
"extra": {
"symfony": {
"allow-contrib": false,
"require": "5.0.*"
"require": "5.1.*"
}
}
}
This diff is collapsed.
......@@ -81,103 +81,4 @@ function customeDropzone(uploadLink, defaultMessage, removeMessage, uploadErrorM
});
}
});
}
function previewXml(xml, divXml) {
while (divXml.lastElementChild) {
divXml.removeChild(divXml.lastElementChild);
}
if (!(typeof xml == "object")) {
let error = document.createElement("p");
error.setAttribute("class", "alert alert-danger");
error.innerHTML = xml;
divXml.appendChild(error);
} else {
let wideCol = document.createElement("div");
wideCol.setAttribute("class", "col");
let rowTitle = document.createElement("div");
rowTitle.setAttribute("class", "row");
let titleName = document.createElement("div");
titleName.setAttribute("class", "col");
titleName.innerHTML = "control";
let titleType = document.createElement("div");
titleType.setAttribute("class", "col");
titleType.innerHTML = "type";
rowTitle.appendChild(titleName);
rowTitle.appendChild(titleType);
wideCol.appendChild(rowTitle);
for (let [key, value] of Object.entries(xml)) {
let rowControl = document.createElement("div");
rowControl.setAttribute("class", "row");
let colName = document.createElement("div");
colName.setAttribute("class", "col");
colName.innerHTML = key;
let colType = document.createElement("div");
colType.setAttribute("class", "col");
colType.innerHTML = value;
rowControl.appendChild(colName);
rowControl.appendChild(colType);
wideCol.appendChild(rowControl);
}
divXml.appendChild(wideCol);
}
}
function previewMap(data, divMap, divLeaflet, map, overlay, img) {
while (divMap.lastElementChild) {
divMap.removeChild(divMap.lastElementChild);
}
fetch(window.location.origin + "/" + data.image).then(function (response) {
if (response.status === 200) {
overlay.setUrl(response.url);
img.onload = function () {
let quoWidthHeight = this.naturalHeight / this.naturalWidth;
img.width = divMap.clientWidth / 2;
img.height = divMap.clientWidth / 2 * quoWidthHeight;
}
img.src = response.url;
} else {
let error = document.createElement("p");
error.setAttribute("class", "alert alert-danger");
error.innerHTML = data.image;
divMap.appendChild(error);
img.width = 0;
img.height = 0;
overlay.setUrl("/empty");
img.src = "/empty";
}
});
try {
let lines = data.kml.split('\n');
lines.splice(0, 1);
let kml = lines.join('\n');
let parser = new DOMParser();
let kmlDoc = parser.parseFromString(kml, "text/xml");
divMap.appendChild(divLeaflet);
let corner = calculateCorner(kmlDoc);
divLeaflet.style.height = Math.floor(window.innerHeight * 0.75) + "px";
overlay.reposition(L.latLng(corner[0]), L.latLng(corner[1]), L.latLng(corner[3]));
map.fitBounds([corner[0], corner[2]]);
// Add recenter button
L.easyButton('fa-map-marker', function (btn, map) {
map.fitBounds([corner[0], corner[2]]);
}, 'Zoom To Home').addTo(map);
} catch (e) {
let error = document.createElement("p");
error.setAttribute("class", "alert alert-danger");
error.innerHTML = data.kml;
divLeaflet.style.width = "0px";
divLeaflet.style.height = "0px";
divMap.appendChild(error);
divMap.appendChild(img);
}
}
function showPreview(data, divXml, divMap, divLeaflet, map, overlay, img) {
previewXml(data.xml, divXml);
previewMap(data, divMap, divLeaflet, map, overlay, img);
}
\ No newline at end of file
......@@ -47,4 +47,127 @@ function generateMap(map_div) {
map.addLayer(osm);
L.control.scale({metric: true, imperial: false}).addTo(map);
return map;
}
function previewXml(data, divXml) { // TODO Supprimer demander à Eric. A défaut, revoir la table en Bootstrap.
while (divXml.lastElementChild) {
divXml.removeChild(divXml.lastElementChild);
}
if (!(typeof data.xml1 == "object")) {
let error = document.createElement("p");
error.setAttribute("class", "alert alert-danger");
error.innerHTML = data.xml1;
divXml.appendChild(error);
} else {
let tableSection = document.createElement("table");
tableSection.setAttribute("class", "table");
let tableHead = document.createElement("thead");
let rowHead = document.createElement("tr");
let indexColumnHead = document.createElement("th");
indexColumnHead.setAttribute("scope", "col");
indexColumnHead.innerHTML = "Numéro";
let nameColumnHead = document.createElement("th");
nameColumnHead.setAttribute("scope", "col");
nameColumnHead.innerHTML = "Nom";
let typeColumnHead = document.createElement("th");
typeColumnHead.setAttribute("scope", "col");
typeColumnHead.innerHTML = "Type";
rowHead.appendChild(indexColumnHead);
rowHead.appendChild(nameColumnHead);
rowHead.appendChild(typeColumnHead);
tableHead.appendChild(rowHead);
tableSection.appendChild(tableHead);
let tableBody = document.createElement("tbody");
tableSection.appendChild(tableBody);
for (let [key, value] of Object.entries(data.xml1)) {
let row = document.createElement("tr");
let indexCell = document.createElement("th");
indexCell.setAttribute("scope", "row");
indexCell.innerHTML = parseInt(key, 10) + 1;
let nameCell = document.createElement("td");
nameCell.innerHTML = value[0];
let typeCell = document.createElement("td");
typeCell.innerHTML = value[1];
row.appendChild(indexCell);
row.appendChild(nameCell);
row.appendChild(typeCell);
tableSection.appendChild(row);
}
divXml.appendChild(tableSection);
}
}
function previewMap(data, divMap, divLeaflet, map, overlay, img) {
while (divMap.lastElementChild) {
divMap.removeChild(divMap.lastElementChild);
}
fetch(window.location.origin + "/" + data.image).then(function (response) {
if (response.status === 200) {
overlay.setUrl(response.url);
img.onload = function () {
let quoWidthHeight = this.naturalHeight / this.naturalWidth;
img.width = divMap.clientWidth / 2;
img.height = divMap.clientWidth / 2 * quoWidthHeight;
}
img.src = response.url;
} else {
let error = document.createElement("p");
error.setAttribute("class", "alert alert-danger");
error.innerHTML = data.image;
divMap.appendChild(error);
img.width = 0;
img.height = 0;
overlay.setUrl("/empty");
img.src = "/empty";
}
});
try {
let lines = data.kml.split('\n');
lines.splice(0, 1);
let kml = lines.join('\n');
let parser = new DOMParser();
let kmlDoc = parser.parseFromString(kml, "text/xml");
divMap.appendChild(divLeaflet);
let corner = calculateCorner(kmlDoc);
divLeaflet.style.height = Math.floor(window.innerHeight * 0.75) + "px";
overlay.reposition(L.latLng(corner[0]), L.latLng(corner[1]), L.latLng(corner[3]));
map.fitBounds([corner[0], corner[2]]);
// Add recenter button
L.easyButton('fa-map-marker', function (btn, map) {
map.fitBounds([corner[0], corner[2]]);
}, 'Zoom To Home').addTo(map);
} catch (e) {
let error = document.createElement("p");
error.setAttribute("class", "alert alert-danger");
error.innerHTML = data.kml;
divLeaflet.style.width = "0px";
divLeaflet.style.height = "0px";
divMap.appendChild(error);
divMap.appendChild(img);
}
}
function addControlPointOnMap(data, map) {
for (let [key, value] of Object.entries(data.xml2)) {
a = L.circleMarker(value, {
radius: 8.0,
fillColor: '#ff0000',
color: '#000000',
weight: 1,
opacity: 1.0,
fillOpacity: 0.8
}).addTo(map);
a.bindPopup(key, {maxWidth: "none"})
}
}
function showPreview(data, divXml, divMap, divLeaflet, map, overlay, img) {
previewXml(data, divXml);
previewMap(data, divMap, divLeaflet, map, overlay, img);
addControlPointOnMap(data, map);
}
\ No newline at end of file
function openTab(tabTitle, tabId) {
let i, tabContent, tabLinks;
tabContent = document.getElementsByClassName("tab-content");
for (i = 0; i < tabContent.length; i++) {
tabContent[i].style.display = "none";
}
tabLinks = document.getElementsByClassName("tab-links");
for (i = 0; i < tabLinks.length; i++) {
tabLinks[i].className = tabLinks[i].className.replace(" active", "");
}
document.getElementById(tabId).style.display = "block";
document.getElementById(tabTitle).className += " active";
}
document.getElementById("tab1").click();
......@@ -20,7 +20,7 @@ use function in_array;
class PlannerController extends AbstractController
{
private $security;
private Security $security;
public function __construct(Security $security)
{
......@@ -177,18 +177,28 @@ class PlannerController extends AbstractController
function course_info($id)
{
$course = $this->getDoctrine()->getRepository(Course::class)->find($id);
$data = array();
$sxml = \simplexml_load_string($course->getXml());
$data1 = array();
$xmlData = $sxml->RaceCourseData;
foreach ($xmlData->Course->children() as $children) {
if ($children->getName() === "CourseControl") {
$data[(string)$children->Control] = (string)$children["type"];
$data1[] = [(string)$children->Control, (string)$children["type"]];
}
}
$data2 = array();
foreach ($sxml->RaceCourseData->children() as $children) {
if ($children->getName() === "Control") {
$data2[(string)$children->Id] = array((string)$children->Position["lat"], (string)$children->Position["lng"]);
}
}
return new JsonResponse(
[
'xml' => $data,
'xml1' => $data1,
'xml2' => $data2,
'kml' => $course->getKml(),
'image' => $course->getImage(),
]
......
......@@ -11,8 +11,7 @@ use PDOException;
use App\Entity\Course;
use App\Entity\User;
use App\Model\CourseValidator;
use App\Model\FileUploader;
use function simplexml_load_string;
class CreateCourse
{
......@@ -59,16 +58,34 @@ class CreateCourse
return $data;
}
private function generatePreviewXml(string $xml)
private function generatePreviewXml1(string $xml)
{
$error = CourseValidator::checkXml($xml);
if ($error == CourseValidator::$NO_ERROR) {
$data = array();
$sxml = \simplexml_load_string($xml);
$xmldata = $sxml->RaceCourseData;
foreach ($xmldata->Course->children() as $children) {
$data = [];
$sxml = simplexml_load_string($xml);
$xmlData = $sxml->RaceCourseData;
foreach ($xmlData->Course->children() as $children) {
if ($children->getName() === "CourseControl") {
$data[(string)$children->Control] = (string)$children["type"];
$data[] = [(string)$children->Control, (string)$children["type"]];
}
}
return $data;
} else {
return $this->translateError($error);
}
}
private function generatePreviewXml2(string $xml)
{
$error = CourseValidator::checkXml($xml);
if ($error == CourseValidator::$NO_ERROR) {
$data = array();
$sxml = simplexml_load_string($xml);
foreach ($sxml->RaceCourseData->children() as $children) {
if ($children->getName() === "Control") {
$data[(string)$children->Id] = array((string)$children->Position["lat"], (string)$children->Position["lng"]);
}
}
......@@ -102,14 +119,19 @@ class CreateCourse
{
$data = array();
$post = $request->request;
if ($post->get("xml") == "true") {
$xml = file_get_contents(FileUploader::getFile($this->user->getId(), "xml"));
$data["xml"] = $this->generatePreviewXml($xml);
$data["xml1"] = $this->generatePreviewXml1($xml);
$data["xml2"] = $this->generatePreviewXml2($xml);
} elseif ($this->course->getXml() != null) {
$data["xml"] = $this->generatePreviewXml($this->course->getXml());
$data["xml1"] = $this->generatePreviewXml1($this->course->getXml());
$data["xml2"] = $this->generatePreviewXml2($this->course->getXml());
} else {
$data["xml"] = $this->translator->trans("no.xml.submitted");
$data["xml1"] = $this->translator->trans("no.xml.submitted");
$data["xml2"] = $this->translator->trans("no.xml.submitted");
}
if ($post->get("kml") == "true") {
$kml = file_get_contents(FileUploader::getFile($this->user->getId(), "kml"));
$data["kml"] = $this->generatePreviewKml($kml);
......@@ -118,6 +140,7 @@ class CreateCourse
} else {
$data["kml"] = $this->translator->trans("no.kml.submitted");
}
if ($post->get("image") == "true") {
$image = FileUploader::getFile($this->user->getId(), "image");
$data["image"] = $this->generatePreviewImage($image);
......
......@@ -238,6 +238,9 @@
"symfony/dependency-injection": {
"version": "v5.0.7"
},
"symfony/deprecation-contracts": {
"version": "v2.1.3"
},
"symfony/doctrine-bridge": {
"version": "v5.0.7"
},
......@@ -312,9 +315,6 @@
"symfony/http-kernel": {
"version": "v5.0.7"
},
"symfony/inflector": {
"version": "v5.0.7"
},
"symfony/intl": {
"version": "v5.0.7"
},
......
{% extends 'base.html.twig' %}
{% block title %}{% trans %}courses{% endtrans %}{% endblock %}
{% block title %}{% trans %}courses.title{% endtrans %}{% endblock %}
{% block body %}
<div class="container" style="padding-top: 20pt">
......
......@@ -24,8 +24,8 @@
{% endblock %}
{% block javascripts %}
<script src="{{ asset('/public/javascript/showMap.js') }}"></script>
<script src="{{ asset('/public/javascript/addCourse.js') }}"></script>
<script src="{{ asset('/public/javascript/showMap.js') }}"></script>
<script src="{{ asset('/public/javascript/courseTrack.js') }}"></script>
<script src="{{ asset('/public/javascript/courseTimeSheet.js') }}"></script>
<script src="{{ asset('/public/javascript/courseFiles.js') }}"></script>
......
{% extends 'base.html.twig' %}
{% block stylesheets %}
<link rel="stylesheet" href="{{ asset('/public/css/tabs.css') }}"/>
<link rel="stylesheet" href="{{ asset('/public/css/dropzone/dist/dropzone.css') }}">
<link rel="stylesheet" href="{{ asset('/public/leaflet/leaflet.css') }}"/>
<link rel="stylesheet" href="{{ asset('/public/leaflet/easy-button.css') }}"/>
......@@ -15,7 +16,6 @@
<script src="{{ asset('/public/javascript/addCourse.js') }}"></script>
<script src="{{ asset('/public/leaflet/easy-button.js') }}"></script>
{{ parent() }} {#SUPPRIMER ?#}
<script>
// init,configure dropzone
let xml_icon;
......@@ -30,7 +30,7 @@
Dropzone.autoDiscover = false;
// dropzone sends files one by one and we have to receive all data at once
function postData(preview) {
function postData(preview) { // TODO Faire deux fonctions ~preview true and false.
let name = document.getElementById("name").value;
let isNameProvided = name.length > 0;
let isXMLProvided = xml instanceof File;
......@@ -119,14 +119,14 @@
{% if data.name is defined %}
<script>window.addEventListener("load", function (event) {
document.getElementById("name").value = "{{ data.name }}";
});</script>
});
</script>
{% endif %}
{% endblock %}
{% block title %}{{ data.title }}{% endblock %}
{% block body %}
<div class="container" style="padding-top: 20pt">
<h3>{{ data.title }}</h3>
{% if error is defined %}
......@@ -135,7 +135,7 @@
<div class="row">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">{% trans %}name{% endtrans %}</span>
<span class="input-group-text">{% trans %}course.name{% endtrans %}</span>
</div>
<input type="text" class="form-control" id="name" placeholder="{% trans %}course.name{% endtrans %}" aria-label="name" aria-describedby="name">