Various bugfixes for teams support
This commit is contained in:
@@ -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 {
|
||||
|
@@ -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(";")
|
||||
};${
|
||||
|
@@ -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)
|
||||
|
@@ -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<Int>() // skipped rounds
|
||||
open val skip = mutableSetOf<Int>() // skipped rounds
|
||||
|
||||
fun equals(other: Pairable): Boolean {
|
||||
return id == other.id
|
||||
|
@@ -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<Int> }
|
||||
}
|
||||
|
||||
fun teamFromJson(json: Json.Object, default: TeamTournament.Team? = null): Team {
|
||||
|
@@ -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")));
|
||||
}
|
||||
|
@@ -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);
|
||||
});
|
||||
|
@@ -63,9 +63,9 @@
|
||||
<select name="type">
|
||||
<option value="INDIVIDUAL" #if(!$tour || $tour.type == 'INDIVIDUAL') selected #end>Individual players</option>
|
||||
<option value="PAIRGO" #if($tour && $tour.type == 'PAIRGO') selected #end>Pair-go tournament</option>
|
||||
#* TODO
|
||||
<option value="RENGO2" #if($tour && $tour.type == 'RENGO2') selected #end>Rengo with 2 players teams</option>
|
||||
<option value="RENGO3" #if($tour && $tour.type == 'RENGO3') selected #end>Rengo with 3 players team</option>
|
||||
#* TODO
|
||||
<option value="TEAM2" #if($tour && $tour.type == 'TEAM2') selected #end>Team of 2 individual players</option>
|
||||
<option value="TEAM3" #if($tour && $tour.type == 'TEAM3') selected #end>Team of 3 individual players</option>
|
||||
<option value="TEAM4" #if($tour && $tour.type == 'TEAM4') selected #end>Team of 4 individual players</option>
|
||||
|
Reference in New Issue
Block a user