mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-21 20:38:24 +02:00
Add cancel button to cancel the last step (works for the last problem acceptance for now)
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
@ -115,6 +115,9 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
|
||||
case 'abort':
|
||||
# Abort the current draw
|
||||
await self.abort(**content)
|
||||
case 'cancel':
|
||||
# Cancel the last step
|
||||
await self.cancel_last_step(**content)
|
||||
case 'dice':
|
||||
# Launch a dice
|
||||
await self.process_dice(**content)
|
||||
@ -647,7 +650,7 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
|
||||
:param pool: The pool to end.
|
||||
"""
|
||||
msg = self.tournament.draw.last_message
|
||||
r = pool.round
|
||||
r = self.tournament.draw.current_round
|
||||
|
||||
if pool.size == 5:
|
||||
# Maybe reorder teams if the same problem is presented twice
|
||||
@ -925,6 +928,49 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
|
||||
await self.channel_layer.group_send(f"tournament-{self.tournament.id}",
|
||||
{'type': 'draw.set_active', 'draw': self.tournament.draw})
|
||||
|
||||
@ensure_orga
|
||||
async def cancel_last_step(self, **kwargs):
|
||||
"""
|
||||
Cancel the last step of the draw.
|
||||
"""
|
||||
if not await Draw.objects.filter(tournament=self.tournament).aexists():
|
||||
return await self.alert(_("The draw has not started yet."), 'danger')
|
||||
|
||||
state = self.tournament.draw.get_state()
|
||||
|
||||
self.tournament.draw.last_message = ""
|
||||
await self.tournament.draw.asave()
|
||||
|
||||
r = self.tournament.draw.current_round
|
||||
|
||||
if state == 'DRAW_ENDED' or state == 'WAITING_FINAL':
|
||||
td = self.tournament.draw.current_round.current_pool.current_team
|
||||
td.purposed = td.accepted
|
||||
td.accepted = None
|
||||
await td.asave()
|
||||
|
||||
await self.channel_layer.group_send(f"volunteer-{self.tournament.id}",
|
||||
{'type': 'draw.continue_visibility', 'visible': False})
|
||||
|
||||
await self.channel_layer.group_send(f"team-{td.participation.team.trigram}",
|
||||
{'type': 'draw.buttons_visibility', 'visible': True})
|
||||
await self.channel_layer.group_send(f"volunteer-{self.tournament.id}",
|
||||
{'type': 'draw.buttons_visibility', 'visible': True})
|
||||
|
||||
await self.channel_layer.group_send(f"tournament-{self.tournament.id}",
|
||||
{'type': 'draw.set_problem',
|
||||
'round': r.number,
|
||||
'team': td.participation.team.trigram,
|
||||
'problem': td.accepted})
|
||||
elif state == 'WAITING_DRAW_PROBLEM':
|
||||
pass
|
||||
|
||||
await self.channel_layer.group_send(f"tournament-{self.tournament.id}",
|
||||
{'type': 'draw.set_info', 'draw': self.tournament.draw})
|
||||
await self.channel_layer.group_send(f"tournament-{self.tournament.id}",
|
||||
{'type': 'draw.set_active', 'draw': self.tournament.draw})
|
||||
|
||||
|
||||
async def draw_alert(self, content):
|
||||
"""
|
||||
Send alert to the current user.
|
||||
|
@ -20,6 +20,15 @@ function abortDraw(tid) {
|
||||
sockets[tid].send(JSON.stringify({'type': 'abort'}))
|
||||
}
|
||||
|
||||
/**
|
||||
* Request to cancel the last step.
|
||||
* Only volunteers are allowed to do this.
|
||||
* @param tid The tournament id
|
||||
*/
|
||||
function cancelLastStep(tid) {
|
||||
sockets[tid].send(JSON.stringify({'type': 'cancel'}))
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@ -583,13 +592,19 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
function setProblemAccepted(round, team, problem) {
|
||||
// Update recap
|
||||
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}`
|
||||
if (problem !== null) {
|
||||
recapDiv.classList.remove('text-bg-warning')
|
||||
recapDiv.classList.add('text-bg-success')
|
||||
}
|
||||
else {
|
||||
recapDiv.classList.add('text-bg-warning')
|
||||
recapDiv.classList.remove('text-bg-success')
|
||||
}
|
||||
recapDiv.textContent = `${team} 📃 ${problem ? problem : '?'}`
|
||||
|
||||
// Update table
|
||||
let tableSpan = document.getElementById(`table-${tournament.id}-round-${round}-problem-${team}`)
|
||||
tableSpan.textContent = problem
|
||||
tableSpan.textContent = problem ? problem : '?'
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -177,6 +177,12 @@
|
||||
</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div id="cancel-last-step-{{ tournament.id }}"
|
||||
class="card-footer text-center">
|
||||
<button class="badge rounded-pill text-bg-warning" onclick="cancelLastStep({{ tournament.id }})">
|
||||
🔙 {% trans "Cancel last step" %}
|
||||
</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user