traque/templates/admin.html.hbs

222 lines
8 KiB
Handlebars
Raw Normal View History

2024-06-10 09:43:35 +02:00
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Traque | Client admin</title>
<!-- LEAFLET INCLUDE -->
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.8.0/dist/leaflet.css"
integrity="sha512-hoalWLoI8r4UszCkZ5kL8vayOGVae1oxXe/2A4AO6J9+580uKHDO3JdHb7NzwwzK5xr/Fs0W40kiNHxM9vyTtQ=="
crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.8.0/dist/leaflet.js"
integrity="sha512-BB3hKbKWOc9Ez/TAwyWxNXeoV9c1v6FIeYiBieIWkpLjauysF18NzgR1MBNBXf8/KABdlkX68nAhlwcDFLGPCQ=="
crossorigin=""></script>
<style type="text/css">
#map {
position: fixed;
top: 0px;
left: 0px;
height: 100%;
width: 50%;
}
#right {
position: fixed;
width: 49%;
height: 98%;
top: 1%;
right: 0.5%;
}
.vieux { color: DarkOrchid; }
.code_count { width: 90%; }
.tableFixHead { overflow: auto; height: 60%; }
.tableFixHead thead th { position: sticky; top: 0; z-index: 1; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 8px 16px; }
th { background: Grey; }
tr:nth-child(even) { background-color: Silver; }
</style>
<script type="text/javascript" src="utils.js"></script>
</head>
<body>
<div id="map"></div>
<div id="right">
<div class="tableFixHead">
<table>
<thead><tr>
<th>Nom</th>
<th>Mallette</th>
<th>Tracker</th>
<th>Invisible</th>
<th>Brouillé</th>
<th>Code Invisibilité</th>
<th>Code Brouillage</th>
<th>Couleur</th>
<!-- <th>Last Update</th> -->
</tr></thead>
<tbody id="teamInfos">
</tbody>
</table>
</div>
<input id="popup"/><button id="sendPopup">Send popup to all clients</button><br/>
<br/>
<a href="https://dgnum.eu"><img src="/dgnum-logo.png" height=50px /></a><br/>
<span style="font-size: 0.8em">Merci à la <a href="https://dgnum.eu">Délégation Générale NUMérique de l'ENS</a>, qui héberge ce site.</span>
</div>
<script type="text/javascript">
setup_map();
// map.on("dblclick", function(data){
// socket.emit("newTracker", {"position": [data.latlng.lat, data.latlng.lng]});
// });
var equipes = {};
var equipes_markers = {};
var info_table = document.getElementById("teamInfos");
function show_update(id){
var equipe = equipes[id];
var state = equipe.state;
if("Vieux" in state){
state = state.Vieux;
document.getElementById(`${id}.invisibility`).checked = state.invisible;
document.getElementById(`${id}.color`).value = state.color;
} else {
state = state.Conscrit;
document.getElementById(`${id}.mallette`).checked = state.mallette;
document.getElementById(`${id}.invisibility`).checked = state.invisible;
document.getElementById(`${id}.blurred`).checked = state.blurred;
document.getElementById(`${id}.tracker`).checked = state.captured;
document.getElementById(`${id}.bonus.invisi`).value = state.invisibility_codes;
document.getElementById(`${id}.bonus.blurred`).value = state.blur_codes;
}
equipes_markers[id].setLatLng(equipe.pos);
equipes_markers[id].setIcon(icons[equipe.color]);
}
evtSource = new EventSource("/admin/events?tok={{tok}}");
function update(data) {
{{#if dbg}}console.log(data);{{/if}}
var id = data.id;
if(!(id in equipes)){
var row = "";
if("Vieux" in data.state){
row = `<td class="vieux">${data.name}</td>`;
row += `<td></td>`;
row += `<td></td>`;
row += `<td><input type="checkbox"
id="${id}.invisibility"
onchange="modifyVieux('${id}')" /></td>`;
row += `<td></td>`;
row += `<td></td>`;
row += `<td></td>`;
row += `<td><select id="${id}.color"
onchange="modifyVieux('${id}')" >
<option value=1>1- Tracker</option>
<option value=3>3- <img src="/icons/3.png" height=15px></option>
<option value=4>4- <img src="/icons/4.png" height=15px></option>
<option value=5>5- <img src="/icons/5.png" height=15px></option>
<option value=6>6- <img src="/icons/6.png" height=15px></option>
<option value=7>7- <img src="/icons/7.png" height=15px></option>
<option value=8>8- <img src="/icons/8.png" height=15px></option>
<option value=9>9- <img src="/icons/9.png" height=15px></option>
<option value=10>10- <img src="/icons/10.png" height=15px></option>
<option value=11>11- <img src="/icons/11.png" height=15px></option>
</select></td>`;
} else {
row = `<td class="conscrit">${data.name}</td>`;
row += `<td><input type="checkbox"
id="${id}.mallette"
onchange="modifyConscrit('${id}')" /></td>`
row += `<td><input type="checkbox"
id="${id}.tracker"
onchange="modifyConscrit('${id}')" /></td>`
row += `<td><input type="checkbox"
id="${id}.invisibility"
onchange="modifyConscrit('${id}')" /></td>`;
row += `<td><input type="checkbox"
id="${id}.blurred"
onchange="modifyConscrit('${id}')" /></td>`
row += `<td><input type="number" min="0"
id="${id}.bonus.invisi"
class="code_count"
onchange="modifyConscrit('${id}')" />
</td>`;
row += `<td><input type="number" min="0"
id="${id}.bonus.blurred"
class="code_count"
onchange="modifyConscrit('${id}')" />
</td>`;
row += `<td></td>`;
}
info_table.innerHTML += `<tr>${row}</tr>`
equipes[id] = data;
equipes_markers[id] = L.marker([0,0], {"icon": icons[0] }).addTo(map);
equipes_markers[id].bindPopup(data.name);
setTimeout(function (){
for(i in equipes){
show_update(i);
}
}, 10);
} else {
equipes[id] = data;
show_update(id);
}
};
evtSource.addEventListener("update", (event) => {
data = JSON.parse(event.data);
update(data);
});
evtSource.addEventListener("full_update", (event) => {
data = JSON.parse(event.data);
info_table.innerHTML = "";
equipes = {};
for(i in equipes_markers){
equipes_markers[i].remove();
}
equipes_markers = {};
for (tracked of data) {
update(tracked);
}
});
function modifyVieux(id){
state = {
Vieux: {
invisible: document.getElementById(`${id}.invisibility`).checked,
color: document.getElementById(`${id}.color`).value - 0,
}
};
fetch(`/admin/${id}?tok={{tok}}`, {
method: "PATCH",
body: JSON.stringify(state)
});
}
function modifyConscrit(id){
state = {
Conscrit: {
mallette: document.getElementById(`${id}.mallette`).checked,
invisible: document.getElementById(`${id}.invisibility`).checked,
blurred: document.getElementById(`${id}.blurred`).checked,
captured: document.getElementById(`${id}.tracker`).checked,
invisibility_codes: document.getElementById(`${id}.bonus.invisi`).value - 0,
blur_codes: document.getElementById(`${id}.bonus.blurred`).value - 0,
}
};
fetch(`/admin/${id}?tok={{tok}}`, {
method: "PATCH",
body: JSON.stringify(state)
});
}
</script>
</body>
</html>