EGF and FFG exports

This commit is contained in:
Claude Brisson
2024-01-01 12:26:40 +01:00
parent 18edd16d6c
commit b261e56807
10 changed files with 218 additions and 54 deletions

View File

@@ -9,13 +9,16 @@ const apiVersion = '1.0';
// .catch(err => { ... });
const base = '/api/';
let headers = function() {
let headers = function(withJson) {
let ret = {
"Content-Type": "application/json; charset=utf-8",
"Accept-Version": apiVersion,
"Accept": "application/json",
"X-Browser-Key": store('browserKey')
'Accept-Version': apiVersion,
'Accept': 'application/json',
'X-Browser-Key': store('browserKey')
};
if (typeof(withJson) === 'undefined') withJson = true;
if (withJson) {
ret['Content-Type'] = 'application/json';
}
let accessToken = store('accessToken');
if (accessToken) {
ret['Authorization'] = `Bearer ${accessToken}`;

View File

@@ -1,3 +1,20 @@
function publish(format, extension) {
let form = $('#tournament-infos')[0];
let shortName = form.val('shortName');
let hdrs = headers();
hdrs['Accept'] = `application/${format}`
fetch(`api/tour/${tour_id}/standings/${activeRound}`, {
headers: hdrs
}).then(resp => {
if (resp.ok) return resp.text()
else throw "publish error"
}).then(txt => {
let blob = new Blob(['\uFEFF', txt.trim()], {type: 'plain/text;charset=utf-8'});
downloadFile(blob, `${shortName}.${extension}`);
close_modal();
}).catch(err => showError(err));
}
onLoad(() => {
$('.criterium').on('click', e => {
let alreadyOpen = e.target.closest('select');
@@ -45,4 +62,10 @@ onLoad(() => {
$('#publish-modal').on('click', e => {
close_modal();
});
$('.publish-ffg').on('click', e => {
publish('ffg', 'tou');
});
$('.publish-egf').on('click', e => {
publish('egf', 'h9');
});
});