diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/ApiHandler.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/ApiHandler.kt index c903d17..891d240 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/ApiHandler.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/ApiHandler.kt @@ -13,7 +13,7 @@ interface ApiHandler { when (request.method) { "GET" -> get(request, response) "POST" -> post(request) - "PUT" -> put(request) + "PUT" -> put(request) "DELETE" -> delete(request) else -> notImplemented() } diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/PairgothApiHandler.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/PairgothApiHandler.kt index 9c4e41f..58a813a 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/PairgothApiHandler.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/PairgothApiHandler.kt @@ -16,7 +16,7 @@ interface PairgothApiHandler: ApiHandler { fun Tournament<*>.dispatchEvent(event: Event, data: Json? = null) { Event.dispatch(event, Json.Object("tournament" to id, "data" to data)) // when storage is not in memory, the tournament has to be persisted - if (event != Event.tournamentAdded && event != Event.tournamentDeleted && event != Event.gameUpdated) + if (event != Event.tournamentAdded && event != Event.tournamentDeleted) Store.replaceTournament(this) } 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 ef15003..ac005ce 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 @@ -71,6 +71,7 @@ object PairingHandler: PairgothApiHandler { val playing = (tournament.games(round).values).filter { it.id != gameId }.flatMap { listOf(it.black, it.white) }.toSet() + if (game.result != Game.Result.UNKNOWN) badRequest("Game already has a result"); game.black = payload.getID("b") ?: badRequest("missing black player id") game.white = payload.getID("w") ?: badRequest("missing white player id") tournament.recomputeDUDD(round, game.id) diff --git a/view-webapp/src/main/sass/tour.scss b/view-webapp/src/main/sass/tour.scss index 78386a0..0c565f1 100644 --- a/view-webapp/src/main/sass/tour.scss +++ b/view-webapp/src/main/sass/tour.scss @@ -202,6 +202,9 @@ } } } + #pairables { + margin-bottom: 1em; + } #paired { .listitem { position: relative; diff --git a/view-webapp/src/main/webapp/js/domhelper.js b/view-webapp/src/main/webapp/js/domhelper.js index e2c54d8..d19eb3d 100644 --- a/view-webapp/src/main/webapp/js/domhelper.js +++ b/view-webapp/src/main/webapp/js/domhelper.js @@ -120,8 +120,14 @@ Element.prototype.hide = function() { return this; } NodeList.prototype.text = function(txt) { - this.item(0).text(txt); - return this; + if (typeof(txt) === 'undefined') { + return this.item(0).text(); + } else { + this.forEach(elem => { + elem.text(txt); + }); + return this; + } } Element.prototype.text = function(txt) { if (typeof(txt) === 'undefined') { 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 55a3011..6e0ebba 100644 --- a/view-webapp/src/main/webapp/js/tour-pairing.inc.js +++ b/view-webapp/src/main/webapp/js/tour-pairing.inc.js @@ -18,6 +18,26 @@ function unpair(games) { }); } +function editGame(game) { + let t = game.find('.table'); + let w = game.find('.white'); + let b = game.find('.black'); + let h = game.find('.handicap'); + + let form = $('#pairing-form')[0]; + form.val('id', game.data('id')); + form.val('t', t.data('value')); + form.val('w', w.data('id')); + $('#edit-pairing-white').text(w.text()); + form.val('b', b.data('id')); + $('#edit-pairing-black').text(b.text()); + form.val('h', h.data('value')); + + $('#update-pairing').addClass('disabled'); + + modal('edit-pairing'); +} + onLoad(()=>{ $('.listitem').on('click', e => { if (e.shiftKey && typeof(focused) !== 'undefined') { @@ -31,13 +51,17 @@ onLoad(()=>{ let parent = e.target.closest('.multi-select'); let children = parent.childNodes.filter('.listitem'); for (let j = from; j <= to; ++j) { new Tablesort($('#players')[0]); - children.item(j).addClass('selected'); children.item(j).attr('draggable', true); } } else { let target = e.target.closest('.listitem'); - focused = target.toggleClass('selected').attr('draggable', target.hasClass('selected')); + if (e.detail === 1) { + focused = target.toggleClass('selected').attr('draggable', target.hasClass('selected')); + } else { + focused = target.attr('draggable', target.hasClass('selected')); + editGame(focused); + } } }); $('#pair').on('click', e => { @@ -56,4 +80,39 @@ onLoad(()=>{ } unpair(games); }); + $('#pairing-form [name]').on('input', e => { + $('#update-pairing').removeClass('disabled'); + }); + $('#pairing-exchange').on('click', e => { + let form = $('#pairing-form')[0]; + let w = form.val('w'); + let b = form.val('b'); + form.val('w', b); + form.val('b', w); + let wName = $('#edit-pairing-white').text(); + let bName = $('#edit-pairing-black').text(); + $('#edit-pairing-white').text(bName); + $('#edit-pairing-black').text(wName); + $('#update-pairing').removeClass('disabled'); + }); + $('#pairing-form').on('submit', e => { + e.preventDefault(); + return false; + }); + $('#update-pairing').on('click', e => { + let form = $('#pairing-form')[0]; + let game = { + id: form.val('id'), + t: form.val('t'), + w: form.val('w'), + b: form.val('b'), + h: form.val('h') + } + api.putJson(`tour/${tour_id}/pair/${activeRound}`, game) + .then(game => { + if (game !== 'error') { + document.location.reload(); + } + }); + }); }); diff --git a/view-webapp/src/main/webapp/js/tour-registration.inc.js b/view-webapp/src/main/webapp/js/tour-registration.inc.js index eb494ef..e2f6a4c 100644 --- a/view-webapp/src/main/webapp/js/tour-registration.inc.js +++ b/view-webapp/src/main/webapp/js/tour-registration.inc.js @@ -122,7 +122,6 @@ onLoad(() => { $('#player-form')[0].dispatchEvent(new CustomEvent('submit', {cancelable: true})); }); $('#player-form').on('submit', e => { - ("submitting!!") e.preventDefault(); let form = $('#player-form')[0]; let player = { 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 7889f1e..9320a53 100644 --- a/view-webapp/src/main/webapp/js/tour-results.inc.js +++ b/view-webapp/src/main/webapp/js/tour-results.inc.js @@ -9,9 +9,9 @@ function setResult(id, result) { 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 'w': white.addClass('winner'); black.addClass('looser'); dispResult = '1-0'; break; + case 'b': black.addClass('winner'); white.addClass('looser'); dispResult = '0-1'; break; + case '=': dispResult = '½-½'; 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; diff --git a/view-webapp/src/main/webapp/tour-pairing.inc.html b/view-webapp/src/main/webapp/tour-pairing.inc.html index 05f2a95..52d1ca3 100644 --- a/view-webapp/src/main/webapp/tour-pairing.inc.html +++ b/view-webapp/src/main/webapp/tour-pairing.inc.html @@ -52,11 +52,11 @@ #set($white = $pmap[$game.w]) #set($black = $pmap[$game.b])