Implemented generation for orgs

ref #119
This commit is contained in:
Nicolai Ort 2021-04-03 19:52:41 +02:00
parent 2472640755
commit 2e3ac154be

View File

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