From 0fba3e065cba2ac32ccadcd31b1d18527b459257 Mon Sep 17 00:00:00 2001 From: Claude Brisson Date: Sat, 20 Jan 2024 11:35:59 +0100 Subject: [PATCH] Final reg status handling tweaks --- .../kotlin/org/jeudego/pairgoth/api/PairingHandler.kt | 9 ++++++--- view-webapp/src/main/webapp/js/tour-registration.inc.js | 2 ++ view-webapp/src/main/webapp/tour.html | 3 +++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/PairingHandler.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/PairingHandler.kt index ac005ce..a9ba349 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/PairingHandler.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/PairingHandler.kt @@ -21,8 +21,8 @@ object PairingHandler: PairgothApiHandler { val playing = tournament.games(round).values.flatMap { listOf(it.black, it.white) }.toSet() - val unpairables = tournament.pairables.values.filter { it.skip.contains(round) }.sortedByDescending { it.rating }.map { it.id }.toJsonArray() - val pairables = tournament.pairables.values.filter { !it.skip.contains(round) && !playing.contains(it.id) }.sortedByDescending { it.rating }.map { it.id }.toJsonArray() + val unpairables = tournament.pairables.values.filter { !it.final || it.skip.contains(round) }.sortedByDescending { it.rating }.map { it.id }.toJsonArray() + val pairables = tournament.pairables.values.filter { it.final && !it.skip.contains(round) && !playing.contains(it.id) }.sortedByDescending { it.rating }.map { it.id }.toJsonArray() val games = tournament.games(round).values return Json.Object( "games" to games.map { it.toJson() }.toCollection(Json.MutableArray()), @@ -44,12 +44,13 @@ object PairingHandler: PairgothApiHandler { }.toSet() val pairables = if (allPlayers) - tournament.pairables.values.filter { !it.skip.contains(round) && !playing.contains(it.id) } + tournament.pairables.values.filter { it.final && !it.skip.contains(round) && !playing.contains(it.id) } else payload.map { // CB - because of the '["all"]' map, conversion to int lands here... Better API syntax for 'all players'? if (it is Number) it.toID() else badRequest("invalid pairable id: #$it") }.map { id -> tournament.pairables[id]?.also { + if (!it.final) badRequest("pairable #$id registration status is not final") if (it.skip.contains(round)) badRequest("pairable #$id does not play round $round") if (playing.contains(it.id)) badRequest("pairable #$id already plays round $round") } ?: badRequest("invalid pairable id: #$id") @@ -79,6 +80,8 @@ object PairingHandler: PairgothApiHandler { payload.getInt("dudd")?.let { game.drawnUpDown = it } val black = tournament.pairables[game.black] ?: badRequest("invalid black player id") val white = tournament.pairables[game.black] ?: badRequest("invalid white player id") + if (!black.final) badRequest("black registration status is not final") + if (!white.final) badRequest("white registration status is not final") if (black.skip.contains(round)) badRequest("black is not playing this round") if (white.skip.contains(round)) badRequest("white is not playing this round") if (playing.contains(black.id)) badRequest("black is already in another game") diff --git a/view-webapp/src/main/webapp/js/tour-registration.inc.js b/view-webapp/src/main/webapp/js/tour-registration.inc.js index 596273a..f8eaa06 100644 --- a/view-webapp/src/main/webapp/js/tour-registration.inc.js +++ b/view-webapp/src/main/webapp/js/tour-registration.inc.js @@ -288,6 +288,8 @@ onLoad(() => { }).then(player => { if (player !== 'error') { cell.toggleClass('final'); + standingsUpToDate = false; + pairablesUpToDate = false; } }); e.preventDefault(); diff --git a/view-webapp/src/main/webapp/tour.html b/view-webapp/src/main/webapp/tour.html index 9857676..bb22aec 100644 --- a/view-webapp/src/main/webapp/tour.html +++ b/view-webapp/src/main/webapp/tour.html @@ -74,6 +74,7 @@ const tour_rounds = ${tour.rounds}; let activeRound = ${round}; let standingsUpToDate = true; + let pairablesUpToDate = true; // $params #end #set($datepickerLocale = $translate.datepickerLocale($request.lang, $request.loc)) @@ -108,6 +109,8 @@ window.location.hash = `#${step}`; if (step === 'standings' && !standingsUpToDate) { window.location.reload(); + } else if (step === 'pairing' && !pairablesUpToDate) { + window.location.reload(); } }