1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-06-22 22:38:24 +02:00

Add Abort button

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello
2023-03-24 12:29:24 +01:00
parent c9fcfcf498
commit 6b5c630048
4 changed files with 172 additions and 146 deletions

View File

@ -8,6 +8,10 @@ const sockets = {}
const messages = document.getElementById('messages')
function abortDraw(tid) {
sockets[tid].send(JSON.stringify({'type': 'abort'}))
}
function drawDice(tid, trigram = null) {
sockets[tid].send(JSON.stringify({'type': 'dice', 'trigram': trigram}))
}
@ -55,9 +59,34 @@ document.addEventListener('DOMContentLoaded', () => {
document.getElementById(`messages-${tournament.id}`).innerHTML = info
}
function drawStart() {
function drawStart(teams) {
document.getElementById(`banner-not-started-${tournament.id}`).classList.add('d-none')
document.getElementById(`draw-content-${tournament.id}`).classList.remove('d-none')
let dicesDiv = document.getElementById(`dices-${tournament.id}`)
for (let team of teams) {
let col = document.createElement('div')
col.classList.add('col-md-1')
dicesDiv.append(col)
let diceDiv = document.createElement('div')
diceDiv.id = `dice-${tournament.id}-${team}`
diceDiv.classList.add('badge', 'rounded-pill', 'text-bg-warning')
if (document.getElementById(`abort-${tournament.id}`) !== null) {
// Check if this is a volunteer
diceDiv.onclick = (e) => drawDice(tournament.id, team)
}
diceDiv.textContent = `${team} 🎲 ??`
col.append(diceDiv)
}
}
function drawAbort() {
document.getElementById(`banner-not-started-${tournament.id}`).classList.remove('d-none')
document.getElementById(`draw-content-${tournament.id}`).classList.add('d-none')
document.getElementById(`dices-${tournament.id}`).innerHTML = ""
document.getElementById(`recap-${tournament.id}-round-list`).innerHTML = ""
document.getElementById(`tables-${tournament.id}`).innerHTML = ""
}
function updateDiceInfo(trigram, result) {
@ -186,6 +215,9 @@ document.addEventListener('DOMContentLoaded', () => {
}
for (let poule of poules) {
if (poule.teams.length === 0)
continue
let pouleTable = document.getElementById(`table-${tournament.id}-${round}-${poule.letter}`)
if (pouleTable === null) {
// Create table
@ -219,7 +251,7 @@ document.addEventListener('DOMContentLoaded', () => {
teamTh.textContent = "Équipe"
phaseTr.append(teamTh)
for (let i = 1; i <= 3; ++i) {
for (let i = 1; i <= (poule.teams.length === 4 ? 4 : 3); ++i) {
let phaseTh = document.createElement('th')
phaseTh.classList.add('text-center')
if (poule.teams.length === 5 && i < 3)
@ -246,7 +278,7 @@ document.addEventListener('DOMContentLoaded', () => {
for (let team of poule.teams) {
let problemTh = document.createElement('th')
problemTh.classList.add('text-center')
problemTh.innerHTML = `Problème <span id="table-${tournament.id}-round-${round}-problem-${team}">?</span>`
problemTh.innerHTML = `Pb. <span id="table-${tournament.id}-round-${round}-problem-${team}">?</span>`
problemTr.append(problemTh)
}
@ -266,17 +298,18 @@ document.addEventListener('DOMContentLoaded', () => {
let defenderTd = document.createElement('td')
defenderTd.classList.add('text-center')
defenderTd.innerText = 'Défenseur⋅se'
defenderTd.innerText = 'Déf'
let opponentTd = document.createElement('td')
opponentTd.classList.add('text-center')
opponentTd.innerText = 'Opposant⋅e'
opponentTd.innerText = 'Opp'
let reporterTd = document.createElement('td')
reporterTd.classList.add('text-center')
reporterTd.innerText = 'Rapporteur⋅e'
reporterTd.innerText = 'Rap'
let emptyTd = document.createElement('td')
let emptyTd2 = document.createElement('td')
if (poule.teams.length === 3) {
@ -311,19 +344,19 @@ document.addEventListener('DOMContentLoaded', () => {
else if (poule.teams.length === 5) {
switch (i) {
case 0:
teamTr.append(defenderTd, emptyTd, opponentTd, reporterTd, emptyTd)
teamTr.append(defenderTd, emptyTd, opponentTd, reporterTd, emptyTd2)
break
case 1:
teamTr.append(emptyTd, defenderTd, reporterTd, emptyTd, opponentTd)
teamTr.append(emptyTd, defenderTd, reporterTd, emptyTd2, opponentTd)
break
case 2:
teamTr.append(opponentTd, emptyTd, defenderTd, emptyTd, reporterTd)
teamTr.append(opponentTd, emptyTd, defenderTd, emptyTd2, reporterTd)
break
case 3:
teamTr.append(reporterTd, opponentTd, emptyTd, defenderTd, emptyTd)
teamTr.append(reporterTd, opponentTd, emptyTd, defenderTd, emptyTd2)
break
case 4:
teamTr.append(emptyTd, reporterTd, emptyTd, opponentTd, defenderTd)
teamTr.append(emptyTd, reporterTd, emptyTd2, opponentTd, defenderTd)
break
}
}
@ -369,7 +402,10 @@ document.addEventListener('DOMContentLoaded', () => {
setInfo(data.information)
break
case 'draw_start':
drawStart()
drawStart(data.trigrams)
break
case 'abort':
drawAbort()
break
case 'dice':
updateDiceInfo(data.team, data.result)