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

82 lines
1.7 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-03-30 12:50:21 +00:00
2022-04-21 12:41:19 +00:00
document.addEventListener('DOMContentLoaded', () => {
new ResultService();
2022-04-05 13:53:41 +00:00
});
2022-04-21 12:41:19 +00:00
class ResultService
2022-03-30 12:50:21 +00:00
{
2022-04-21 12:41:19 +00:00
constructor()
{
this.hash = 0;
this.alertbox = document.getElementById("alert");
this.table = document.getElementById("ranking-table");
2022-03-30 12:50:21 +00:00
2022-04-21 12:41:19 +00:00
this.#loop();
}
2022-03-30 08:51:46 +00:00
2022-04-21 12:41:19 +00:00
async #loop(self)
2022-03-30 08:51:46 +00:00
{
2022-04-21 12:41:19 +00:00
try {
await this.#updateTable();
this.alertbox.classList.add("hidden");
} catch (error) {
console.log(error);
this.alertbox.innerHTML = "<b>Noe gikk galt: </b>" + error;
this.alertbox.classList.remove("hidden");
}
setTimeout(() => {
this.#loop();
}, 1000);
2022-03-30 08:51:46 +00:00
}
2022-04-21 12:41:19 +00:00
async #updateTable()
{
let response = await fetch("../api/v1/race/sync.php?h=" + this.hash);
if (response.status === 204)
{
return;
}
2022-03-30 08:51:46 +00:00
2022-04-21 12:41:19 +00:00
let json = await response.json();
2022-03-30 08:51:46 +00:00
2022-04-21 12:41:19 +00:00
this.hash = json.hash;
2022-03-30 12:50:21 +00:00
2022-04-21 12:41:19 +00:00
let data = json.data;
2022-04-04 09:09:58 +00:00
2022-04-21 12:41:19 +00:00
let tableHTML = "";
tableHTML += "<table>";
tableHTML += "<tr>";
tableHTML += "<th>Navn</th>";
tableHTML += "<th>Bestetid</th>";
tableHTML += "</tr>";
2022-04-04 09:09:58 +00:00
2022-04-21 12:41:19 +00:00
data.forEach(element => {
tableHTML += "<tr>";
tableHTML += "<td>" + element.name + "</td>";
tableHTML += "<td>" + element.date + "</td>";
tableHTML += "</tr>";
});
2022-04-04 09:09:58 +00:00
2022-04-21 12:41:19 +00:00
tableHTML += "<table>";
2022-04-04 16:08:39 +00:00
2022-04-21 12:41:19 +00:00
this.table.innerHTML = tableHTML;
}
2022-03-30 08:51:46 +00:00
}
2022-04-21 12:41:19 +00:00
2022-03-21 11:28:18 +00:00
</script>