class ResultService { constructor(alertBox, rankingTable, endpoint) { this.alertBox = alertBox; this.rankingTable = rankingTable; this.endpoint = endpoint; this.hash = 0; this.loop(); } async loop() { try { await this.updateTable(); this.alertBox.classList.add("hidden"); } catch (error) { console.log(error); this.alertBox.innerHTML = "Noe gikk galt: " + error; this.alertBox.classList.remove("hidden"); } setTimeout(() => { this.loop(); }, 1000); } async updateTable() { let response = await fetch(this.endpoint + this.hash); if (response.status === 204) { return; } let json = await response.json(); this.hash = json.hash; let data = json.data; data.times = data.times.reverse(); let tableHTML = ""; tableHTML += ""; tableHTML += ""; tableHTML += ""; tableHTML += ""; tableHTML += ""; tableHTML += ""; tableHTML += ""; tableHTML += ""; let iterator = 0; data.times.forEach(element => { iterator++; tableHTML += ""; tableHTML += ""; tableHTML += ""; tableHTML += ""; tableHTML += ""; tableHTML += ""; tableHTML += ""; }); tableHTML += "
#LagBedriftTidRunder
" + iterator + "" + data.map.team[element.id].name + "" + data.map.team[element.id].company + "" + element.time + "" + data.map.team[element.id].rounds+ "
"; this.rankingTable.innerHTML = tableHTML; } }