Debug export, handle export of by player

This commit is contained in:
Claude Brisson
2023-12-27 12:19:25 +01:00
parent 797ac17b74
commit 23bb6cb86d
3 changed files with 23 additions and 7 deletions

View File

@@ -222,13 +222,14 @@ object OpenGotha {
<Games> <Games>
// TODO - table number is not any more kinda random like this // TODO - table number is not any more kinda random like this
${(1..tournament.lastRound()).map { tournament.games(it) }.flatMapIndexed { index, games -> ${(1..tournament.lastRound()).map { tournament.games(it) }.flatMapIndexed { index, games ->
games.values.mapIndexed { table, game -> games.values.mapIndexedNotNull { table, game ->
Triple(index + 1, table , game) if (game.black == 0 || game.white == 0) null
else Triple(index + 1, table , game)
} }
}.joinToString("\n") { (round, table, game) -> }.joinToString("\n") { (round, table, game) ->
"""<Game blackPlayer="${ """<Game blackPlayer="${
(tournament.pairables[game.black]!! as Player).let { black -> (tournament.pairables[game.black]!! as Player).let { black ->
"${black.name}${black.firstname}".uppercase(Locale.ENGLISH) // Use Locale.ENGLISH to transform é to É "${black.name.replace(" ", "")}${black.firstname.replace(" ", "")}".uppercase(Locale.ENGLISH) // Use Locale.ENGLISH to transform é to É
} }
}" handicap="0" knownColor="true" result="${ }" handicap="0" knownColor="true" result="${
when (game.result) { when (game.result) {
@@ -252,6 +253,20 @@ object OpenGotha {
} }
</Games> </Games>
<ByePlayer> <ByePlayer>
${
(1..tournament.lastRound()).map { round ->
tournament.games(round).values.firstNotNullOfOrNull { g ->
if (g.black == 0 || g.white == 0) g else null
}?.let {
tournament.pairables[
if (it.black == 0) it.white
else it.black
] as Player
}?.let { p ->
"<ByePlayer player=\"${p.name.replace(" ", "")}${p.firstname.replace(" ", "")}\" roundNumber=\"${round}\"/>"
}
}.joinToString("\n")
}
</ByePlayer> </ByePlayer>
<TournamentParameterSet> <TournamentParameterSet>
<GeneralParameterSet bInternet="${tournament.online}" basicTime="${tournament.timeSystem.mainTime}" beginDate="${tournament.startDate}" canByoYomiTime="${tournament.timeSystem.byoyomi}" complementaryTimeSystem="${when(tournament.timeSystem.type) { <GeneralParameterSet bInternet="${tournament.online}" basicTime="${tournament.timeSystem.mainTime}" beginDate="${tournament.startDate}" canByoYomiTime="${tournament.timeSystem.byoyomi}" complementaryTimeSystem="${when(tournament.timeSystem.type) {

View File

@@ -165,6 +165,7 @@ function close_modal() {
function downloadFile(blob, filename) { function downloadFile(blob, filename) {
let url = URL.createObjectURL(blob); let url = URL.createObjectURL(blob);
let link = document.createElement("a");
link.setAttribute("href", url); link.setAttribute("href", url);
link.setAttribute("download", filename); link.setAttribute("download", filename);
link.style.visibility = 'hidden'; link.style.visibility = 'hidden';

View File

@@ -102,15 +102,15 @@ onLoad(() => {
$('#export').on('click', e => { $('#export').on('click', e => {
let form = $('#tournament-infos')[0]; let form = $('#tournament-infos')[0];
let shortName = form.val('shortName'); let shortName = form.val('shortName');
let headers = headers(); let hdrs = headers();
headers['Accept'] = 'application/xml'; hdrs['Accept'] = 'application/xml';
fetch(`${base}tour/${tour_id}`, { fetch(`${base}tour/${tour_id}`, {
headers: headers headers: hdrs
}).then(resp => { }).then(resp => {
if (resp.ok) return resp.text() if (resp.ok) return resp.text()
else throw "export error" else throw "export error"
}).then(txt => { }).then(txt => {
let blob = new Blob(['\uFEFF', txt], {type: 'application/xml;charset=utf-8'}); let blob = new Blob(['\uFEFF', txt.trim()], {type: 'application/xml;charset=utf-8'});
downloadFile(blob, `${shortName}.xml`); downloadFile(blob, `${shortName}.xml`);
}).catch(err => showError(err)); }).catch(err => showError(err));
}); });