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 a638382..5a16cd5 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 @@ -36,6 +36,11 @@ object TeamHandler: PairgothApiHandler { val team = tournament.teams[id] ?: badRequest("invalid team id") val payload = getObjectPayload(request) val updated = tournament.teamFromJson(payload, team) + for (round in 1..tournament.lastRound()) { + if (tournament.pairedTeams(round).contains(team.id) && !updated.canPlay(round)) { + badRequest("team is playing round #$round, number of pairable players cannot change for this round") + } + } tournament.teams[updated.id] = updated tournament.dispatchEvent(TeamUpdated, request, team.toJson()) return Json.Object("success" to true) @@ -45,7 +50,7 @@ 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)) { + if (tournament.pairedTeams().contains(id)) { badRequest("team is playing"); } tournament.teams.remove(id) ?: badRequest("invalid team 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 b517d37..5452804 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 @@ -243,6 +243,8 @@ class TeamTournament( fun pairedTeams() = super.pairedPlayers() + fun pairedTeams(round: Int) = super.pairedPlayers(round) + override fun pairedPlayers() = super.pairedPlayers().flatMap { pairables[it]!!.asTeam()!!.playerIds }.toSet() override fun pairedPlayers(round: Int) = super.pairedPlayers(round).flatMap { pairables[it]!!.asTeam()!!.playerIds }.toSet() diff --git a/view-webapp/src/main/kotlin/org/jeudego/pairgoth/view/PairgothTool.kt b/view-webapp/src/main/kotlin/org/jeudego/pairgoth/view/PairgothTool.kt index 8212e5f..c2ce9a1 100644 --- a/view-webapp/src/main/kotlin/org/jeudego/pairgoth/view/PairgothTool.kt +++ b/view-webapp/src/main/kotlin/org/jeudego/pairgoth/view/PairgothTool.kt @@ -17,6 +17,14 @@ import kotlin.io.path.walk class PairgothTool { fun toMap(array: Json.Array) = array.map { ser -> ser as Json.Object }.associateBy { it.getLong("id")!! } + fun getTeamMap(array: Json.Array) = array.flatMap { ser -> (ser as Json.Object).getArray("players")!!.map { Pair(it, ser.getLong("id")!!) } }.toMap() + + fun truncate(disp: String?, length: Int): String { + if (disp == null) return "" + if (disp.length <= length) return disp + return disp.substring(0, length) + "…" + } + fun countFinals(array: Json.Array) = array.map { ser -> ser as Json.Object }.count { it.getBoolean("final") ?: false } fun getCriteria() = mapOf( diff --git a/view-webapp/src/main/webapp/tour-pairing.inc.html b/view-webapp/src/main/webapp/tour-pairing.inc.html index 1933c4b..aaceec9 100644 --- a/view-webapp/src/main/webapp/tour-pairing.inc.html +++ b/view-webapp/src/main/webapp/tour-pairing.inc.html @@ -32,13 +32,13 @@