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

Problems can be accepted or rejected. Draw can go to the end

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello
2023-03-25 06:21:39 +01:00
parent e90005b192
commit cebe977d49
4 changed files with 282 additions and 26 deletions

View File

@ -20,6 +20,14 @@ function drawProblem(tid) {
sockets[tid].send(JSON.stringify({'type': 'draw_problem'}))
}
function acceptProblem(tid) {
sockets[tid].send(JSON.stringify({'type': 'accept'}))
}
function rejectProblem(tid) {
sockets[tid].send(JSON.stringify({'type': 'reject'}))
}
function showNotification(title, body, timeout = 5000) {
let notif = new Notification(title, {'body': body, 'icon': "/static/tfjm.svg"})
if (timeout)
@ -181,7 +189,7 @@ document.addEventListener('DOMContentLoaded', () => {
diceDiv.parentElement.style.order = c.toString()
c += 1
let teamLiId = `recap-team-${team}`
let teamLiId = `recap-${tournament.id}-round-${round}-team-${team}`
let teamLi = document.getElementById(teamLiId)
if (teamLi === null) {
@ -193,7 +201,7 @@ document.addEventListener('DOMContentLoaded', () => {
teamList.append(teamLi)
}
let acceptedDivId = `recap-team-${team}-accepted`
let acceptedDivId = `recap-${tournament.id}-round-${round}-team-${team}-accepted`
let acceptedDiv = document.getElementById(acceptedDivId)
if (acceptedDiv === null) {
acceptedDiv = document.createElement('div')
@ -203,7 +211,7 @@ document.addEventListener('DOMContentLoaded', () => {
teamLi.append(acceptedDiv)
}
let rejectedDivId = `recap-team-${team}-rejected`
let rejectedDivId = `recap-${tournament.id}-round-${round}-team-${team}-rejected`
let rejectedDiv = document.getElementById(rejectedDivId)
if (rejectedDiv === null) {
rejectedDiv = document.createElement('div')
@ -402,11 +410,38 @@ document.addEventListener('DOMContentLoaded', () => {
if (poolLi !== null)
poolLi.classList.add('list-group-item-success')
let teamLi = document.getElementById(`recap-team-${team}`)
let teamLi = document.getElementById(`recap-${tournament.id}-round-${round}-team-${team}`)
if (teamLi !== null)
teamLi.classList.add('list-group-item-info')
}
function setProblemAccepted(round, team, problem) {
let recapDiv = document.getElementById(`recap-${tournament.id}-round-${round}-team-${team}-accepted`)
recapDiv.classList.remove('text-bg-warning')
recapDiv.classList.add('text-bg-success')
recapDiv.textContent = `${team} 📃 ${problem}`
let tableSpan = document.getElementById(`table-${tournament.id}-round-${round}-problem-${team}`)
tableSpan.textContent = problem
}
function setProblemRejected(round, team, rejected) {
let recapDiv = document.getElementById(`recap-${tournament.id}-round-${round}-team-${team}-rejected`)
recapDiv.textContent = `🗑️ ${rejected.join(', ')}`
if (rejected.length >= 4) {
// TODO Fix this static value
let penaltyDiv = document.getElementById(`recap-${tournament.id}-round-${round}-team-${team}-penalty`)
if (penaltyDiv === null) {
penaltyDiv = document.createElement('div')
penaltyDiv.id = `recap-${tournament.id}-round-${round}-team-${team}-penalty`
penaltyDiv.classList.add('badge', 'rounded-pill', 'text-bg-info')
recapDiv.parentNode.append(penaltyDiv)
}
penaltyDiv.textContent = `${0.5 * (rejected.length - 3)}`
}
}
socket.addEventListener('message', e => {
const data = JSON.parse(e.data)
console.log(data)
@ -445,6 +480,12 @@ document.addEventListener('DOMContentLoaded', () => {
case 'set_active':
updateActiveRecap(data.round, data.poule, data.team)
break
case 'set_problem':
setProblemAccepted(data.round, data.team, data.problem)
break
case 'reject_problem':
setProblemRejected(data.round, data.team, data.rejected)
break
}
})