parent
7b685d6cad
commit
2472640755
@ -24,7 +24,7 @@
|
||||
if (generate_orgs.length > 0) {
|
||||
generateOrgCards(locale);
|
||||
} else if (generate_teams.length > 0) {
|
||||
generateTeamCards(locale);
|
||||
generateTeamCertificates(locale);
|
||||
} else {
|
||||
generateRunnerCertificates(locale);
|
||||
}
|
||||
@ -83,72 +83,68 @@
|
||||
.catch((err) => {});
|
||||
}
|
||||
|
||||
// async function generateTeamCards(locale) {
|
||||
// const toast = Toastify({
|
||||
// text: $_("generating-pdfs"),
|
||||
// duration: -1,
|
||||
// }).showToast();
|
||||
// let count = 0;
|
||||
// const current_cards = await RunnerCardService.runnerCardControllerGetAll();
|
||||
// for (const t of generate_teams) {
|
||||
// const runners = await RunnerTeamService.runnerTeamControllerGetRunners(
|
||||
// t.id
|
||||
// );
|
||||
// let cards = [];
|
||||
// for (let runner of runners) {
|
||||
// let card = current_cards.find((c) => c.runner?.id == runner.id);
|
||||
// if (!card) {
|
||||
// card = await RunnerCardService.runnerCardControllerPost({
|
||||
// runner: runner.id,
|
||||
// });
|
||||
// }
|
||||
// cards.push(card);
|
||||
// }
|
||||
// fetch(
|
||||
// `${config.baseurl}/documents/cards?locale=${locale}&download=true&key=${config.documentserver_key}`,
|
||||
// {
|
||||
// method: "POST",
|
||||
// headers: {
|
||||
// "Content-Type": "application/json",
|
||||
// },
|
||||
// body: JSON.stringify(cards),
|
||||
// }
|
||||
// )
|
||||
// .then((response) => {
|
||||
// if (response.status != "200") {
|
||||
// toast.hideToast();
|
||||
// Toastify({
|
||||
// text: $_("pdf-generation-failed"),
|
||||
// duration: 3500,
|
||||
// backgroundColor:
|
||||
// "linear-gradient(90deg, hsla(281, 37%, 45%, 1) 0%, hsla(1, 62%, 48%, 1) 100%)",
|
||||
// }).showToast();
|
||||
// } else {
|
||||
// return response.blob();
|
||||
// }
|
||||
// })
|
||||
// .then((blob) => {
|
||||
// count++;
|
||||
// const url = window.URL.createObjectURL(blob);
|
||||
// let a = document.createElement("a");
|
||||
// a.href = url;
|
||||
// a.download = "Sponsorings_" + t.name + ".pdf";
|
||||
// document.body.appendChild(a);
|
||||
// a.click();
|
||||
// a.remove();
|
||||
// if (count === generate_teams.length) {
|
||||
// toast.hideToast();
|
||||
// Toastify({
|
||||
// text: $_("pdfs-successfully-generated"),
|
||||
// duration: 3500,
|
||||
// backgroundColor:
|
||||
// "linear-gradient(to right, #00b09b, #96c93d)",
|
||||
// }).showToast();
|
||||
// }
|
||||
// })
|
||||
// .catch((err) => {});
|
||||
// }
|
||||
// }
|
||||
async function generateTeamCertificates(locale) {
|
||||
const toast = Toastify({
|
||||
text: $_("generating-pdfs"),
|
||||
duration: -1,
|
||||
}).showToast();
|
||||
let count = 0;
|
||||
const current_cards = await RunnerCardService.runnerCardControllerGetAll();
|
||||
for (const t of generate_teams) {
|
||||
const runners = await RunnerTeamService.runnerTeamControllerGetRunners(
|
||||
t.id
|
||||
);
|
||||
const current_donations = await DonationService.donationControllerGetAll();
|
||||
let certificateRunners = [];
|
||||
for (let runner of generate_runners) {
|
||||
runner.distanceDonations = current_donations.find((d) => d.runner?.id == runner.id) || [];
|
||||
certificateRunners.push(runner);
|
||||
}
|
||||
fetch(
|
||||
`${config.baseurl}/documents/cards?locale=${locale}&download=true&key=${config.documentserver_key}`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(certificateRunners),
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
if (response.status != "200") {
|
||||
toast.hideToast();
|
||||
Toastify({
|
||||
text: $_("pdf-generation-failed"),
|
||||
duration: 3500,
|
||||
backgroundColor:
|
||||
"linear-gradient(90deg, hsla(281, 37%, 45%, 1) 0%, hsla(1, 62%, 48%, 1) 100%)",
|
||||
}).showToast();
|
||||
} else {
|
||||
return response.blob();
|
||||
}
|
||||
})
|
||||
.then((blob) => {
|
||||
count++;
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
let a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = "Sponsorings_" + t.name + ".pdf";
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
if (count === generate_teams.length) {
|
||||
toast.hideToast();
|
||||
Toastify({
|
||||
text: $_("pdfs-successfully-generated"),
|
||||
duration: 3500,
|
||||
backgroundColor:
|
||||
"linear-gradient(to right, #00b09b, #96c93d)",
|
||||
}).showToast();
|
||||
}
|
||||
})
|
||||
.catch((err) => {});
|
||||
}
|
||||
}
|
||||
|
||||
// async function generateOrgCards(locale) {
|
||||
// const toast = Toastify({
|
||||
|
Loading…
x
Reference in New Issue
Block a user