From 23a4ae37b26d9ee1e9e2edcc8cfb305d6dd7a58c Mon Sep 17 00:00:00 2001 From: Claude Brisson Date: Mon, 15 Apr 2024 19:50:45 +0200 Subject: [PATCH] Various bugfixes for teams support --- .../kotlin/org/jeudego/pairgoth/api/PairingHandler.kt | 4 +--- .../org/jeudego/pairgoth/api/StandingsHandler.kt | 8 ++++---- .../kotlin/org/jeudego/pairgoth/api/TeamHandler.kt | 3 +++ .../main/kotlin/org/jeudego/pairgoth/model/Pairable.kt | 2 +- .../kotlin/org/jeudego/pairgoth/model/Tournament.kt | 2 ++ view-webapp/src/main/webapp/js/tour-pairing.inc.js | 2 +- view-webapp/src/main/webapp/js/tour-teams.inc.js | 10 +++++++++- view-webapp/src/main/webapp/tour-information.inc.html | 2 +- 8 files changed, 22 insertions(+), 11 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 3a11875..dc51ca0 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 @@ -147,12 +147,10 @@ object PairingHandler: PairgothApiHandler { override fun delete(request: HttpServletRequest, response: HttpServletResponse): Json { val tournament = getTournament(request) val round = getSubSelector(request)?.toIntOrNull() ?: badRequest("invalid round number") - // only allow last round (if players have not been paired in the last round, it *may* be possible to be more laxist...) - // Nope - // if (round != tournament.lastRound()) badRequest("cannot delete games in other rounds but the last") val payload = getArrayPayload(request) val allPlayers = payload.size == 1 && payload[0] == "all" if (allPlayers) { + // TODO - just remove this, it is never used ; and no check is done on whether the players are playing... tournament.games(round).clear() } else { payload.forEach { diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/StandingsHandler.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/StandingsHandler.kt index 39500b6..ead26c6 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/StandingsHandler.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/StandingsHandler.kt @@ -161,11 +161,11 @@ ${ "${ player.getString("num")!!.padStart(4, ' ') } ${ - "${player.getString("name")} ${player.getString("firstname")}".padEnd(30, ' ').take(30) + "${player.getString("name")} ${player.getString("firstname") ?: ""}".padEnd(30, ' ').take(30) } ${ displayRank(player.getInt("rank")!!).uppercase().padStart(3, ' ') } ${ - player.getString("country")!!.uppercase() + player.getString("country")?.uppercase() ?: "" } ${ (player.getString("club") ?: "").padStart(4).take(4) } ${ @@ -209,7 +209,7 @@ ${ "${ player.getString("num")!!.padStart(4, ' ') } ${ - "${player.getString("name")} ${player.getString("firstname")}".padEnd(24, ' ').take(24) + "${player.getString("name")} ${player.getString("firstname") ?: ""}".padEnd(24, ' ').take(24) } ${ displayRank(player.getInt("rank")!!).uppercase().padStart(3, ' ') } ${ @@ -255,7 +255,7 @@ ${ // lines lines.forEach { line -> writer.println("${ - fields.joinToString(";") { if (it.second) "\"${line[it.first]}\"" else "${line[it.first]}" } + fields.joinToString(";") { if (it.second) "\"${line[it.first] ?: ""}\"" else "${line[it.first] ?: ""}" } };${ line.getArray("results")!!.joinToString(";") };${ diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/TeamHandler.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/TeamHandler.kt index 15a43e1..5389ddc 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/TeamHandler.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/TeamHandler.kt @@ -45,6 +45,9 @@ object TeamHandler: PairgothApiHandler { val tournament = getTournament(request) if (tournament !is TeamTournament) badRequest("tournament is not a team tournament") val id = getSubSelector(request)?.toIntOrNull() ?: badRequest("missing or invalid team selector") + if (tournament.pairedPlayers().contains(id)) { + badRequest("team is playing"); + } tournament.teams.remove(id) ?: badRequest("invalid team id") tournament.dispatchEvent(TeamDeleted, request, Json.Object("id" to id)) return Json.Object("success" to true) diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairable.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairable.kt index 270608d..4f23fc9 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairable.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairable.kt @@ -21,7 +21,7 @@ sealed class Pairable(val id: ID, val name: String, val rating: Int, val rank: I open fun fullName(separator: String = " "): String { return name } - val skip = mutableSetOf() // skipped rounds + open val skip = mutableSetOf() // skipped rounds fun equals(other: Pairable): Boolean { return id == other.id diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Tournament.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Tournament.kt index 50fb97c..333e8f6 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Tournament.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Tournament.kt @@ -196,6 +196,8 @@ class TeamTournament( club?.also { json["club"] = it } } val teamOfIndividuals: Boolean get() = type.individual + + override val skip get() = playerIds.map { players[it]!!.skip }.reduce { left, right -> (left union right) as MutableSet } } fun teamFromJson(json: Json.Object, default: TeamTournament.Team? = null): Team { diff --git a/view-webapp/src/main/webapp/js/tour-pairing.inc.js b/view-webapp/src/main/webapp/js/tour-pairing.inc.js index 9dd4d6a..381234d 100644 --- a/view-webapp/src/main/webapp/js/tour-pairing.inc.js +++ b/view-webapp/src/main/webapp/js/tour-pairing.inc.js @@ -117,7 +117,7 @@ onLoad(()=>{ }); $('#pair').on('click', e => { let parts = $('#pairables .selected.listitem').map(item => parseInt(item.data("id"))); - if (parts.length) { + if (parts.length === 0) { $('#pairables .listitem').addClass('selected'); parts = $('#pairables .selected.listitem').map(item => parseInt(item.data("id"))); } diff --git a/view-webapp/src/main/webapp/js/tour-teams.inc.js b/view-webapp/src/main/webapp/js/tour-teams.inc.js index c2f0dc4..96d3fa2 100644 --- a/view-webapp/src/main/webapp/js/tour-teams.inc.js +++ b/view-webapp/src/main/webapp/js/tour-teams.inc.js @@ -13,10 +13,14 @@ function split(teams) { let promises = teams.map(team => api.deleteJson(`tour/${tour_id}/team/${team}`)); Promise.all(promises) .then(rsts => { + let all = true; + let any = false; for (let rst of rsts) { + all = all && rst.success; + any = any || rst.success; if (!rst.success) console.error(rst.error) } - document.location.reload(); + if (any) document.location.reload(); }); } @@ -28,6 +32,10 @@ onLoad(() => { }); $('#split').on('click', e => { let rows = $('#teams .selected.listitem') + if (rows.length == 0) { + $('#teams .listitem').addClass('selected'); + rows = $('#teams .selected.listitem'); + } let teams = rows.map(item => parseInt(item.data("id"))); if (teams.length !== 0) split(teams); }); diff --git a/view-webapp/src/main/webapp/tour-information.inc.html b/view-webapp/src/main/webapp/tour-information.inc.html index 6cac88e..7b2da03 100644 --- a/view-webapp/src/main/webapp/tour-information.inc.html +++ b/view-webapp/src/main/webapp/tour-information.inc.html @@ -63,9 +63,9 @@