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 35f1a5e..daef968 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 @@ -27,4 +27,14 @@ object ResultsHandler: PairgothApiHandler { tournament.dispatchEvent(Event.ResultUpdated, request, Json.Object("round" to round, "data" to game)) return Json.Object("success" to true) } + + override fun delete(request: HttpServletRequest, response: HttpServletResponse): Json { + val tournament = getTournament(request) + val round = getSubSelector(request)?.toIntOrNull() ?: badRequest("invalid round number") + for (game in tournament.games(round).values) { + game.result = Game.Result.UNKNOWN + } + tournament.dispatchEvent(Event.ResultsCleared, request, Json.Object("round" to round)) + return Json.Object("success" to true) + } } diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/server/Event.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/server/Event.kt index 57147ee..82fa26d 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/server/Event.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/server/Event.kt @@ -17,6 +17,7 @@ enum class Event { GamesDeleted, GameUpdated, ResultUpdated, + ResultsCleared, TablesRenumbered ; diff --git a/doc/API.md b/doc/API.md index 4a079a8..d40645e 100644 --- a/doc/API.md +++ b/doc/API.md @@ -17,7 +17,7 @@ POST, PUT and DELETE requests return either the 200 HTTP code with `{ "success": + /api/tour/#tid/team GET POST Team handling + /api/tour/#tid/team/#tid GET PUT DELETE Team handling + /api/tour/#tid/pair/#rn GET POST PUT DELETE Pairing -+ /api/tour/#tid/res/#rn GET PUT Results ++ /api/tour/#tid/res/#rn GET PUT DELETE Results + /api/tour/#tid/standings GET Standings + /api/tour/#tid/stand/#rn GET Standings @@ -136,6 +136,12 @@ POST, PUT and DELETE requests return either the 200 HTTP code with `{ "success": *output* `{ "success": true }` ++ `DELETE /api/tour/#tip/res/#rn` Clear all results (put back all results to unknown) + + *input* none + + *output* `{ "success": true }` + ## Standings + `GET /api/tour/#tid/stand/#rn` Get standings after round #rn (or initial standings for round '0') 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 04f6c79..ef0ddd3 100644 --- a/view-webapp/src/main/webapp/js/tour-results.inc.js +++ b/view-webapp/src/main/webapp/js/tour-results.inc.js @@ -41,6 +41,15 @@ function setResult(id, result, previous) { }) } +function clearResults() { + api.deleteJson(`tour/${tour_id}/res/${activeRound}`) + .then(res => { + if (res !== 'error') { + document.location.reload(); + } + }) +} + const results = [ '?', 'w', 'b', '=', 'X', '#', '0' ]; onLoad(()=>{ @@ -70,4 +79,9 @@ onLoad(()=>{ $('#results-table tbody tr').removeClass('filtered'); } }); + $('#clear-results').on('click', e => { + if (confirm($('#confirmation')[0].textContent)) { + clearResults(); + } + }); }); diff --git a/view-webapp/src/main/webapp/tour-results.inc.html b/view-webapp/src/main/webapp/tour-results.inc.html index e7c84c1..a95ba5f 100644 --- a/view-webapp/src/main/webapp/tour-results.inc.html +++ b/view-webapp/src/main/webapp/tour-results.inc.html @@ -39,4 +39,13 @@ +
+ +
+ +