Add an API call and a button to reset all results for a round

This commit is contained in:
Claude Brisson
2024-06-13 20:00:52 +02:00
parent 0fd9f6e27a
commit f7d42c399c
5 changed files with 41 additions and 1 deletions

View File

@@ -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)
}
}

View File

@@ -17,6 +17,7 @@ enum class Event {
GamesDeleted,
GameUpdated,
ResultUpdated,
ResultsCleared,
TablesRenumbered
;

View File

@@ -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')

View File

@@ -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();
}
});
});

View File

@@ -39,4 +39,13 @@
</tbody>
</table>
</div>
<div class="form-actions">
<button id="clear-results" class="ui orange right labeled icon floating info button">
<i class="trash icon"></i>
Clear results
</button>
</div>
</div>
<div id="confirmation" class="hidden">
Clear all results for round <span>$round</span> ?
</div>