This commit is contained in:
William 2022-04-21 14:41:19 +02:00
parent 79893ba3dd
commit 941e1a8965
2 changed files with 54 additions and 50 deletions

View File

@ -12,31 +12,41 @@ Laster inn...
</div>
<script>
let hash = 0;
let alertbox = document.getElementById("alert");
document.addEventListener('DOMContentLoaded', function() {
loop();
document.addEventListener('DOMContentLoaded', () => {
new ResultService();
});
async function loop()
class ResultService
{
try {
await updateTable();
alertbox.classList.add("hidden");
} catch (error) {
alertbox.innerHTML = "<b>Noe gikk galt: </b>" + error;
alertbox.classList.remove("hidden");
constructor()
{
this.hash = 0;
this.alertbox = document.getElementById("alert");
this.table = document.getElementById("ranking-table");
this.#loop();
}
setTimeout(function() {
loop();
}, 1000);
}
async #loop(self)
{
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");
}
async function updateTable()
{
let response = await fetch("../api/v1/race/sync.php?h=" + hash);
setTimeout(() => {
this.#loop();
}, 1000);
}
async #updateTable()
{
let response = await fetch("../api/v1/race/sync.php?h=" + this.hash);
if (response.status === 204)
{
@ -45,28 +55,28 @@ async function updateTable()
let json = await response.json();
hash = json.hash;
this.hash = json.hash;
let data = json.data;
let table_html = "";
table_html += "<table>";
table_html += "<tr>";
table_html += "<th>Navn</th>";
table_html += "<th>Bestetid</th>";
table_html += "</tr>";
let tableHTML = "";
tableHTML += "<table>";
tableHTML += "<tr>";
tableHTML += "<th>Navn</th>";
tableHTML += "<th>Bestetid</th>";
tableHTML += "</tr>";
data.forEach(element => {
table_html += "<tr>";
table_html += "<td>" + element.n + "</td>";
table_html += "<td>" + element.d + "</td>";
table_html += "</tr>";
tableHTML += "<tr>";
tableHTML += "<td>" + element.name + "</td>";
tableHTML += "<td>" + element.date + "</td>";
tableHTML += "</tr>";
});
table_html += "<table>";
tableHTML += "<table>";
console.log(data);
document.getElementById("ranking-table").innerHTML = table_html;
this.table.innerHTML = tableHTML;
}
}
</script>

View File

@ -22,15 +22,9 @@ foreach ($times as $time)
{
$team = $team_mapper->get($time->team_id);
if (!$team)
{
// this should not happen as related times should be deleted with the team
#continue;
}
$row = [
"n" => $team->name,
"d" => $time->date->getTimestamp()
"name" => $team->name,
"date" => $time->date->getTimestamp()
];
array_push($data, $row);