From a70e5df576da45244888161b82d4071d394b5d35 Mon Sep 17 00:00:00 2001 From: Claude Brisson Date: Thu, 21 Dec 2023 22:33:15 +0100 Subject: [PATCH] Pairing and unpairing functional --- .../src/main/webapp/js/tour-pairing.inc.js | 13 +++++++ .../src/main/webapp/tour-pairing.inc.html | 39 +++++++++++++------ 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/view-webapp/src/main/webapp/js/tour-pairing.inc.js b/view-webapp/src/main/webapp/js/tour-pairing.inc.js index 03a28be..78a709e 100644 --- a/view-webapp/src/main/webapp/js/tour-pairing.inc.js +++ b/view-webapp/src/main/webapp/js/tour-pairing.inc.js @@ -9,6 +9,15 @@ function pair(parts) { }); } +function unpair(games) { + api.deleteJson(`tour/${tour_id}/pair/${activeRound}`, games) + .then(rst => { + if (rst !== 'error') { + document.location.reload(); + } + }); +} + onLoad(()=>{ $('.listitem').on('click', e => { if (e.shiftKey && typeof(focused) !== 'undefined') { @@ -34,4 +43,8 @@ onLoad(()=>{ let parts = $('#pairables')[0].childNodes.filter('.selected.listitem').map(item => parseInt(item.data("id"))); pair(parts); }); + $('#unpair').on('click', e => { + let games = $('#paired')[0].childNodes.filter('.selected.listitem').map(item => parseInt(item.data("id"))); + unpair(games); + }); }); diff --git a/view-webapp/src/main/webapp/tour-pairing.inc.html b/view-webapp/src/main/webapp/tour-pairing.inc.html index 59ba431..7804130 100644 --- a/view-webapp/src/main/webapp/tour-pairing.inc.html +++ b/view-webapp/src/main/webapp/tour-pairing.inc.html @@ -1,3 +1,18 @@ +#set($roundPairing = $api.get("tour/${params.id}/pair/$round")) +#if($roundPairing.error) + + #set($pairables = []) + #set($games = []) + #set($unpairables = []) +#else + #set($pairables = $roundPairing.pairables) + #set($games = $roundPairing.games) + #set($unpairables = $roundPairing.unpairables) +#end
@@ -8,18 +23,9 @@
-#set($pairables = $api.get("tour/${params.id}/pair/$round")) -#if($pairables.isObject() && $pairables.error) - -#else - #foreach($p in $pairables) - #set($part = $pmap[$p]) -
$part.name $part.firstname$part.country #rank($part.rank)
- #end +#foreach($p in $pairables) + #set($part = $pmap[$p]) +
$part.name $part.firstname#rank($part.rank) $part.country
#end
@@ -33,9 +39,18 @@
+#foreach($game in $games) + #set($white = $pmap[$game.w]) + #set($black = $pmap[$game.b]) +
#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.h
+#end
+#foreach($p in $unpairables) + #set($part = $pmap[$p]) +
$part.name $part.firstname#rank($part.rank) $part.country
+#end