Results tab ok

This commit is contained in:
Claude Brisson
2023-12-24 07:45:26 +01:00
parent 36f9fe6f09
commit 864ba82b57
7 changed files with 74 additions and 7 deletions

View File

@@ -33,6 +33,7 @@ object PairingHandler: PairgothApiHandler {
override fun post(request: HttpServletRequest): Json { override fun post(request: HttpServletRequest): Json {
val tournament = getTournament(request) val tournament = getTournament(request)
val round = getSubSelector(request)?.toIntOrNull() ?: badRequest("invalid round number") val round = getSubSelector(request)?.toIntOrNull() ?: badRequest("invalid round number")
if (round > tournament.lastRound() + 1) badRequest("invalid round: previous round has not been played")
val payload = getArrayPayload(request) val payload = getArrayPayload(request)
val allPlayers = payload.size == 1 && payload[0] == "all" val allPlayers = payload.size == 1 && payload[0] == "all"
//if (!allPlayers && tournament.pairing.type == PairingType.SWISS) badRequest("Swiss pairing requires all pairable players") //if (!allPlayers && tournament.pairing.type == PairingType.SWISS) badRequest("Swiss pairing requires all pairable players")

View File

@@ -21,6 +21,7 @@ object ResultsHandler: PairgothApiHandler {
override fun put(request: HttpServletRequest): Json { override fun put(request: HttpServletRequest): Json {
val tournament = getTournament(request) val tournament = getTournament(request)
val round = getSubSelector(request)?.toIntOrNull() ?: badRequest("invalid round number") val round = getSubSelector(request)?.toIntOrNull() ?: badRequest("invalid round number")
if (round != tournament.lastRound()) badRequest("cannot enter results in other rounds but the last")
val payload = getObjectPayload(request) val payload = getObjectPayload(request)
val game = tournament.games(round)[payload.getInt("id")] ?: badRequest("invalid game id") val game = tournament.games(round)[payload.getInt("id")] ?: badRequest("invalid game id")
game.result = Game.Result.fromSymbol(payload.getChar("result") ?: badRequest("missing result")) game.result = Game.Result.fromSymbol(payload.getChar("result") ?: badRequest("missing result"))

View File

@@ -212,6 +212,7 @@ object OpenGotha {
} }
</Players> </Players>
<Games> <Games>
// TODO - table number is not any more kinda random like this
${(1..tournament.lastRound()).map { tournament.games(it) }.flatMapIndexed { index, games -> ${(1..tournament.lastRound()).map { tournament.games(it) }.flatMapIndexed { index, games ->
games.values.mapIndexed { table, game -> games.values.mapIndexed { table, game ->
Triple(index + 1, table , game) Triple(index + 1, table , game)

View File

@@ -214,12 +214,22 @@
#results-list { #results-list {
text-align: center; text-align: center;
.player, .result { .player, .result {
background-color: white;
color: black;
cursor: pointer; cursor: pointer;
&:hover { &:hover {
background: rgba(0,0,0,.05); background: rgba(0,0,0,.05);
color: rgba(0,0,0,.95); color: rgba(0,0,0,.95);
} }
} }
.player {
&.winner {
font-weight: bold;
}
&.looser {
font-style: italic;
}
}
} }
} }

View File

@@ -64,7 +64,7 @@ Node.prototype.offset = function() {
return { top: _y, left: _x }; return { top: _y, left: _x };
} }
NodeList.prototype.offset = function() { NodeList.prototype.offset = function() {
this.item(0).offset(); return this.item(0).offset();
} }
Element.prototype.attr = function (key, value) { Element.prototype.attr = function (key, value) {
if (typeof(value) === 'undefined') { if (typeof(value) === 'undefined') {
@@ -94,7 +94,7 @@ Element.prototype.data = function (key, value) {
} }
NodeList.prototype.data = function(key, value) { NodeList.prototype.data = function(key, value) {
if (typeof(value) === 'undefined') { if (typeof(value) === 'undefined') {
this.item(0).data(key); return this.item(0).data(key);
} else { } else {
this.forEach(elem => { this.forEach(elem => {
elem.data(key, value); elem.data(key, value);
@@ -108,6 +108,7 @@ NodeList.prototype.show = function() {
} }
Element.prototype.show = function() { Element.prototype.show = function() {
this.style.display = 'block'; this.style.display = 'block';
return this;
} }
NodeList.prototype.hide = function() { NodeList.prototype.hide = function() {
this.item(0).hide(); this.item(0).hide();
@@ -115,15 +116,18 @@ NodeList.prototype.hide = function() {
} }
Element.prototype.hide = function() { Element.prototype.hide = function() {
this.style.display = 'none'; this.style.display = 'none';
return this;
} }
NodeList.prototype.text = function(txt) { NodeList.prototype.text = function(txt) {
this.item(0).text(txt); this.item(0).text(txt);
return this;
} }
Element.prototype.text = function(txt) { Element.prototype.text = function(txt) {
if (typeof(txt) === 'undefined') { if (typeof(txt) === 'undefined') {
return this.textContent; return this.textContent;
} else { } else {
this.textContent = txt; this.textContent = txt;
return this;
} }
} }
NodeList.prototype.item = function (i) { NodeList.prototype.item = function (i) {
@@ -170,6 +174,7 @@ Element.prototype.val = function(value) {
NodeList.prototype.focus = function() { NodeList.prototype.focus = function() {
let first = this.item(0); let first = this.item(0);
if (first) first.focus(); if (first) first.focus();
return this;
} }
Element.prototype.index = function(selector) { Element.prototype.index = function(selector) {

View File

@@ -1,3 +1,45 @@
function setResult(id, result) {
api.putJson(`tour/${tour_id}/res/${activeRound}`, { id: id, result: result })
.then(res => {
if (res !== 'error') {
let row = $(`#results-list tr#result-${id}`);
row.find('td').removeClass('winner').removeClass('looser');
let white = row.find('td.white');
let black = row.find('td.black');
let dispResult = result;
switch (result) {
case '?': break;
case 'w': white.addClass('winner'); black.addClass('looser'); dispResult = 'w+'; break;
case 'b': black.addClass('winner'); white.addClass('looser'); dispResult = 'b+'; break;
case '=': break;
case 'X': break;
case '#': white.addClass('winner'); black.addClass('winner'); dispResult = '1-1'; break;
case '0': white.addClass('looser'); black.addClass('looser'); dispResult = '0-0'; break;
}
let resultCell = row.find('td.result');
resultCell.text(dispResult).data('result', result);
}
})
}
const results = [ '?', 'w', 'b', '=', 'X', '#', '0' ];
onLoad(()=>{ onLoad(()=>{
new Tablesort($('#results-table')[0]); new Tablesort($('#results-table')[0]);
}); $('#results-table .player').on('click', e => {
let cell = e.target.closest('.player');
let gameId = e.target.closest('tr').data('id');
let result = cell.hasClass('white') ? 'w' : 'b';
setResult(gameId, result);
});
$('#results-table .result').on('click', e => {
let cell = e.target.closest('.result');
let gameId = e.target.closest('tr').data('id');
let result = cell.data('result');
let index = results.indexOf(result);
console.log(index)
result = results[(index + 1)%results.length];
console.log(result)
setResult(gameId, result);
});
});

View File

@@ -1,4 +1,10 @@
<div class="tab-content" id="results"> <div class="tab-content" id="results">
<div id="results-round">
Results for round
<button class="ui floating choose-round prev-round button">&laquo;</button>
<span class="active-round">$round</span>
<button class="ui floating choose-round next-round button">&raquo;</button>
</div>
<div id="results-list" class="roundbox"> <div id="results-list" class="roundbox">
<table id="results-table" class="ui celled striped table"> <table id="results-table" class="ui celled striped table">
<thead class="centered"> <thead class="centered">
@@ -8,15 +14,16 @@
<th>result</th> <th>result</th>
</thead> </thead>
<tbody> <tbody>
#set($dispRst = {'?':'?', 'w':'w+', 'b':'b+', '=':'=', 'X':'X', '#':'1-1', '0':'0-0'})
#foreach($game in $games) #foreach($game in $games)
#set($white = $pmap[$game.w]) #set($white = $pmap[$game.w])
#set($black = $pmap[$game.b]) #set($black = $pmap[$game.b])
#if($black && $white) #if($black && $white)
<tr data-id="$game.id"> <tr id="result-$game.id" data-id="$game.id">
<td>#$game.t</td> <td>#$game.t</td>
<td class="player" data-id="$white.id" data-sort="$white.name $white.firstname"><span class="white">#if($white)$white.name $white.firstname #rank($white.rank)#{else}BIP#end</span></td> <td class="white player #if($game.r == 'w' || $game.r == '#') winner #elseif($game.r == 'b' || $game.r == '0') looser #end" data-id="$white.id" data-sort="$white.name $white.firstname"><span>#if($white)$white.name $white.firstname #rank($white.rank)#{else}BIP#end</span></td>
<td class="player" data-id="$black.id" data-sort="$black.name $black.firstname"><span class="black">#if($black)$black.name $black.firstname #rank($black.rank)#{else}BIP#end</span></td> <td class="black player #if($game.r == 'b' || $game.r == '#') winner #elseif($game.r == 'w' || $game.r == '0') looser #end" data-id="$black.id" data-sort="$black.name $black.firstname"><span>#if($black)$black.name $black.firstname #rank($black.rank)#{else}BIP#end</span></td>
<td class="result centered">$game.r</td> <td class="result centered" data-result="$game.r">$dispRst[$game.r]</td>
</tr> </tr>
#end #end
#end #end