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 @@
-
+
#foreach($p in $pairables) #set($part = $pmap[$p])
$part.name#if($part.firstname) $part.firstname#end#rank($part.rank)#if($part.country) $part.country#end
#end
-
+
#foreach($p in $unpairables) #set($part = $pmap[$p])
$part.name#if($part.firstname) $part.firstname#end#rank($part.rank)#if($part.country) $part.country#end
diff --git a/view-webapp/src/main/webapp/tour-registration.inc.html b/view-webapp/src/main/webapp/tour-registration.inc.html index 91125dc..a3475ea 100644 --- a/view-webapp/src/main/webapp/tour-registration.inc.html +++ b/view-webapp/src/main/webapp/tour-registration.inc.html @@ -6,6 +6,7 @@ ## Pairgo, rengo and teams of individuals #set($teams = $api.get("tour/${params.id}/team")) #set($pmap = $utils.toMap($teams)) + #set($tmap = $utils.getTeamMap($teams)) #end ## Team players do not have an individual MMS @@ -66,6 +67,9 @@ Rating #if($tour.type == 'INDIVIDUAL' && $tour.pairing.type == 'MAC_MAHON') MMS +#end +#if($tour.type != 'INDIVIDUAL') + Team #end Participation @@ -91,6 +95,15 @@ $part.rating #if($tour.type == 'INDIVIDUAL' && $tour.pairing.type == 'MAC_MAHON') $!mmsPlayersMap[$part.id] +#end +#if($tour.type != 'INDIVIDUAL') + #set($teamId = $tmap[$part.id]) + #if($teamId) + #set($teamName = $!pmap[$teamId].name) + #end + + $esc.html($utils.truncate($!teamName, 10)) + #end