This commit is contained in:
William 2022-04-04 09:09:58 +00:00
parent a1d1123894
commit b0e23a9d61
2 changed files with 45 additions and 9 deletions

View File

@ -1,11 +1,9 @@
<h1>Live resultater</h1> <h1>Live resultater</h1>
<br> <br>
<table id ="table">
<tr> <div id="ranking-table">
<th>Some shit</th>
<th>Some shit</th> </div>
</tr>
</table>
<script> <script>
var hash = 0; var hash = 0;
@ -34,6 +32,25 @@ async function updateTable()
let data = json.data; let data = json.data;
let table_html = "";
table_html += "<table>";
table_html += "<tr>";
table_html += "<th>Navn</th>";
table_html += "<th>Runder</th>";
table_html += "<th>Bestetid</th>";
table_html += "</tr>";
data.forEach(element => {
table_html += "<tr>";
table_html += "<td>" + element.name + "</td>";
table_html += "<td>" + element.rounds + "</td>";
table_html += "<td>" + element.bestTime + "</td>";
table_html += "</tr>";
});
table_html += "<table>";
document.getElementById("ranking-table").innerHTML = table_html;
} }
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {

View File

@ -7,20 +7,39 @@
use App\Teamtable\TeamMapper; use App\Teamtable\TeamMapper;
use App\Timetable\TimeMapper; use App\Timetable\TimeMapper;
$teamMapper = new TimeMapper($app->database->conn); $teamMapper = new TeamMapper($app->database->conn);
$timeMapper = new TimeMapper($app->database->conn); $timeMapper = new TimeMapper($app->database->conn);
$prev_hash = (int)filter_input(INPUT_GET, 'h'); $prev_hash = (int)filter_input(INPUT_GET, 'h');
$data = [];
$times = $timeMapper->getAll(); $times = $timeMapper->getAll();
$hash = crc32(serialize($timeMapper->getAll())); foreach ($times as $time)
{
$team = $teamMapper->get($time->teamId);
if (!$team)
{
return;
}
$row = [
"name" => $team->name,
"rounds" => $team->rounds,
"bestTime" => $team->bestTime
];
array_push($data, $row);
}
$hash = crc32(serialize($data));
if ($prev_hash !== $hash) if ($prev_hash !== $hash)
{ {
$app->api([ $app->api([
"hash" => $hash, "hash" => $hash,
"data" => $times "data" => $data
]); ]);
} }
// return nothing // return nothing