This repository has been archived on 2023-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
web/app/view/pages/race/live.php

72 lines
1.4 KiB
PHP
Raw Normal View History

2022-04-20 09:02:19 +00:00
<div id="alert" class="alert danger hidden" role="alert"></div>
2022-03-21 11:28:18 +00:00
<h1>Live resultater</h1>
2022-03-23 13:03:33 +00:00
<br>
2022-04-04 09:09:58 +00:00
2022-04-04 16:08:39 +00:00
<noscript>
Denne siden krever JavaScript
</noscript>
2022-04-04 09:09:58 +00:00
2022-04-04 16:08:39 +00:00
<div id="ranking-table">
Laster inn...
2022-04-04 09:09:58 +00:00
</div>
2022-03-21 11:28:18 +00:00
2022-03-23 09:08:36 +00:00
<script>
2022-04-20 09:02:19 +00:00
let hash = 0;
let alertbox = document.getElementById("alert");
2022-03-30 12:50:21 +00:00
2022-04-05 13:53:41 +00:00
document.addEventListener('DOMContentLoaded', function() {
loop();
});
async function loop()
2022-03-30 12:50:21 +00:00
{
2022-04-05 13:53:41 +00:00
try {
await updateTable();
2022-04-20 09:02:19 +00:00
alertbox.classList.add("hidden");
2022-04-05 13:53:41 +00:00
} catch (error) {
2022-04-20 09:02:19 +00:00
alertbox.innerHTML = "<b>Noe gikk galt: </b>" + error;
alertbox.classList.remove("hidden");
2022-04-05 13:53:41 +00:00
}
2022-03-30 12:50:21 +00:00
2022-04-05 13:53:41 +00:00
setTimeout(function() {
loop();
}, 1000);
2022-03-30 12:50:21 +00:00
}
async function updateTable()
2022-03-23 13:03:33 +00:00
{
2022-04-14 20:59:42 +00:00
let response = await fetch("../api/v1/race/sync.php?h=" + hash);
2022-03-30 08:51:46 +00:00
if (response.status === 204)
{
return;
}
2022-03-30 12:50:21 +00:00
let json = await response.json();
2022-03-30 08:51:46 +00:00
hash = json.hash;
2022-03-30 12:50:21 +00:00
let data = json.data;
2022-04-04 09:09:58 +00:00
let table_html = "";
table_html += "<table>";
table_html += "<tr>";
table_html += "<th>Navn</th>";
table_html += "<th>Bestetid</th>";
table_html += "</tr>";
data.forEach(element => {
table_html += "<tr>";
2022-04-08 12:24:16 +00:00
table_html += "<td>" + element.n + "</td>";
table_html += "<td>" + element.d + "</td>";
2022-04-04 09:09:58 +00:00
table_html += "</tr>";
});
table_html += "<table>";
2022-04-04 16:08:39 +00:00
console.log(data);
2022-04-04 09:09:58 +00:00
document.getElementById("ranking-table").innerHTML = table_html;
2022-03-30 08:51:46 +00:00
}
2022-03-21 11:28:18 +00:00
</script>