From 864ba82b57fa6d0150465878149058dfa528a103 Mon Sep 17 00:00:00 2001 From: Claude Brisson Date: Sun, 24 Dec 2023 07:45:26 +0100 Subject: [PATCH] Results tab ok --- .../jeudego/pairgoth/api/PairingHandler.kt | 1 + .../jeudego/pairgoth/api/ResultsHandler.kt | 1 + .../org/jeudego/pairgoth/ext/OpenGotha.kt | 1 + view-webapp/src/main/sass/tour.scss | 10 +++++ view-webapp/src/main/webapp/js/domhelper.js | 9 +++- .../src/main/webapp/js/tour-results.inc.js | 44 ++++++++++++++++++- .../src/main/webapp/tour-results.inc.html | 15 +++++-- 7 files changed, 74 insertions(+), 7 deletions(-) diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/PairingHandler.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/PairingHandler.kt index 8edc824..e48faab 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/PairingHandler.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/PairingHandler.kt @@ -33,6 +33,7 @@ object PairingHandler: PairgothApiHandler { override fun post(request: HttpServletRequest): Json { val tournament = getTournament(request) 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 allPlayers = payload.size == 1 && payload[0] == "all" //if (!allPlayers && tournament.pairing.type == PairingType.SWISS) badRequest("Swiss pairing requires all pairable players") diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/ResultsHandler.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/ResultsHandler.kt index 372fdc6..135647f 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/ResultsHandler.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/ResultsHandler.kt @@ -21,6 +21,7 @@ object ResultsHandler: PairgothApiHandler { override fun put(request: HttpServletRequest): Json { val tournament = getTournament(request) 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 game = tournament.games(round)[payload.getInt("id")] ?: badRequest("invalid game id") game.result = Game.Result.fromSymbol(payload.getChar("result") ?: badRequest("missing result")) diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/ext/OpenGotha.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/ext/OpenGotha.kt index c49f5a5..c4b37ec 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/ext/OpenGotha.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/ext/OpenGotha.kt @@ -212,6 +212,7 @@ object OpenGotha { } + // TODO - table number is not any more kinda random like this ${(1..tournament.lastRound()).map { tournament.games(it) }.flatMapIndexed { index, games -> games.values.mapIndexed { table, game -> Triple(index + 1, table , game) diff --git a/view-webapp/src/main/sass/tour.scss b/view-webapp/src/main/sass/tour.scss index 18d162c..bc119e8 100644 --- a/view-webapp/src/main/sass/tour.scss +++ b/view-webapp/src/main/sass/tour.scss @@ -214,12 +214,22 @@ #results-list { text-align: center; .player, .result { + background-color: white; + color: black; cursor: pointer; &:hover { background: rgba(0,0,0,.05); color: rgba(0,0,0,.95); } } + .player { + &.winner { + font-weight: bold; + } + &.looser { + font-style: italic; + } + } } } diff --git a/view-webapp/src/main/webapp/js/domhelper.js b/view-webapp/src/main/webapp/js/domhelper.js index a3e5807..148954f 100644 --- a/view-webapp/src/main/webapp/js/domhelper.js +++ b/view-webapp/src/main/webapp/js/domhelper.js @@ -64,7 +64,7 @@ Node.prototype.offset = function() { return { top: _y, left: _x }; } NodeList.prototype.offset = function() { - this.item(0).offset(); + return this.item(0).offset(); } Element.prototype.attr = function (key, value) { if (typeof(value) === 'undefined') { @@ -94,7 +94,7 @@ Element.prototype.data = function (key, value) { } NodeList.prototype.data = function(key, value) { if (typeof(value) === 'undefined') { - this.item(0).data(key); + return this.item(0).data(key); } else { this.forEach(elem => { elem.data(key, value); @@ -108,6 +108,7 @@ NodeList.prototype.show = function() { } Element.prototype.show = function() { this.style.display = 'block'; + return this; } NodeList.prototype.hide = function() { this.item(0).hide(); @@ -115,15 +116,18 @@ NodeList.prototype.hide = function() { } Element.prototype.hide = function() { this.style.display = 'none'; + return this; } NodeList.prototype.text = function(txt) { this.item(0).text(txt); + return this; } Element.prototype.text = function(txt) { if (typeof(txt) === 'undefined') { return this.textContent; } else { this.textContent = txt; + return this; } } NodeList.prototype.item = function (i) { @@ -170,6 +174,7 @@ Element.prototype.val = function(value) { NodeList.prototype.focus = function() { let first = this.item(0); if (first) first.focus(); + return this; } Element.prototype.index = function(selector) { diff --git a/view-webapp/src/main/webapp/js/tour-results.inc.js b/view-webapp/src/main/webapp/js/tour-results.inc.js index 52003e8..7889f1e 100644 --- a/view-webapp/src/main/webapp/js/tour-results.inc.js +++ b/view-webapp/src/main/webapp/js/tour-results.inc.js @@ -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(()=>{ new Tablesort($('#results-table')[0]); -}); \ No newline at end of file + $('#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); + }); +}); diff --git a/view-webapp/src/main/webapp/tour-results.inc.html b/view-webapp/src/main/webapp/tour-results.inc.html index ec0667d..e10385a 100644 --- a/view-webapp/src/main/webapp/tour-results.inc.html +++ b/view-webapp/src/main/webapp/tour-results.inc.html @@ -1,4 +1,10 @@
+
+ Results for round + + $round + +
@@ -8,15 +14,16 @@ +#set($dispRst = {'?':'?', 'w':'w+', 'b':'b+', '=':'=', 'X':'X', '#':'1-1', '0':'0-0'}) #foreach($game in $games) #set($white = $pmap[$game.w]) #set($black = $pmap[$game.b]) #if($black && $white) - + - - - + + + #end #end
result
#$game.t#if($white)$white.name $white.firstname #rank($white.rank)#{else}BIP#end#if($black)$black.name $black.firstname #rank($black.rank)#{else}BIP#end$game.r#if($white)$white.name $white.firstname #rank($white.rank)#{else}BIP#end#if($black)$black.name $black.firstname #rank($black.rank)#{else}BIP#end$dispRst[$game.r]