From ed1fdecb2aca9aabe78cc6ae21270f912772f24b Mon Sep 17 00:00:00 2001 From: scayac Date: Mon, 29 Sep 2025 22:34:34 +0200 Subject: [PATCH] =?UTF-8?q?Correction=20bug=20tableau=20r=C3=A9sultats=20q?= =?UTF-8?q?uand=20arriv=C3=A9e=20en=20direct=20Modifications=20ic=C3=B4nes?= =?UTF-8?q?=20boutons=20interface?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/course_detail.html | 35 ++++++++++++++++++++++++++--------- templates/main.html | 10 ++++++---- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/templates/course_detail.html b/templates/course_detail.html index bceb24b..4e103fa 100644 --- a/templates/course_detail.html +++ b/templates/course_detail.html @@ -81,7 +81,12 @@ {% if a.temps %}{{ a.temps|seconds_to_hms }}{% endif %} {% empty %} - Aucun coureur arrivé. + + Aucun coureur arrivé. + + + + {% endfor %} @@ -104,14 +109,26 @@ const wsUrl = `${wsScheme}://${window.location.host}/ws/course/${courseId}/`; const socket = new WebSocket(wsUrl); socket.onmessage = function(e) { - // Recharge juste le tbody via AJAX - fetch(window.location.href, { headers: { 'X-Requested-With': 'XMLHttpRequest' } }) - .then(response => response.text()) - .then(html => { - const table = document.getElementById('arriveesTable').getElementsByTagName('tbody')[0]; - table.innerHTML = html; - $('#arriveesTable').DataTable(); - }); + // Ajoute dynamiquement la nouvelle ligne reçue via WebSocket + let data; + try { + data = JSON.parse(e.data); + } catch { + return; + } + // 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 diff --git a/templates/main.html b/templates/main.html index 7aa641c..6336688 100644 --- a/templates/main.html +++ b/templates/main.html @@ -38,18 +38,20 @@
-  Générer les dossards +   +
{% csrf_token %}