2023-03-23 15:17:29 +00:00
|
|
|
(async () => {
|
|
|
|
// check notification permission
|
2023-04-04 17:52:44 +00:00
|
|
|
// This is useful to alert people that they should do something
|
2023-03-23 15:17:29 +00:00
|
|
|
await Notification.requestPermission()
|
|
|
|
})()
|
|
|
|
|
2024-10-20 18:13:49 +00:00
|
|
|
const TFJM = JSON.parse(document.getElementById('TFJM_settings').textContent)
|
|
|
|
const RECOMMENDED_SOLUTIONS_COUNT = TFJM.RECOMMENDED_SOLUTIONS_COUNT
|
2024-06-07 12:18:25 +00:00
|
|
|
|
2023-04-04 17:52:44 +00:00
|
|
|
const problems_count = JSON.parse(document.getElementById('problems_count').textContent)
|
|
|
|
|
2023-03-22 14:24:15 +00:00
|
|
|
const tournaments = JSON.parse(document.getElementById('tournaments_list').textContent)
|
2023-05-11 15:07:53 +00:00
|
|
|
let socket = null
|
2023-03-22 14:24:15 +00:00
|
|
|
|
2023-03-22 17:44:49 +00:00
|
|
|
const messages = document.getElementById('messages')
|
2023-03-22 14:24:15 +00:00
|
|
|
|
2023-04-04 17:52:44 +00:00
|
|
|
/**
|
|
|
|
* Request to abort the draw of the given tournament.
|
|
|
|
* Only volunteers are allowed to do this.
|
|
|
|
* @param tid The tournament id
|
|
|
|
*/
|
2023-03-24 11:29:24 +00:00
|
|
|
function abortDraw(tid) {
|
2023-05-11 15:07:53 +00:00
|
|
|
socket.send(JSON.stringify({'tid': tid, 'type': 'abort'}))
|
2023-03-24 11:29:24 +00:00
|
|
|
}
|
|
|
|
|
2023-04-05 17:22:48 +00:00
|
|
|
/**
|
|
|
|
* Request to cancel the last step.
|
|
|
|
* Only volunteers are allowed to do this.
|
|
|
|
* @param tid The tournament id
|
|
|
|
*/
|
|
|
|
function cancelLastStep(tid) {
|
2023-05-11 15:07:53 +00:00
|
|
|
socket.send(JSON.stringify({'tid': tid, 'type': 'cancel'}))
|
2023-04-05 17:22:48 +00:00
|
|
|
}
|
|
|
|
|
2023-04-04 17:52:44 +00:00
|
|
|
/**
|
|
|
|
* Request to launch a dice between 1 and 100, for the two first steps.
|
|
|
|
* The parameter `trigram` can be specified (by volunteers) to launch a dice for a specific team.
|
|
|
|
* @param tid The tournament id
|
|
|
|
* @param trigram The trigram of the team that a volunteer wants to force the dice launch (default: null)
|
2023-05-19 16:24:01 +00:00
|
|
|
* @param result The forced value. Null if unused (for regular people)
|
2023-04-04 17:52:44 +00:00
|
|
|
*/
|
2023-05-19 16:24:01 +00:00
|
|
|
function drawDice(tid, trigram = null, result = null) {
|
|
|
|
socket.send(JSON.stringify({'tid': tid, 'type': 'dice', 'trigram': trigram, 'result': result}))
|
2023-03-23 15:17:29 +00:00
|
|
|
}
|
|
|
|
|
2024-04-22 21:36:52 +00:00
|
|
|
/**
|
|
|
|
* Fetch the requested dice from the buttons and request to draw it.
|
|
|
|
* Only available for debug purposes and for admins.
|
|
|
|
* @param tid The tournament id
|
|
|
|
*/
|
|
|
|
function drawDebugDice(tid) {
|
|
|
|
let dice_10 = parseInt(document.querySelector(`input[name="debug-dice-${tid}-10"]:checked`).value)
|
|
|
|
let dice_1 = parseInt(document.querySelector(`input[name="debug-dice-${tid}-1"]:checked`).value)
|
|
|
|
let result = (dice_10 + dice_1) || 100
|
|
|
|
let team_div = document.querySelector(`div[id="dices-${tid}"] > div > div[class*="text-bg-warning"]`)
|
|
|
|
let team = team_div.getAttribute("data-team")
|
|
|
|
drawDice(tid, team, result)
|
|
|
|
}
|
|
|
|
|
2023-04-04 17:52:44 +00:00
|
|
|
/**
|
|
|
|
* Request to draw a new problem.
|
|
|
|
* @param tid The tournament id
|
2023-05-19 16:24:01 +00:00
|
|
|
* @param problem The forced problem. Null if unused (for regular people)
|
2023-04-04 17:52:44 +00:00
|
|
|
*/
|
2023-05-19 16:24:01 +00:00
|
|
|
function drawProblem(tid, problem = null) {
|
|
|
|
socket.send(JSON.stringify({'tid': tid, 'type': 'draw_problem', 'problem': problem}))
|
2023-03-24 12:24:44 +00:00
|
|
|
}
|
|
|
|
|
2023-04-04 17:52:44 +00:00
|
|
|
/**
|
|
|
|
* Accept the current proposed problem.
|
|
|
|
* @param tid The tournament id
|
|
|
|
*/
|
2023-03-25 05:21:39 +00:00
|
|
|
function acceptProblem(tid) {
|
2023-05-11 15:07:53 +00:00
|
|
|
socket.send(JSON.stringify({'tid': tid, 'type': 'accept'}))
|
2023-03-25 05:21:39 +00:00
|
|
|
}
|
|
|
|
|
2023-04-04 17:52:44 +00:00
|
|
|
/**
|
|
|
|
* Reject the current proposed problem.
|
|
|
|
* @param tid The tournament id
|
|
|
|
*/
|
2023-03-25 05:21:39 +00:00
|
|
|
function rejectProblem(tid) {
|
2023-05-11 15:07:53 +00:00
|
|
|
socket.send(JSON.stringify({'tid': tid, 'type': 'reject'}))
|
2023-03-25 05:21:39 +00:00
|
|
|
}
|
|
|
|
|
2023-04-04 17:52:44 +00:00
|
|
|
/**
|
|
|
|
* Volunteers can export the draw to make it available for notation.
|
|
|
|
* @param tid The tournament id
|
|
|
|
*/
|
2023-03-25 19:38:58 +00:00
|
|
|
function exportDraw(tid) {
|
2023-05-11 15:07:53 +00:00
|
|
|
socket.send(JSON.stringify({'tid': tid, 'type': 'export'}))
|
2023-03-25 19:38:58 +00:00
|
|
|
}
|
|
|
|
|
2023-04-04 17:52:44 +00:00
|
|
|
/**
|
|
|
|
* Volunteers can make the draw continue for the second round of the final.
|
|
|
|
* @param tid The tournament id
|
|
|
|
*/
|
2023-03-26 09:08:03 +00:00
|
|
|
function continueFinal(tid) {
|
2023-05-11 15:07:53 +00:00
|
|
|
socket.send(JSON.stringify({'tid': tid, 'type': 'continue_final'}))
|
2023-03-26 09:08:03 +00:00
|
|
|
}
|
|
|
|
|
2023-04-04 17:52:44 +00:00
|
|
|
/**
|
|
|
|
* Display a new notification with the given title and the given body.
|
|
|
|
* @param title The title of the notification
|
|
|
|
* @param body The body of the notification
|
|
|
|
* @param timeout The time (in milliseconds) after that the notification automatically closes. 0 to make indefinite. Default to 5000 ms.
|
|
|
|
* @return Notification
|
|
|
|
*/
|
2023-03-23 15:17:29 +00:00
|
|
|
function showNotification(title, body, timeout = 5000) {
|
|
|
|
let notif = new Notification(title, {'body': body, 'icon': "/static/tfjm.svg"})
|
|
|
|
if (timeout)
|
|
|
|
setTimeout(() => notif.close(), timeout)
|
2023-04-04 17:52:44 +00:00
|
|
|
return notif
|
2023-03-23 15:17:29 +00:00
|
|
|
}
|
|
|
|
|
2023-03-22 17:44:49 +00:00
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
2023-03-22 19:41:16 +00:00
|
|
|
if (document.location.hash) {
|
2023-04-04 17:52:44 +00:00
|
|
|
// Open the tab of the tournament that is present in the hash
|
2023-03-22 19:41:16 +00:00
|
|
|
document.querySelectorAll('button[data-bs-toggle="tab"]').forEach(elem => {
|
|
|
|
if ('#' + elem.innerText.toLowerCase() === document.location.hash.toLowerCase()) {
|
|
|
|
elem.click()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-04-04 17:52:44 +00:00
|
|
|
// When a tab is opened, add the tournament name in the hash
|
2023-03-22 19:41:16 +00:00
|
|
|
document.querySelectorAll('button[data-bs-toggle="tab"]').forEach(
|
|
|
|
elem => elem.addEventListener(
|
|
|
|
'click', () => document.location.hash = '#' + elem.innerText.toLowerCase()))
|
|
|
|
|
2023-05-11 15:07:53 +00:00
|
|
|
/**
|
|
|
|
* Add alert message on the top on the interface.
|
|
|
|
* @param message The content of the alert.
|
|
|
|
* @param type The alert type, which is a bootstrap color (success, info, warning, danger,…).
|
|
|
|
* @param timeout The time (in milliseconds) before the alert is auto-closing. 0 to infinitely, default to 5000 ms.
|
|
|
|
*/
|
|
|
|
function addMessage(message, type, timeout = 5000) {
|
|
|
|
const wrapper = document.createElement('div')
|
|
|
|
wrapper.innerHTML = [
|
|
|
|
`<div class="alert alert-${type} alert-dismissible" role="alert">`,
|
|
|
|
`<div>${message}</div>`,
|
|
|
|
'<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>',
|
|
|
|
].join('\n')
|
|
|
|
messages.append(wrapper)
|
|
|
|
|
|
|
|
if (timeout)
|
|
|
|
setTimeout(() => wrapper.remove(), timeout)
|
|
|
|
}
|
2023-03-22 17:44:49 +00:00
|
|
|
|
2023-05-11 15:07:53 +00:00
|
|
|
/**
|
|
|
|
* Update the information banner.
|
|
|
|
* @param tid The tournament id
|
|
|
|
* @param info The content to updated
|
|
|
|
*/
|
|
|
|
function setInfo(tid, info) {
|
|
|
|
document.getElementById(`messages-${tid}`).innerHTML = info
|
|
|
|
}
|
2023-03-23 15:17:29 +00:00
|
|
|
|
2023-05-11 15:07:53 +00:00
|
|
|
/**
|
|
|
|
* Open the draw interface, given the list of teams.
|
|
|
|
* @param tid The tournament id
|
|
|
|
* @param teams The list of teams (represented by their trigrams) that are present on this draw.
|
|
|
|
*/
|
|
|
|
function drawStart(tid, teams) {
|
|
|
|
// Hide the not-started-banner
|
|
|
|
document.getElementById(`banner-not-started-${tid}`).classList.add('d-none')
|
|
|
|
// Display the full draw interface
|
|
|
|
document.getElementById(`draw-content-${tid}`).classList.remove('d-none')
|
|
|
|
|
|
|
|
let dicesDiv = document.getElementById(`dices-${tid}`)
|
|
|
|
for (let team of teams) {
|
|
|
|
// Add empty dice score badge for each team
|
|
|
|
let col = document.createElement('div')
|
|
|
|
col.classList.add('col-md-1')
|
|
|
|
dicesDiv.append(col)
|
|
|
|
|
|
|
|
let diceDiv = document.createElement('div')
|
|
|
|
diceDiv.id = `dice-${tid}-${team}`
|
|
|
|
diceDiv.classList.add('badge', 'rounded-pill', 'text-bg-warning')
|
|
|
|
if (document.getElementById(`abort-${tid}`) !== null) {
|
|
|
|
// Check if this is a volunteer, who can launch a die for a specific team
|
|
|
|
diceDiv.onclick = (_) => drawDice(tid, team)
|
2023-03-24 11:29:24 +00:00
|
|
|
}
|
2023-05-11 15:07:53 +00:00
|
|
|
diceDiv.textContent = `${team} 🎲 ??`
|
|
|
|
col.append(diceDiv)
|
2023-03-24 11:29:24 +00:00
|
|
|
}
|
2023-05-11 15:07:53 +00:00
|
|
|
}
|
2023-03-24 11:29:24 +00:00
|
|
|
|
2023-05-11 15:07:53 +00:00
|
|
|
/**
|
|
|
|
* Abort the current draw, and make all invisible, except the not-started-banner.
|
|
|
|
* @param tid The tournament id
|
|
|
|
*/
|
|
|
|
function drawAbort(tid) {
|
|
|
|
document.getElementById(`banner-not-started-${tid}`).classList.remove('d-none')
|
|
|
|
document.getElementById(`draw-content-${tid}`).classList.add('d-none')
|
|
|
|
document.getElementById(`dices-${tid}`).innerHTML = ""
|
|
|
|
document.getElementById(`recap-${tid}-round-list`).innerHTML = ""
|
|
|
|
document.getElementById(`tables-${tid}`).innerHTML = ""
|
|
|
|
updateDiceVisibility(tid, false)
|
|
|
|
updateBoxVisibility(tid, false)
|
|
|
|
updateButtonsVisibility(tid, false)
|
|
|
|
updateExportVisibility(tid, false)
|
|
|
|
updateContinueVisibility(tid, false)
|
|
|
|
}
|
2023-03-22 17:44:49 +00:00
|
|
|
|
2023-05-11 15:07:53 +00:00
|
|
|
/**
|
|
|
|
* This function is triggered after a new dice result. We update the score of the team.
|
|
|
|
* Can be resetted to empty values if the result is null.
|
|
|
|
* @param tid The tournament id
|
|
|
|
* @param trigram The trigram of the team that launched its dice
|
|
|
|
* @param result The result of the dice. null if it is a reset.
|
|
|
|
*/
|
|
|
|
function updateDiceInfo(tid, trigram, result) {
|
|
|
|
let elem = document.getElementById(`dice-${tid}-${trigram}`)
|
|
|
|
if (result === null) {
|
|
|
|
elem.classList.remove('text-bg-success')
|
|
|
|
elem.classList.add('text-bg-warning')
|
|
|
|
elem.innerText = `${trigram} 🎲 ??`
|
2023-05-19 16:24:01 +00:00
|
|
|
} else {
|
2023-05-11 15:07:53 +00:00
|
|
|
elem.classList.remove('text-bg-warning')
|
|
|
|
elem.classList.add('text-bg-success')
|
|
|
|
elem.innerText = `${trigram} 🎲 ${result}`
|
2023-03-23 15:17:29 +00:00
|
|
|
}
|
2024-04-22 21:36:52 +00:00
|
|
|
|
|
|
|
let nextTeam = document.querySelector(` div[id="dices-${tid}"] > div > div[class*="text-bg-warning"]`).getAttribute("data-team")
|
|
|
|
if (nextTeam) {
|
|
|
|
// If there is one team that does not have launched its dice, then we update the debug section
|
|
|
|
let debugSpan = document.getElementById(`debug-dice-${tid}-team`)
|
|
|
|
if (debugSpan)
|
|
|
|
debugSpan.innerText = nextTeam
|
|
|
|
}
|
2023-05-11 15:07:53 +00:00
|
|
|
}
|
2023-03-23 15:17:29 +00:00
|
|
|
|
2023-05-11 15:07:53 +00:00
|
|
|
/**
|
|
|
|
* Display or hide the dice button.
|
|
|
|
* @param tid The tournament id
|
|
|
|
* @param visible The visibility status
|
|
|
|
*/
|
|
|
|
function updateDiceVisibility(tid, visible) {
|
|
|
|
let div = document.getElementById(`launch-dice-${tid}`)
|
2024-04-22 21:36:52 +00:00
|
|
|
let div_debug = document.getElementById(`debug-dice-form-${tid}`)
|
|
|
|
if (visible) {
|
2023-05-11 15:07:53 +00:00
|
|
|
div.classList.remove('d-none')
|
2024-04-22 21:36:52 +00:00
|
|
|
div_debug.classList.remove('d-none')
|
|
|
|
}
|
|
|
|
else {
|
2023-05-11 15:07:53 +00:00
|
|
|
div.classList.add('d-none')
|
2024-04-22 21:36:52 +00:00
|
|
|
div_debug.classList.add('d-none')
|
|
|
|
}
|
2023-05-11 15:07:53 +00:00
|
|
|
}
|
2023-03-24 12:24:44 +00:00
|
|
|
|
2023-05-11 15:07:53 +00:00
|
|
|
/**
|
|
|
|
* Display or hide the box button.
|
|
|
|
* @param tid The tournament id
|
|
|
|
* @param visible The visibility status
|
|
|
|
*/
|
|
|
|
function updateBoxVisibility(tid, visible) {
|
|
|
|
let div = document.getElementById(`draw-problem-${tid}`)
|
2024-04-22 21:36:52 +00:00
|
|
|
let div_debug = document.getElementById(`debug-problem-form-${tid}`)
|
|
|
|
if (visible) {
|
2023-05-11 15:07:53 +00:00
|
|
|
div.classList.remove('d-none')
|
2024-04-22 21:36:52 +00:00
|
|
|
div_debug.classList.remove('d-none')
|
|
|
|
}
|
|
|
|
else {
|
2023-05-11 15:07:53 +00:00
|
|
|
div.classList.add('d-none')
|
2024-04-22 21:36:52 +00:00
|
|
|
div_debug.classList.add('d-none')
|
|
|
|
}
|
2023-05-11 15:07:53 +00:00
|
|
|
}
|
2023-03-24 12:24:44 +00:00
|
|
|
|
2023-05-11 15:07:53 +00:00
|
|
|
/**
|
|
|
|
* Display or hide the accept and reject buttons.
|
|
|
|
* @param tid The tournament id
|
|
|
|
* @param visible The visibility status
|
|
|
|
*/
|
|
|
|
function updateButtonsVisibility(tid, visible) {
|
|
|
|
let div = document.getElementById(`buttons-${tid}`)
|
|
|
|
if (visible)
|
|
|
|
div.classList.remove('d-none')
|
|
|
|
else
|
|
|
|
div.classList.add('d-none')
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display or hide the export button.
|
|
|
|
* @param tid The tournament id
|
|
|
|
* @param visible The visibility status
|
|
|
|
*/
|
|
|
|
function updateExportVisibility(tid, visible) {
|
|
|
|
let div = document.getElementById(`export-${tid}`)
|
|
|
|
if (visible)
|
|
|
|
div.classList.remove('d-none')
|
|
|
|
else
|
|
|
|
div.classList.add('d-none')
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display or hide the continuation button.
|
|
|
|
* @param tid The tournament id
|
|
|
|
* @param visible The visibility status
|
|
|
|
*/
|
|
|
|
function updateContinueVisibility(tid, visible) {
|
|
|
|
let div = document.getElementById(`continue-${tid}`)
|
|
|
|
if (div !== null) {
|
|
|
|
// Only present during the final
|
2023-03-25 19:38:58 +00:00
|
|
|
if (visible)
|
|
|
|
div.classList.remove('d-none')
|
|
|
|
else
|
|
|
|
div.classList.add('d-none')
|
|
|
|
}
|
2023-05-11 15:07:53 +00:00
|
|
|
}
|
2023-03-25 19:38:58 +00:00
|
|
|
|
2023-05-11 15:07:53 +00:00
|
|
|
/**
|
|
|
|
* Set the different pools for the given round, and update the interface.
|
|
|
|
* @param tid The tournament id
|
2024-06-07 13:48:52 +00:00
|
|
|
* @param round The round number, as integer (1 or 2, or 3 for ETEAM)
|
2023-05-11 15:07:53 +00:00
|
|
|
* @param poules The list of poules, which are represented with their letters and trigrams,
|
|
|
|
* [{'letter': 'A', 'teams': ['ABC', 'DEF', 'GHI']}]
|
|
|
|
*/
|
|
|
|
function updatePoules(tid, round, poules) {
|
|
|
|
let roundList = document.getElementById(`recap-${tid}-round-list`)
|
|
|
|
let poolListId = `recap-${tid}-round-${round}-pool-list`
|
|
|
|
let poolList = document.getElementById(poolListId)
|
|
|
|
if (poolList === null) {
|
|
|
|
// Add a div for the round in the recap div
|
|
|
|
let div = document.createElement('div')
|
|
|
|
div.id = `recap-${tid}-round-${round}`
|
|
|
|
div.classList.add('col-md-6', 'px-3', 'py-3')
|
|
|
|
div.setAttribute('data-tournament', tid)
|
|
|
|
|
|
|
|
let title = document.createElement('strong')
|
|
|
|
title.textContent = 'Tour ' + round
|
|
|
|
|
|
|
|
poolList = document.createElement('ul')
|
|
|
|
poolList.id = poolListId
|
|
|
|
poolList.classList.add('list-group', 'list-group-flush')
|
|
|
|
|
|
|
|
div.append(title, poolList)
|
|
|
|
roundList.append(div)
|
2023-03-26 09:08:03 +00:00
|
|
|
}
|
|
|
|
|
2023-05-11 15:07:53 +00:00
|
|
|
let c = 1
|
|
|
|
|
|
|
|
for (let poule of poules) {
|
|
|
|
let teamListId = `recap-${tid}-round-${round}-pool-${poule.letter}-team-list`
|
|
|
|
let teamList = document.getElementById(teamListId)
|
|
|
|
if (teamList === null) {
|
|
|
|
// Add a div for the pool in the recap div
|
|
|
|
let li = document.createElement('li')
|
|
|
|
li.id = `recap-${tid}-round-${round}-pool-${poule.letter}`
|
|
|
|
li.classList.add('list-group-item', 'px-3', 'py-3')
|
|
|
|
li.setAttribute('data-tournament', tid)
|
2023-03-24 10:10:07 +00:00
|
|
|
|
|
|
|
let title = document.createElement('strong')
|
2023-05-11 15:07:53 +00:00
|
|
|
title.textContent = 'Poule ' + poule.letter + round
|
2023-03-24 10:10:07 +00:00
|
|
|
|
2023-05-11 15:07:53 +00:00
|
|
|
teamList = document.createElement('ul')
|
|
|
|
teamList.id = teamListId
|
|
|
|
teamList.classList.add('list-group', 'list-group-flush')
|
2023-03-24 10:10:07 +00:00
|
|
|
|
2023-05-11 15:07:53 +00:00
|
|
|
li.append(title, teamList)
|
|
|
|
poolList.append(li)
|
2023-03-24 10:10:07 +00:00
|
|
|
}
|
2023-05-11 16:00:32 +00:00
|
|
|
teamList.innerHTML = ""
|
|
|
|
|
|
|
|
for (let team of poule.teams) {
|
|
|
|
// Reorder dices
|
|
|
|
let diceDiv = document.getElementById(`dice-${tid}-${team}`)
|
|
|
|
diceDiv.parentElement.style.order = c.toString()
|
|
|
|
c += 1
|
|
|
|
|
|
|
|
let teamLiId = `recap-${tid}-round-${round}-team-${team}`
|
|
|
|
|
|
|
|
// Add a line for the team in the recap
|
|
|
|
let teamLi = document.createElement('li')
|
|
|
|
teamLi.id = teamLiId
|
|
|
|
teamLi.classList.add('list-group-item')
|
|
|
|
teamLi.setAttribute('data-tournament', tid)
|
|
|
|
|
|
|
|
teamList.append(teamLi)
|
|
|
|
|
|
|
|
// Add the accepted problem div (empty for now)
|
|
|
|
let acceptedDivId = `recap-${tid}-round-${round}-team-${team}-accepted`
|
|
|
|
let acceptedDiv = document.getElementById(acceptedDivId)
|
|
|
|
if (acceptedDiv === null) {
|
|
|
|
acceptedDiv = document.createElement('div')
|
|
|
|
acceptedDiv.id = acceptedDivId
|
|
|
|
acceptedDiv.classList.add('badge', 'rounded-pill', 'text-bg-warning')
|
|
|
|
acceptedDiv.textContent = `${team} 📃 ?`
|
|
|
|
teamLi.append(acceptedDiv)
|
|
|
|
}
|
2023-03-24 10:10:07 +00:00
|
|
|
|
2023-05-11 16:00:32 +00:00
|
|
|
// Add the rejected problems div (empty for now)
|
|
|
|
let rejectedDivId = `recap-${tid}-round-${round}-team-${team}-rejected`
|
|
|
|
let rejectedDiv = document.getElementById(rejectedDivId)
|
|
|
|
if (rejectedDiv === null) {
|
|
|
|
rejectedDiv = document.createElement('div')
|
|
|
|
rejectedDiv.id = rejectedDivId
|
|
|
|
rejectedDiv.classList.add('badge', 'rounded-pill', 'text-bg-danger')
|
|
|
|
rejectedDiv.textContent = '🗑️'
|
|
|
|
teamLi.append(rejectedDiv)
|
2023-03-25 06:54:53 +00:00
|
|
|
}
|
|
|
|
}
|
2023-03-24 10:10:07 +00:00
|
|
|
|
2023-05-11 15:07:53 +00:00
|
|
|
// Draw tables
|
|
|
|
let tablesDiv = document.getElementById(`tables-${tid}`)
|
|
|
|
let tablesRoundDiv = document.getElementById(`tables-${tid}-round-${round}`)
|
|
|
|
if (tablesRoundDiv === null) {
|
|
|
|
// Add the tables div for the current round if necessary
|
2023-03-25 06:54:53 +00:00
|
|
|
let card = document.createElement('div')
|
2023-05-11 15:07:53 +00:00
|
|
|
card.classList.add('card', 'col-md-6')
|
|
|
|
tablesDiv.append(card)
|
2023-03-25 06:54:53 +00:00
|
|
|
|
|
|
|
let cardHeader = document.createElement('div')
|
|
|
|
cardHeader.classList.add('card-header')
|
2023-05-11 15:07:53 +00:00
|
|
|
cardHeader.innerHTML = `<h2>Tour ${round}</h2>`
|
2023-03-25 06:54:53 +00:00
|
|
|
card.append(cardHeader)
|
|
|
|
|
2023-05-11 15:07:53 +00:00
|
|
|
tablesRoundDiv = document.createElement('div')
|
|
|
|
tablesRoundDiv.id = `tables-${tid}-round-${round}`
|
|
|
|
tablesRoundDiv.classList.add('card-body', 'd-flex', 'flex-wrap')
|
|
|
|
card.append(tablesRoundDiv)
|
|
|
|
}
|
2023-03-24 10:10:07 +00:00
|
|
|
|
2023-05-11 15:07:53 +00:00
|
|
|
for (let poule of poules) {
|
|
|
|
if (poule.teams.length === 0)
|
|
|
|
continue
|
2023-03-25 06:54:53 +00:00
|
|
|
|
2023-05-11 15:07:53 +00:00
|
|
|
// Display the table for the pool
|
|
|
|
updatePouleTable(tid, round, poule)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the table for the given round and the given pool, where there will be the chosen problems.
|
|
|
|
* @param tid The tournament id
|
2024-06-07 13:48:52 +00:00
|
|
|
* @param round The round number, as integer (1 or 2, or 3 for ETEAM)
|
2023-05-11 15:07:53 +00:00
|
|
|
* @param poule The current pool, which id represented with its letter and trigrams,
|
|
|
|
* {'letter': 'A', 'teams': ['ABC', 'DEF', 'GHI']}
|
|
|
|
*/
|
|
|
|
function updatePouleTable(tid, round, poule) {
|
|
|
|
let tablesRoundDiv = document.getElementById(`tables-${tid}-round-${round}`)
|
|
|
|
let pouleTable = document.getElementById(`table-${tid}-${round}-${poule.letter}`)
|
|
|
|
if (pouleTable === null) {
|
|
|
|
// Create table
|
|
|
|
let card = document.createElement('div')
|
|
|
|
card.classList.add('card', 'w-100', 'my-3', `order-${poule.letter.charCodeAt(0) - 64}`)
|
|
|
|
tablesRoundDiv.append(card)
|
|
|
|
|
|
|
|
let cardHeader = document.createElement('div')
|
|
|
|
cardHeader.classList.add('card-header')
|
|
|
|
cardHeader.innerHTML = `<h2>Poule ${poule.letter}${round}</h2>`
|
|
|
|
card.append(cardHeader)
|
|
|
|
|
|
|
|
let cardBody = document.createElement('div')
|
|
|
|
cardBody.classList.add('card-body')
|
|
|
|
card.append(cardBody)
|
|
|
|
|
|
|
|
pouleTable = document.createElement('table')
|
|
|
|
pouleTable.id = `table-${tid}-${round}-${poule.letter}`
|
|
|
|
pouleTable.classList.add('table', 'table-stripped')
|
|
|
|
cardBody.append(pouleTable)
|
|
|
|
|
|
|
|
let thead = document.createElement('thead')
|
|
|
|
pouleTable.append(thead)
|
|
|
|
|
|
|
|
let phaseTr = document.createElement('tr')
|
|
|
|
thead.append(phaseTr)
|
|
|
|
|
|
|
|
let teamTh = document.createElement('th')
|
|
|
|
teamTh.classList.add('text-center')
|
|
|
|
teamTh.rowSpan = poule.teams.length === 5 ? 3 : 2
|
|
|
|
teamTh.textContent = "Équipe"
|
|
|
|
phaseTr.append(teamTh)
|
|
|
|
|
|
|
|
// Add columns
|
|
|
|
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)
|
|
|
|
phaseTh.colSpan = 2
|
|
|
|
phaseTh.textContent = `Phase ${i}`
|
|
|
|
phaseTr.append(phaseTh)
|
|
|
|
}
|
2023-03-24 10:10:07 +00:00
|
|
|
|
2023-05-11 15:07:53 +00:00
|
|
|
if (poule.teams.length === 5) {
|
|
|
|
let roomTr = document.createElement('tr')
|
|
|
|
thead.append(roomTr)
|
2023-03-24 10:10:07 +00:00
|
|
|
|
2023-05-11 15:07:53 +00:00
|
|
|
for (let i = 0; i < 5; ++i) {
|
|
|
|
let roomTh = document.createElement('th')
|
|
|
|
roomTh.classList.add('text-center')
|
|
|
|
roomTh.textContent = `Salle ${1 + (i % 2)}`
|
|
|
|
roomTr.append(roomTh)
|
2023-03-25 06:54:53 +00:00
|
|
|
}
|
2023-05-11 15:07:53 +00:00
|
|
|
}
|
2023-03-25 06:54:53 +00:00
|
|
|
|
2023-05-11 15:07:53 +00:00
|
|
|
let problemTr = document.createElement('tr')
|
|
|
|
thead.append(problemTr)
|
|
|
|
|
|
|
|
for (let team of poule.teams) {
|
|
|
|
let problemTh = document.createElement('th')
|
|
|
|
problemTh.classList.add('text-center')
|
|
|
|
// Problem is unknown for now
|
|
|
|
problemTh.innerHTML = `Pb. <span id="table-${tid}-round-${round}-problem-${team}">?</span>`
|
|
|
|
problemTr.append(problemTh)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add body
|
|
|
|
let tbody = document.createElement('tbody')
|
|
|
|
pouleTable.append(tbody)
|
|
|
|
|
|
|
|
for (let i = 0; i < poule.teams.length; ++i) {
|
|
|
|
let team = poule.teams[i]
|
|
|
|
|
|
|
|
let teamTr = document.createElement('tr')
|
|
|
|
tbody.append(teamTr)
|
|
|
|
|
|
|
|
// First create cells, then we will add them in the table
|
|
|
|
let teamTd = document.createElement('td')
|
|
|
|
teamTd.classList.add('text-center')
|
|
|
|
teamTd.innerText = team
|
|
|
|
teamTr.append(teamTd)
|
|
|
|
|
2024-07-06 20:12:07 +00:00
|
|
|
let reporterTd = document.createElement('td')
|
|
|
|
reporterTd.classList.add('text-center')
|
|
|
|
reporterTd.innerText = 'Déf'
|
2023-05-11 15:07:53 +00:00
|
|
|
|
|
|
|
let opponentTd = document.createElement('td')
|
|
|
|
opponentTd.classList.add('text-center')
|
|
|
|
opponentTd.innerText = 'Opp'
|
|
|
|
|
2024-07-05 09:00:11 +00:00
|
|
|
let reviewerTd = document.createElement('td')
|
|
|
|
reviewerTd.classList.add('text-center')
|
|
|
|
reviewerTd.innerText = 'Rap'
|
2023-05-11 15:07:53 +00:00
|
|
|
|
|
|
|
// Put the cells in their right places, according to the pool size and the row number.
|
|
|
|
if (poule.teams.length === 3) {
|
|
|
|
switch (i) {
|
|
|
|
case 0:
|
2024-07-06 20:12:07 +00:00
|
|
|
teamTr.append(reporterTd, reviewerTd, opponentTd)
|
2023-05-11 15:07:53 +00:00
|
|
|
break
|
|
|
|
case 1:
|
2024-07-06 20:12:07 +00:00
|
|
|
teamTr.append(opponentTd, reporterTd, reviewerTd)
|
2023-05-11 15:07:53 +00:00
|
|
|
break
|
|
|
|
case 2:
|
2024-07-06 20:12:07 +00:00
|
|
|
teamTr.append(reviewerTd, opponentTd, reporterTd)
|
2023-05-11 15:07:53 +00:00
|
|
|
break
|
2023-03-25 06:54:53 +00:00
|
|
|
}
|
2023-05-19 16:24:01 +00:00
|
|
|
} else if (poule.teams.length === 4) {
|
2023-05-11 15:07:53 +00:00
|
|
|
let emptyTd = document.createElement('td')
|
|
|
|
switch (i) {
|
|
|
|
case 0:
|
2024-07-06 20:12:07 +00:00
|
|
|
teamTr.append(reporterTd, emptyTd, reviewerTd, opponentTd)
|
2023-05-11 15:07:53 +00:00
|
|
|
break
|
|
|
|
case 1:
|
2024-07-06 20:12:07 +00:00
|
|
|
teamTr.append(opponentTd, reporterTd, emptyTd, reviewerTd)
|
2023-05-11 15:07:53 +00:00
|
|
|
break
|
|
|
|
case 2:
|
2024-07-06 20:12:07 +00:00
|
|
|
teamTr.append(reviewerTd, opponentTd, reporterTd, emptyTd)
|
2023-05-11 15:07:53 +00:00
|
|
|
break
|
|
|
|
case 3:
|
2024-07-06 20:12:07 +00:00
|
|
|
teamTr.append(emptyTd, reviewerTd, opponentTd, reporterTd)
|
2023-05-11 15:07:53 +00:00
|
|
|
break
|
2023-03-25 06:54:53 +00:00
|
|
|
}
|
2023-05-19 16:24:01 +00:00
|
|
|
} else if (poule.teams.length === 5) {
|
2023-05-11 15:07:53 +00:00
|
|
|
let emptyTd = document.createElement('td')
|
|
|
|
let emptyTd2 = document.createElement('td')
|
|
|
|
switch (i) {
|
|
|
|
case 0:
|
2024-07-06 20:12:07 +00:00
|
|
|
teamTr.append(reporterTd, emptyTd, opponentTd, reviewerTd, emptyTd2)
|
2023-05-11 15:07:53 +00:00
|
|
|
break
|
|
|
|
case 1:
|
2024-07-06 20:12:07 +00:00
|
|
|
teamTr.append(emptyTd, reporterTd, reviewerTd, emptyTd2, opponentTd)
|
2023-05-11 15:07:53 +00:00
|
|
|
break
|
|
|
|
case 2:
|
2024-07-06 20:12:07 +00:00
|
|
|
teamTr.append(opponentTd, emptyTd, reporterTd, emptyTd2, reviewerTd)
|
2023-05-11 15:07:53 +00:00
|
|
|
break
|
|
|
|
case 3:
|
2024-07-06 20:12:07 +00:00
|
|
|
teamTr.append(reviewerTd, opponentTd, emptyTd, reporterTd, emptyTd2)
|
2023-05-11 15:07:53 +00:00
|
|
|
break
|
|
|
|
case 4:
|
2024-07-06 20:12:07 +00:00
|
|
|
teamTr.append(emptyTd, reviewerTd, emptyTd2, opponentTd, reporterTd)
|
2023-05-11 15:07:53 +00:00
|
|
|
break
|
2023-03-24 10:10:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-05-11 15:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Highlight the team that is currently choosing its problem.
|
|
|
|
* @param tid The tournament id
|
2024-06-07 13:48:52 +00:00
|
|
|
* @param round The current round number, as integer (1 or 2, or 3 for ETEAM)
|
2023-05-11 15:07:53 +00:00
|
|
|
* @param pool The current pool letter (A, B, C or D) (null if non-relevant)
|
|
|
|
* @param team The current team trigram (null if non-relevant)
|
|
|
|
*/
|
|
|
|
function updateActiveRecap(tid, round, pool, team) {
|
|
|
|
// Remove the previous highlights
|
|
|
|
document.querySelectorAll(`div.text-bg-secondary[data-tournament="${tid}"]`)
|
|
|
|
.forEach(elem => elem.classList.remove('text-bg-secondary'))
|
|
|
|
document.querySelectorAll(`li.list-group-item-success[data-tournament="${tid}"]`)
|
|
|
|
.forEach(elem => elem.classList.remove('list-group-item-success'))
|
|
|
|
document.querySelectorAll(`li.list-group-item-info[data-tournament="${tid}"]`)
|
|
|
|
.forEach(elem => elem.classList.remove('list-group-item-info'))
|
|
|
|
|
|
|
|
// Highlight current round, if existing
|
|
|
|
let roundDiv = document.getElementById(`recap-${tid}-round-${round}`)
|
|
|
|
if (roundDiv !== null)
|
|
|
|
roundDiv.classList.add('text-bg-secondary')
|
|
|
|
|
|
|
|
// Highlight current pool, if existing
|
|
|
|
let poolLi = document.getElementById(`recap-${tid}-round-${round}-pool-${pool}`)
|
|
|
|
if (poolLi !== null)
|
|
|
|
poolLi.classList.add('list-group-item-success')
|
|
|
|
|
|
|
|
// Highlight current team, if existing
|
|
|
|
let teamLi = document.getElementById(`recap-${tid}-round-${round}-team-${team}`)
|
|
|
|
if (teamLi !== null)
|
|
|
|
teamLi.classList.add('list-group-item-info')
|
2024-04-22 21:36:52 +00:00
|
|
|
|
|
|
|
let debugSpan = document.getElementById(`debug-problem-${tid}-team`)
|
|
|
|
if (debugSpan && team) {
|
|
|
|
debugSpan.innerText = team
|
|
|
|
}
|
2023-05-11 15:07:53 +00:00
|
|
|
}
|
2023-03-24 10:10:07 +00:00
|
|
|
|
2023-05-11 15:07:53 +00:00
|
|
|
/**
|
|
|
|
* Update the recap and the table when a team accepts a problem.
|
|
|
|
* @param tid The tournament id
|
2024-06-07 13:48:52 +00:00
|
|
|
* @param round The current round, as integer (1 or 2, or 3 for ETEAM)
|
2023-05-11 15:07:53 +00:00
|
|
|
* @param team The current team trigram
|
|
|
|
* @param problem The accepted problem, as integer
|
|
|
|
*/
|
|
|
|
function setProblemAccepted(tid, round, team, problem) {
|
|
|
|
// Update recap
|
|
|
|
let recapDiv = document.getElementById(`recap-${tid}-round-${round}-team-${team}-accepted`)
|
|
|
|
if (problem !== null) {
|
|
|
|
recapDiv.classList.remove('text-bg-warning')
|
|
|
|
recapDiv.classList.add('text-bg-success')
|
2023-05-19 16:24:01 +00:00
|
|
|
} else {
|
2023-05-11 15:07:53 +00:00
|
|
|
recapDiv.classList.add('text-bg-warning')
|
|
|
|
recapDiv.classList.remove('text-bg-success')
|
|
|
|
}
|
|
|
|
recapDiv.textContent = `${team} 📃 ${problem ? problem : '?'}`
|
2023-03-24 10:10:07 +00:00
|
|
|
|
2023-05-11 15:07:53 +00:00
|
|
|
// Update table
|
|
|
|
let tableSpan = document.getElementById(`table-${tid}-round-${round}-problem-${team}`)
|
|
|
|
tableSpan.textContent = problem ? problem : '?'
|
|
|
|
}
|
2023-03-25 05:21:39 +00:00
|
|
|
|
2023-05-11 15:07:53 +00:00
|
|
|
/**
|
|
|
|
* Update the recap when a team rejects a problem.
|
|
|
|
* @param tid The tournament id
|
2024-06-07 13:48:52 +00:00
|
|
|
* @param round The current round, as integer (1 or 2, or 3 for ETEAM)
|
2023-05-11 15:07:53 +00:00
|
|
|
* @param team The current team trigram
|
|
|
|
* @param rejected The full list of rejected problems
|
|
|
|
*/
|
|
|
|
function setProblemRejected(tid, round, team, rejected) {
|
|
|
|
// Update recap
|
|
|
|
let recapDiv = document.getElementById(`recap-${tid}-round-${round}-team-${team}-rejected`)
|
|
|
|
recapDiv.textContent = `🗑️ ${rejected.join(', ')}`
|
|
|
|
|
|
|
|
let penaltyDiv = document.getElementById(`recap-${tid}-round-${round}-team-${team}-penalty`)
|
2024-06-07 12:18:25 +00:00
|
|
|
if (rejected.length > problems_count - RECOMMENDED_SOLUTIONS_COUNT) {
|
2024-07-06 20:12:07 +00:00
|
|
|
// If more than P - 5 problems were rejected, add a penalty of 25% of the coefficient of the oral reporter
|
2024-06-07 12:18:25 +00:00
|
|
|
// This is P - 6 for the ETEAM
|
2023-05-11 15:07:53 +00:00
|
|
|
if (penaltyDiv === null) {
|
|
|
|
penaltyDiv = document.createElement('div')
|
|
|
|
penaltyDiv.id = `recap-${tid}-round-${round}-team-${team}-penalty`
|
|
|
|
penaltyDiv.classList.add('badge', 'rounded-pill', 'text-bg-info')
|
|
|
|
recapDiv.parentNode.append(penaltyDiv)
|
|
|
|
}
|
2024-06-07 12:18:25 +00:00
|
|
|
penaltyDiv.textContent = `❌ ${25 * (rejected.length - (problems_count - RECOMMENDED_SOLUTIONS_COUNT))} %`
|
2023-05-19 16:24:01 +00:00
|
|
|
} else {
|
2023-05-11 15:07:53 +00:00
|
|
|
// Eventually remove this div
|
|
|
|
if (penaltyDiv !== null)
|
|
|
|
penaltyDiv.remove()
|
2023-03-25 05:21:39 +00:00
|
|
|
}
|
2023-05-11 15:07:53 +00:00
|
|
|
}
|
2023-03-25 05:21:39 +00:00
|
|
|
|
2023-05-11 15:07:53 +00:00
|
|
|
/**
|
|
|
|
* For a 5-teams pool, we may reorder the pool if two teams select the same problem.
|
|
|
|
* Then, we redraw the table and set the accepted problems.
|
|
|
|
* @param tid The tournament id
|
2024-06-07 13:48:52 +00:00
|
|
|
* @param round The current round, as integer (1 or 2, or 3 for ETEAM)
|
2023-05-11 15:07:53 +00:00
|
|
|
* @param poule The pool represented by its letter
|
|
|
|
* @param teams The teams list represented by their trigrams, ["ABC", "DEF", "GHI", "JKL", "MNO"]
|
|
|
|
* @param problems The accepted problems in the same order than the teams, [1, 1, 2, 2, 3]
|
|
|
|
*/
|
|
|
|
function reorderPoule(tid, round, poule, teams, problems) {
|
|
|
|
// Redraw the pool table
|
|
|
|
let table = document.getElementById(`table-${tid}-${round}-${poule}`)
|
|
|
|
table.parentElement.parentElement.remove()
|
|
|
|
|
|
|
|
updatePouleTable(tid, round, {'letter': poule, 'teams': teams})
|
|
|
|
|
|
|
|
// Put the problems in the table
|
|
|
|
for (let i = 0; i < teams.length; ++i) {
|
|
|
|
let team = teams[i]
|
|
|
|
let problem = problems[i]
|
|
|
|
|
|
|
|
setProblemAccepted(tid, round, team, problem)
|
2024-07-09 11:51:50 +00:00
|
|
|
|
|
|
|
let recapTeam = document.getElementById(`recap-${tid}-round-${round}-team-${team}`)
|
|
|
|
recapTeam.style.order = i.toString()
|
2023-03-25 05:21:39 +00:00
|
|
|
}
|
2023-05-11 15:07:53 +00:00
|
|
|
}
|
2023-03-25 05:21:39 +00:00
|
|
|
|
2023-05-11 15:07:53 +00:00
|
|
|
/**
|
|
|
|
* Process the received data from the server.
|
|
|
|
* @param tid The tournament id
|
|
|
|
* @param data The received message
|
|
|
|
*/
|
|
|
|
function processMessage(tid, data) {
|
|
|
|
switch (data.type) {
|
|
|
|
case 'alert':
|
|
|
|
// Add alert message
|
|
|
|
addMessage(data.message, data.alert_type)
|
|
|
|
break
|
|
|
|
case 'notification':
|
|
|
|
// Add notification
|
|
|
|
showNotification(data.title, data.body)
|
|
|
|
break
|
|
|
|
case 'set_info':
|
|
|
|
// Update information banner
|
|
|
|
setInfo(tid, data.information)
|
|
|
|
break
|
|
|
|
case 'draw_start':
|
|
|
|
// Start the draw and update the interface
|
|
|
|
drawStart(tid, data.trigrams)
|
|
|
|
break
|
|
|
|
case 'abort':
|
|
|
|
// Abort the current draw
|
|
|
|
drawAbort(tid)
|
|
|
|
break
|
|
|
|
case 'dice':
|
|
|
|
// Update the interface after a dice launch
|
|
|
|
updateDiceInfo(tid, data.team, data.result)
|
|
|
|
break
|
|
|
|
case 'dice_visibility':
|
|
|
|
// Update the dice button visibility
|
|
|
|
updateDiceVisibility(tid, data.visible)
|
|
|
|
break
|
|
|
|
case 'box_visibility':
|
|
|
|
// Update the box button visibility
|
|
|
|
updateBoxVisibility(tid, data.visible)
|
|
|
|
break
|
|
|
|
case 'buttons_visibility':
|
|
|
|
// Update the accept/reject buttons visibility
|
|
|
|
updateButtonsVisibility(tid, data.visible)
|
|
|
|
break
|
|
|
|
case 'export_visibility':
|
|
|
|
// Update the export button visibility
|
|
|
|
updateExportVisibility(tid, data.visible)
|
|
|
|
break
|
|
|
|
case 'continue_visibility':
|
|
|
|
// Update the continue button visibility for the final tournament
|
|
|
|
updateContinueVisibility(tid, data.visible)
|
|
|
|
break
|
|
|
|
case 'set_poules':
|
|
|
|
// Set teams order and pools and update the interface
|
|
|
|
updatePoules(tid, data.round, data.poules)
|
|
|
|
break
|
|
|
|
case 'set_active':
|
|
|
|
// Highlight the team that is selecting a problem
|
|
|
|
updateActiveRecap(tid, data.round, data.poule, data.team)
|
|
|
|
break
|
|
|
|
case 'set_problem':
|
|
|
|
// Mark a problem as accepted and update the interface
|
|
|
|
setProblemAccepted(tid, data.round, data.team, data.problem)
|
|
|
|
break
|
|
|
|
case 'reject_problem':
|
|
|
|
// Mark a problem as rejected and update the interface
|
|
|
|
setProblemRejected(tid, data.round, data.team, data.rejected)
|
|
|
|
break
|
|
|
|
case 'reorder_poule':
|
|
|
|
// Reorder a pool and redraw the associated table
|
|
|
|
reorderPoule(tid, data.round, data.poule, data.teams, data.problems)
|
|
|
|
break
|
2023-03-25 06:54:53 +00:00
|
|
|
}
|
2023-05-11 15:07:53 +00:00
|
|
|
}
|
2023-03-25 06:54:53 +00:00
|
|
|
|
2024-04-06 20:25:58 +00:00
|
|
|
function setupSocket(nextDelay = 1000) {
|
2023-05-11 15:13:52 +00:00
|
|
|
// Open a global websocket
|
|
|
|
socket = new WebSocket(
|
|
|
|
(document.location.protocol === 'https:' ? 'wss' : 'ws') + '://' + window.location.host + '/ws/draw/'
|
|
|
|
)
|
|
|
|
|
|
|
|
// Listen on websockets and process messages from the server
|
|
|
|
socket.addEventListener('message', e => {
|
|
|
|
// Parse received data as JSON
|
|
|
|
const data = JSON.parse(e.data)
|
|
|
|
|
|
|
|
processMessage(data['tid'], data)
|
|
|
|
})
|
|
|
|
|
|
|
|
// Manage errors
|
|
|
|
socket.addEventListener('close', e => {
|
|
|
|
console.error('Chat socket closed unexpectedly, restarting…')
|
2024-04-06 20:25:58 +00:00
|
|
|
setTimeout(() => setupSocket(2 * nextDelay), nextDelay)
|
2023-05-11 15:13:52 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// When the socket is opened, set the language in order to receive alerts in the good language
|
|
|
|
socket.addEventListener('open', e => {
|
|
|
|
socket.send(JSON.stringify({
|
|
|
|
'tid': tournaments[0].id,
|
|
|
|
'type': 'set_language',
|
|
|
|
'language': document.getElementsByName('language')[0].value,
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
|
|
|
|
for (let tournament of tournaments) {
|
|
|
|
// Manage the start form
|
|
|
|
let format_form = document.getElementById('format-form-' + tournament.id)
|
|
|
|
if (format_form !== null) {
|
|
|
|
format_form.addEventListener('submit', function (e) {
|
|
|
|
e.preventDefault()
|
|
|
|
|
|
|
|
socket.send(JSON.stringify({
|
|
|
|
'tid': tournament.id,
|
|
|
|
'type': 'start_draw',
|
|
|
|
'fmt': document.getElementById('format-' + tournament.id).value
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
}
|
2023-03-23 15:17:29 +00:00
|
|
|
}
|
2023-03-22 17:44:49 +00:00
|
|
|
}
|
2023-05-11 15:13:52 +00:00
|
|
|
|
|
|
|
setupSocket()
|
2023-05-19 16:24:01 +00:00
|
|
|
|
|
|
|
if (document.querySelector('a[href="/admin/"]')) {
|
|
|
|
// Administrators can fake the draw
|
|
|
|
// This is useful for debug purposes, or
|
|
|
|
document.getElementsByTagName('body')[0].addEventListener('keyup', event => {
|
|
|
|
if (event.key === 'f') {
|
|
|
|
let activeTab = document.querySelector('#tournaments-tab button.active')
|
|
|
|
let tid = activeTab.id.substring(4)
|
|
|
|
|
|
|
|
let dice = document.getElementById(`launch-dice-${tid}`)
|
|
|
|
let box = document.getElementById(`draw-problem-${tid}`)
|
|
|
|
let value = NaN
|
|
|
|
if (!dice.classList.contains('d-none')) {
|
|
|
|
value = parseInt(prompt("Entrez la valeur du dé (laissez vide pour annuler) :"))
|
|
|
|
if (!isNaN(value) && 1 <= value && value <= 100)
|
|
|
|
drawDice(tid, null, value)
|
|
|
|
|
|
|
|
} else if (!box.classList.contains('d-none')) {
|
|
|
|
value = parseInt(prompt("Entrez le numéro du problème à choisir (laissez vide pour annuler) :"))
|
|
|
|
if (!isNaN(value) && 1 <= value && value <= 8)
|
|
|
|
drawProblem(tid, value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2023-03-22 17:44:49 +00:00
|
|
|
})
|