|
|
|
@ -81,7 +81,12 @@ |
|
|
|
<td>{% if a.temps %}{{ a.temps|seconds_to_hms }}{% endif %}</td> |
|
|
|
<td>{% if a.temps %}{{ a.temps|seconds_to_hms }}{% endif %}</td> |
|
|
|
</tr> |
|
|
|
</tr> |
|
|
|
{% empty %} |
|
|
|
{% empty %} |
|
|
|
<tr><td colspan="4">Aucun coureur arrivé.</td></tr> |
|
|
|
<tr> |
|
|
|
|
|
|
|
<td>Aucun coureur arrivé.</td> |
|
|
|
|
|
|
|
<td></td> |
|
|
|
|
|
|
|
<td></td> |
|
|
|
|
|
|
|
<td></td> |
|
|
|
|
|
|
|
</tr> |
|
|
|
{% endfor %} |
|
|
|
{% endfor %} |
|
|
|
</tbody> |
|
|
|
</tbody> |
|
|
|
</table> |
|
|
|
</table> |
|
|
|
@ -104,14 +109,26 @@ const wsUrl = `${wsScheme}://${window.location.host}/ws/course/${courseId}/`; |
|
|
|
const socket = new WebSocket(wsUrl); |
|
|
|
const socket = new WebSocket(wsUrl); |
|
|
|
|
|
|
|
|
|
|
|
socket.onmessage = function(e) { |
|
|
|
socket.onmessage = function(e) { |
|
|
|
// Recharge juste le tbody via AJAX |
|
|
|
// Ajoute dynamiquement la nouvelle ligne reçue via WebSocket |
|
|
|
fetch(window.location.href, { headers: { 'X-Requested-With': 'XMLHttpRequest' } }) |
|
|
|
let data; |
|
|
|
.then(response => response.text()) |
|
|
|
try { |
|
|
|
.then(html => { |
|
|
|
data = JSON.parse(e.data); |
|
|
|
const table = document.getElementById('arriveesTable').getElementsByTagName('tbody')[0]; |
|
|
|
} catch { |
|
|
|
table.innerHTML = html; |
|
|
|
return; |
|
|
|
$('#arriveesTable').DataTable(); |
|
|
|
} |
|
|
|
}); |
|
|
|
// Vérifie le format des données reçues |
|
|
|
|
|
|
|
let rowData; |
|
|
|
|
|
|
|
if (Array.isArray(data)) { |
|
|
|
|
|
|
|
rowData = data; |
|
|
|
|
|
|
|
} else if (typeof data === 'object' && data !== null) { |
|
|
|
|
|
|
|
// Transforme l'objet en tableau dans l'ordre attendu |
|
|
|
|
|
|
|
rowData = [data.rang, data.nom || (data.coureur && data.coureur.nom), data.classe || (data.coureur && data.coureur.classe), data.temps]; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// Format inconnu, ignore |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var dt = $('#arriveesTable').DataTable(); |
|
|
|
|
|
|
|
dt.row.add(rowData).draw(false); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Modal confirmation fin de course |
|
|
|
// Modal confirmation fin de course |
|
|
|
|