View team on registration page ; review code of constraints on teams updates
This commit is contained in:
@@ -36,6 +36,11 @@ object TeamHandler: PairgothApiHandler {
|
|||||||
val team = tournament.teams[id] ?: badRequest("invalid team id")
|
val team = tournament.teams[id] ?: badRequest("invalid team id")
|
||||||
val payload = getObjectPayload(request)
|
val payload = getObjectPayload(request)
|
||||||
val updated = tournament.teamFromJson(payload, team)
|
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.teams[updated.id] = updated
|
||||||
tournament.dispatchEvent(TeamUpdated, request, team.toJson())
|
tournament.dispatchEvent(TeamUpdated, request, team.toJson())
|
||||||
return Json.Object("success" to true)
|
return Json.Object("success" to true)
|
||||||
@@ -45,7 +50,7 @@ object TeamHandler: PairgothApiHandler {
|
|||||||
val tournament = getTournament(request)
|
val tournament = getTournament(request)
|
||||||
if (tournament !is TeamTournament) badRequest("tournament is not a team tournament")
|
if (tournament !is TeamTournament) badRequest("tournament is not a team tournament")
|
||||||
val id = getSubSelector(request)?.toIntOrNull() ?: badRequest("missing or invalid team selector")
|
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");
|
badRequest("team is playing");
|
||||||
}
|
}
|
||||||
tournament.teams.remove(id) ?: badRequest("invalid team id")
|
tournament.teams.remove(id) ?: badRequest("invalid team id")
|
||||||
|
@@ -243,6 +243,8 @@ class TeamTournament(
|
|||||||
|
|
||||||
fun pairedTeams() = super.pairedPlayers()
|
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() = super.pairedPlayers().flatMap { pairables[it]!!.asTeam()!!.playerIds }.toSet()
|
||||||
|
|
||||||
override fun pairedPlayers(round: Int) = super.pairedPlayers(round).flatMap { pairables[it]!!.asTeam()!!.playerIds }.toSet()
|
override fun pairedPlayers(round: Int) = super.pairedPlayers(round).flatMap { pairables[it]!!.asTeam()!!.playerIds }.toSet()
|
||||||
|
@@ -17,6 +17,14 @@ import kotlin.io.path.walk
|
|||||||
class PairgothTool {
|
class PairgothTool {
|
||||||
fun toMap(array: Json.Array) = array.map { ser -> ser as Json.Object }.associateBy { it.getLong("id")!! }
|
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 countFinals(array: Json.Array) = array.map { ser -> ser as Json.Object }.count { it.getBoolean("final") ?: false }
|
||||||
|
|
||||||
fun getCriteria() = mapOf(
|
fun getCriteria() = mapOf(
|
||||||
|
@@ -32,13 +32,13 @@
|
|||||||
</div>
|
</div>
|
||||||
<div id="pairing-lists">
|
<div id="pairing-lists">
|
||||||
<div id="pairing-left">
|
<div id="pairing-left">
|
||||||
<div id="pairables" class="multi-select" title="pairable players">
|
<div id="pairables" class="multi-select" title="pairable #if($tour.type == 'INDIVIDUAL')players#{else}teams#end">
|
||||||
#foreach($p in $pairables)
|
#foreach($p in $pairables)
|
||||||
#set($part = $pmap[$p])
|
#set($part = $pmap[$p])
|
||||||
<div data-id="$part.id" class="listitem pairable"><span class="name">$part.name#if($part.firstname) $part.firstname#end</span><span>#rank($part.rank)#if($part.country) $part.country#end</span></div>
|
<div data-id="$part.id" class="listitem pairable"><span class="name">$part.name#if($part.firstname) $part.firstname#end</span><span>#rank($part.rank)#if($part.country) $part.country#end</span></div>
|
||||||
#end
|
#end
|
||||||
</div>
|
</div>
|
||||||
<div id="unpairables" class="multi-select" title="unpairable players">
|
<div id="unpairables" class="multi-select" title="unpairable #if($tour.type == 'INDIVIDUAL')players#{else}teams#end">
|
||||||
#foreach($p in $unpairables)
|
#foreach($p in $unpairables)
|
||||||
#set($part = $pmap[$p])
|
#set($part = $pmap[$p])
|
||||||
<div data-id="$part.id" class="listitem unpairable"><span class="name">$part.name#if($part.firstname) $part.firstname#end</span><span>#rank($part.rank)#if($part.country) $part.country#end</span></div>
|
<div data-id="$part.id" class="listitem unpairable"><span class="name">$part.name#if($part.firstname) $part.firstname#end</span><span>#rank($part.rank)#if($part.country) $part.country#end</span></div>
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
## Pairgo, rengo and teams of individuals
|
## Pairgo, rengo and teams of individuals
|
||||||
#set($teams = $api.get("tour/${params.id}/team"))
|
#set($teams = $api.get("tour/${params.id}/team"))
|
||||||
#set($pmap = $utils.toMap($teams))
|
#set($pmap = $utils.toMap($teams))
|
||||||
|
#set($tmap = $utils.getTeamMap($teams))
|
||||||
#end
|
#end
|
||||||
|
|
||||||
## Team players do not have an individual MMS
|
## Team players do not have an individual MMS
|
||||||
@@ -66,6 +67,9 @@
|
|||||||
<th data-sort-default="1" aria-sort="ascending">Rating</th>
|
<th data-sort-default="1" aria-sort="ascending">Rating</th>
|
||||||
#if($tour.type == 'INDIVIDUAL' && $tour.pairing.type == 'MAC_MAHON')
|
#if($tour.type == 'INDIVIDUAL' && $tour.pairing.type == 'MAC_MAHON')
|
||||||
<th>MMS</th>
|
<th>MMS</th>
|
||||||
|
#end
|
||||||
|
#if($tour.type != 'INDIVIDUAL')
|
||||||
|
<th>Team</th>
|
||||||
#end
|
#end
|
||||||
<th>Participation</th>
|
<th>Participation</th>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -91,6 +95,15 @@
|
|||||||
<td>$part.rating</td>
|
<td>$part.rating</td>
|
||||||
#if($tour.type == 'INDIVIDUAL' && $tour.pairing.type == 'MAC_MAHON')
|
#if($tour.type == 'INDIVIDUAL' && $tour.pairing.type == 'MAC_MAHON')
|
||||||
<td>$!mmsPlayersMap[$part.id]</td>
|
<td>$!mmsPlayersMap[$part.id]</td>
|
||||||
|
#end
|
||||||
|
#if($tour.type != 'INDIVIDUAL')
|
||||||
|
#set($teamId = $tmap[$part.id])
|
||||||
|
#if($teamId)
|
||||||
|
#set($teamName = $!pmap[$teamId].name)
|
||||||
|
#end
|
||||||
|
<td title="$esc.html($teamName)">
|
||||||
|
$esc.html($utils.truncate($!teamName, 10))
|
||||||
|
</td>
|
||||||
#end
|
#end
|
||||||
<td class="participating" data-sort="#if($part.skip)$part.skip.size()/part.skip#{else}0#end">
|
<td class="participating" data-sort="#if($part.skip)$part.skip.size()/part.skip#{else}0#end">
|
||||||
<div class="participation">
|
<div class="participation">
|
||||||
|
Reference in New Issue
Block a user