Commit c2d998c2 authored by A Boiteau's avatar A Boiteau Committed by Regis
Browse files

New behaviour, selecting a free-order track now deselected every other...

parent 7bfc57b7
......@@ -18,12 +18,17 @@ function removeDownloadButton(div, button) {
div.removeChild(button);
}
function clearDownloadButton(div) {
while (div.hasChildNodes()){
div.firstChild.remove();
}
}
function downloadFile(filename, contents) {
oldHeader = "<gpx version=\"1.0\">"
let oldHeader = "<gpx version=\"1.0\">"
if (contents.startsWith(oldHeader)) {
contents = contents.substring(oldHeader.length);
}
header = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?><gpx version=\"1.1\" xmlns=\"http://www.topografix.com/GPX/1/1\" creator=\"Vikazimut\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">";
let header = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?><gpx version=\"1.1\" xmlns=\"http://www.topografix.com/GPX/1/1\" creator=\"Vikazimut\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">";
contents = header + contents;
let element = document.createElement('a');
......
......@@ -12,6 +12,11 @@ function removeTimeSheet(event, pseudo) {
showTimeSheet();
}
function clearTimeSheet(){
timeSheetData = [];
showTimeSheet();
}
function convertTimetoString(time) {
timeInS = time / 1000.0;
hrs = Math.floor(timeInS / 3600);
......@@ -31,6 +36,27 @@ function convertTimetoString(time) {
}
}
function deltaDistanceCalculator(idealDistance,realDistance){
let distanceString = idealDistance.toString() + " m";
(idealDistance >+ realDistance) ? distanceString += " (+" : distanceString += " (";
distanceString += Math.round(((idealDistance/realDistance)-1)*100) + "%)";
return distanceString;
}
function RKCalculator(timeInMilliseconds,distanceInMeter){
let timeInS = timeInMilliseconds / 1000.0;
let mins = timeInS / 60;
let distInKm = distanceInMeter / 1000.0;
return (Math.round(mins / distInKm * 10)/10).toFixed(1);
}
function speedCalculator(timeInMilliseconds,distanceInMeter){
let timeInS = timeInMilliseconds / 1000.0;
let hrs = timeInS / 3600;
let distInKm = distanceInMeter / 1000.0;
return (Math.round(distInKm / hrs * 10)/10).toFixed(1);
}
function renderTimeSheet(distances) {
if (timeSheetData.length === 0) {
return document.createElement("p");
......@@ -51,11 +77,13 @@ function renderTimeSheet(distances) {
let headRow2 = document.createElement("tr");
cell = document.createElement("th");
cell.setAttribute("scope", "col");
cell.innerHTML = "poste";
cell.className = "align-middle";
cell.innerHTML = translations.controlPoint;
headRow2.appendChild(cell);
cell = document.createElement("th");
cell.setAttribute("scope", "col");
cell.innerHTML = "longueur";
cell.className = "align-middle";
cell.innerHTML = translations.length + " (m)";
headRow2.appendChild(cell);
let head = document.createElement("thead");
......@@ -66,19 +94,22 @@ function renderTimeSheet(distances) {
let body = document.createElement("tbody");
let rows = [];
let cps = timeSheetData[0][1];
for (let $i = 0; $i < cps.length; $i++) {
const index = cps[$i]["controlPoint"];
let totalDistance = 0;
for (let i = 0; i < cps.length; i++) {
const index = cps[i]["controlPoint"];
let controlCell = document.createElement("th");
let lengthCell = document.createElement("td");
controlCell.setAttribute("scope", "col");
if (index === 0) {
controlCell.innerHTML = "Départ";
controlCell.innerHTML = translations.start;
} else if (index === timeSheetData[0][1].length - 1) {
controlCell.innerHTML = "Arrivée";
lengthCell.innerHTML = distances[$i] + " m";
controlCell.innerHTML = translations.finish;
lengthCell.innerHTML = distances[i] + " m";
totalDistance += distances[i];
} else {
controlCell.innerHTML = index;
lengthCell.innerHTML = distances[$i] + " m";
lengthCell.innerHTML = distances[i] + " m";
totalDistance += distances[i];
}
let row = document.createElement("tr");
row.appendChild(controlCell);
......@@ -86,55 +117,91 @@ function renderTimeSheet(distances) {
body.appendChild(row);
rows.push(row);
}
let totalTitleCell = document.createElement("th");
totalTitleCell.innerHTML = translations.totals;
let totalLengthCell = document.createElement("th");
totalLengthCell.innerHTML = totalDistance.toString() + " m";
let totalsRow = document.createElement("tr");
totalsRow.appendChild(totalTitleCell);
totalsRow.appendChild(totalLengthCell);
body.appendChild(totalsRow);
// Body tracks
timeSheetData.forEach(function (orienteerData) {
let cell = document.createElement("th");
cell.colSpan = 3;
cell.setAttribute("scope", "col");
cell.innerHTML = orienteerData[0];
headRow1.appendChild(cell);
cell = document.createElement("th");
cell.setAttribute("scope", "col");
cell.innerHTML = "durée";
headRow2.appendChild(cell);
cell = document.createElement("th");
cell.setAttribute("scope", "col");
cell.innerHTML = "distance";
headRow2.appendChild(cell);
cell = document.createElement("th");
cell.setAttribute("scope", "col");
cell.innerHTML = "RK";
headRow2.appendChild(cell);
for (let i = 0; i < orienteerData[1].length; i++) {
let index = i;
let timeCell = document.createElement("th");
timeCell.style.background = "lightgray";
timeCell.setAttribute("scope", "col");
let distanceCell = document.createElement("td");
distanceCell.setAttribute("scope", "col");
let paceCell = document.createElement("td");
paceCell.setAttribute("scope", "col");
if (i > 0) {
time = orienteerData[2][i];
if (time > 0) {
timeCell.innerHTML = convertTimetoString(orienteerData[2][i]);
distanceCell.innerHTML = orienteerData[3][i] + " m";
paceCell.innerHTML = convertTimetoString(orienteerData[4][i]);
} else {
timeCell.innerHTML = "--:--";
distanceCell.innerHTML = "-";
paceCell.innerHTML = "--:--";
}
let cell = document.createElement("th");
cell.colSpan = 3;
cell.setAttribute("scope", "col");
cell.innerHTML = orienteerData[0];
headRow1.appendChild(cell);
cell = document.createElement("th");
cell.setAttribute("scope", "col");
cell.className = "align-middle";
cell.innerHTML = translations.duration;
headRow2.appendChild(cell);
cell = document.createElement("th");
cell.setAttribute("scope", "col");
cell.className = "align-middle";
cell.innerHTML = translations.distance+ " (m)";
headRow2.appendChild(cell);
cell = document.createElement("th");
cell.setAttribute("scope", "col");
cell.className = "align-middle";
cell.innerHTML = translations.RK + " (min/km) / <br>" + translations.speed + " (km/h)";
headRow2.appendChild(cell);
let orienteerTotalDistance = 0;
let orienteerTotalTime = 0;
let time, distance;
for (let i = 0; i < orienteerData[1].length; i++) {
let index = i;
let timeCell = document.createElement("td");
timeCell.style.background = "lightgray";
timeCell.setAttribute("scope", "col");
let distanceCell = document.createElement("td");
distanceCell.setAttribute("scope", "col");
let paceCell = document.createElement("td");
paceCell.setAttribute("scope", "col");
if (i > 0) {
time = orienteerData[2][i];
if (time > 0) {
distance = orienteerData[3][i]
timeCell.innerHTML = convertTimetoString(time);
distanceCell.innerHTML = deltaDistanceCalculator(distance,distances[i]);
paceCell.innerHTML = RKCalculator(time,distance) + " / " + speedCalculator(time,distance);
orienteerTotalDistance += distance;
orienteerTotalTime += time;
} else {
timeCell.innerHTML = "--:--";
distanceCell.innerHTML = "-";
paceCell.innerHTML = "--:--";
}
rows[index].appendChild(timeCell);
rows[index].appendChild(distanceCell);
rows[index].appendChild(paceCell);
}
rows[index].appendChild(timeCell);
rows[index].appendChild(distanceCell);
rows[index].appendChild(paceCell);
}
);
let totalTimeCell = document.createElement("th");
totalTimeCell.style.background = "lightgray";
totalTimeCell.setAttribute("scope", "col");
let totalDistanceCell = document.createElement("th");
totalDistanceCell.setAttribute("scope", "col");
let speedMeanCell = document.createElement("th");
speedMeanCell.setAttribute("scope", "col");
totalTimeCell.innerHTML = convertTimetoString(orienteerTotalTime);
totalDistanceCell.innerHTML = deltaDistanceCalculator(orienteerTotalDistance,totalDistance);
speedMeanCell.innerHTML = RKCalculator(orienteerTotalTime,orienteerTotalDistance).toString() + " min/km"
+ "<br>"
+ speedCalculator(orienteerTotalTime,orienteerTotalDistance).toString() + " km/h";
totalsRow.appendChild(totalTimeCell);
totalsRow.appendChild(totalDistanceCell);
totalsRow.appendChild(speedMeanCell);
});
tableElement.appendChild(head);
tableElement.appendChild(body);
......
......@@ -15,7 +15,7 @@ function addTrack(event, map, track) {
});
gpx.addTo(map);
event.target.style.borderColor = color;
return gpx;
return [gpx, color];
}
function removeTrack(event, map, gpx) {
......@@ -23,4 +23,17 @@ function removeTrack(event, map, gpx) {
colorPicker.addColor(color);
gpx.clearLayers();
event.target.style.borderColor = "white";
}
function clearTracks(){
for (let traces of Object.values(gpxDictionary)){
let gpx = traces[0];
let color = traces[1];
colorPicker.addColor(color);
gpx.clearLayers();
}
document.querySelectorAll("button").forEach( el => {
el.style.borderColor = "white";
});
gpxDictionary = {};
}
\ No newline at end of file
......@@ -70,7 +70,7 @@
</div>
</nav>
<div id="nav-sidebar" style="display: none; position: fixed; right: 0; top: 50pt; min-width: 200px;height: 100%; background-color: #FF671F; z-index: 999;">
<div id="nav-sidebar" style="display: none; position: fixed; right: 0; top: 50pt; min-width: 200px;height: 100%; background-color: #FF671F; z-index: 10000;">
<ul class="nav flex-column side-nav" id="small-screen-visitor-nav">
<li class="nav-item">
<a class="nav-link navbar-item" href="{{ path('worldmap') }}">{% trans %}menu.item.courses{% endtrans %}</a>
......
......@@ -48,12 +48,25 @@
<script src="{{ asset('/public/leaflet/easy-button.js') }}"></script>
<script>
let translations = {
'start' : '{{ 'timeSheet.start' | trans | escape('js') }}',
'finish' : '{{ 'timeSheet.finish' | trans | escape('js') }}',
'duration' : '{{ 'timeSheet.duration' | trans | escape('js') }}',
'distance' : '{{ 'timeSheet.distance' | trans | escape('js') }}',
'controlPoint' : '{{ 'timeSheet.control.point' | trans | escape('js') }}',
'length' : '{{ 'timeSheet.length' | trans | escape('js') }}',
'RK' : '{{ 'timeSheet.RK' | trans | escape('js') }}',
'totals' : '{{ 'timeSheet.totals' | trans | escape('js') }}',
'mean' : '{{ 'timeSheet.mean' | trans | escape('js') }}',
'speed' : '{{ 'timeSheet.speed' | trans | escape('js') }}',
}
const colorPicker = new ColorPicker();
const tableEnable = false;
const gpxDictionary = {};
let gpxDictionary = {};
const buttonDictionary = {};
let divLeaflet, map, overlay;
let timeSheetData = [];
let displayedFormat = 0;
function showMap() {
let xhr = new XMLHttpRequest();
......@@ -133,14 +146,18 @@
trackButton.addEventListener("click", function (event) {
const element = event.target;
if (!gpxDictionary[element.value]) {
gpxDictionary[element.value] = addTrack(event, map, gpxTrace);
if (courseFormat === 0) {
addTimeSheet(element.innerHTML, punchedPoints, splitTimes, distances, paces);
if (courseFormat === 1 || (courseFormat === 0 && displayedFormat === 1)) {
displayedFormat = courseFormat;
clearTimeSheet();
clearTracks();
clearDownloadButton(document.getElementById("files-tab"));
}
gpxDictionary[element.value] = addTrack(event, map, gpxTrace);
addTimeSheet(element.innerHTML, punchedPoints, splitTimes, distances, paces);
buttonDictionary[element.value] = addDownloadButton(event, element.innerHTML, gpxTrace, document.getElementById("files-tab"));
} else {
let gpxLayer = gpxDictionary[element.value];
removeTrack(event, map, gpxLayer, gpxTrace);
let gpxLayer = gpxDictionary[element.value][0];
removeTrack(event, map, gpxLayer);
removeTimeSheet(event, element.innerHTML);
removeDownloadButton(document.getElementById("files-tab"), buttonDictionary[element.value]);
delete gpxDictionary[element.value];
......
......@@ -1105,6 +1105,46 @@ of Computer Science.</target>
<source>my_event.return.my_event</source>
<target>back to my event list</target>
</trans-unit>
<trans-unit id="64aRO2a" resname="timeSheet.start">
<source>timeSheet.start</source>
<target>Start</target>
</trans-unit>
<trans-unit id="FqCFtPC" resname="timeSheet.finish">
<source>timeSheet.finish</source>
<target>Finish</target>
</trans-unit>
<trans-unit id="g5gXHwR" resname="timeSheet.duration">
<source>timeSheet.duration</source>
<target>Duration</target>
</trans-unit>
<trans-unit id="VC5azBS" resname="timeSheet.distance">
<source>timeSheet.distance</source>
<target>Distance</target>
</trans-unit>
<trans-unit id="5TdSOoe" resname="timeSheet.control.point">
<source>timeSheet.control.point</source>
<target>Control point</target>
</trans-unit>
<trans-unit id="RvEzuX9" resname="timeSheet.length">
<source>timeSheet.length</source>
<target>Length</target>
</trans-unit>
<trans-unit id="lhyW0rQ" resname="timeSheet.RK">
<source>timeSheet.RK</source>
<target>RK</target>
</trans-unit>
<trans-unit id="fHxCRLv" resname="timeSheet.totals">
<source>timeSheet.totals</source>
<target>Totals</target>
</trans-unit>
<trans-unit id="_lItc_M" resname="timeSheet.mean">
<source>timeSheet.mean</source>
<target>on average</target>
</trans-unit>
<trans-unit id="_PH8Bsa" resname="timeSheet.speed">
<source>timeSheet.speed</source>
<target>Speed</target>
</trans-unit>
</body>
</file>
</xliff>
......@@ -1209,6 +1209,46 @@ de l’Informatique.</target>
<source>my_event.return.my_event</source>
<target>retour à ma liste d'événements</target>
</trans-unit>
<trans-unit id="64aRO2a" resname="timeSheet.start">
<source>timeSheet.start</source>
<target>Départ</target>
</trans-unit>
<trans-unit id="FqCFtPC" resname="timeSheet.finish">
<source>timeSheet.finish</source>
<target>Arrivée</target>
</trans-unit>
<trans-unit id="g5gXHwR" resname="timeSheet.duration">
<source>timeSheet.duration</source>
<target>Durée</target>
</trans-unit>
<trans-unit id="VC5azBS" resname="timeSheet.distance">
<source>timeSheet.distance</source>
<target>Distance parcourue</target>
</trans-unit>
<trans-unit id="5TdSOoe" resname="timeSheet.control.point">
<source>timeSheet.control.point</source>
<target>Poste</target>
</trans-unit>
<trans-unit id="RvEzuX9" resname="timeSheet.length">
<source>timeSheet.length</source>
<target>Longueur</target>
</trans-unit>
<trans-unit id="lhyW0rQ" resname="timeSheet.RK">
<source>timeSheet.RK</source>
<target>RK</target>
</trans-unit>
<trans-unit id="fHxCRLv" resname="timeSheet.totals">
<source>timeSheet.totals</source>
<target>Totaux</target>
</trans-unit>
<trans-unit id="_lItc_M" resname="timeSheet.mean">
<source>timeSheet.mean</source>
<target>en moyenne</target>
</trans-unit>
<trans-unit id="_PH8Bsa" resname="timeSheet.speed">
<source>timeSheet.speed</source>
<target>Vitesse</target>
</trans-unit>
</body>
</file>
</xliff>
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