|
|
|
@ -20,13 +20,13 @@
|
|
|
|
|
export let generate_orgs = [];
|
|
|
|
|
export let generate_teams = [];
|
|
|
|
|
|
|
|
|
|
function generateCertificates(locale) {
|
|
|
|
|
function generateCertificates(locale, include0runners = false) {
|
|
|
|
|
if (generate_orgs.length > 0) {
|
|
|
|
|
generateOrgCertificates(locale);
|
|
|
|
|
generateOrgCertificates(locale, include0runners = false);
|
|
|
|
|
} else if (generate_teams.length > 0) {
|
|
|
|
|
generateTeamCertificates(locale);
|
|
|
|
|
generateTeamCertificates(locale, include0runners = false);
|
|
|
|
|
} else {
|
|
|
|
|
generateRunnerCertificates(locale);
|
|
|
|
|
generateRunnerCertificates(locale, include0runners = false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function download(blob, fileName) {
|
|
|
|
@ -41,7 +41,7 @@
|
|
|
|
|
toast.success($_("pdf-successfully-generated"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function generateRunnerCertificates(locale) {
|
|
|
|
|
async function generateRunnerCertificates(locale, include0runners = false) {
|
|
|
|
|
toast.loading($_("generating-pdf"));
|
|
|
|
|
const current_donations =
|
|
|
|
|
(await DonationService.donationControllerGetAll()) || [];
|
|
|
|
@ -50,7 +50,15 @@
|
|
|
|
|
const linkRunner = await RunnerService.runnerControllerGetOne(runner.id)
|
|
|
|
|
linkRunner.distanceDonations =
|
|
|
|
|
current_donations.filter((d) => d.runner?.id == runner.id) || [];
|
|
|
|
|
certificateRunners.push(linkRunner);
|
|
|
|
|
// check if linkRunner.distance is 0, if so, and include0runners is false, skip this runner
|
|
|
|
|
if (
|
|
|
|
|
!include0runners &&
|
|
|
|
|
(linkRunner.distance === 0 || linkRunner.distance === null)
|
|
|
|
|
) {
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
certificateRunners.push(linkRunner);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
documentServer
|
|
|
|
|
.generateCertificates(certificateRunners, locale)
|
|
|
|
@ -66,7 +74,7 @@
|
|
|
|
|
.catch((err) => {});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function generateTeamCertificates(locale) {
|
|
|
|
|
async function generateTeamCertificates(locale, include0runners = false) {
|
|
|
|
|
toast.loading($_("generating-pdfs"));
|
|
|
|
|
let count = 0;
|
|
|
|
|
const current_donations =
|
|
|
|
@ -80,7 +88,15 @@
|
|
|
|
|
for (let runner of runners) {
|
|
|
|
|
runner.distanceDonations =
|
|
|
|
|
current_donations.filter((d) => d.runner?.id == runner.id) || [];
|
|
|
|
|
certificateRunners.push(runner);
|
|
|
|
|
// check if runner.distance is 0, if so, and include0runners is false, skip this runner
|
|
|
|
|
if (
|
|
|
|
|
!include0runners &&
|
|
|
|
|
(runner.distance === 0 || runner.distance === null)
|
|
|
|
|
) {
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
certificateRunners.push(runner);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
documentServer
|
|
|
|
|
.generateCertificates(certificateRunners, locale)
|
|
|
|
@ -95,7 +111,7 @@
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function generateOrgCertificates(locale) {
|
|
|
|
|
async function generateOrgCertificates(locale, include0runners = false) {
|
|
|
|
|
toast.loading($_("generating-pdfs"));
|
|
|
|
|
const current_donations =
|
|
|
|
|
(await DonationService.donationControllerGetAll()) || [];
|
|
|
|
@ -114,7 +130,15 @@
|
|
|
|
|
for (let runner of runners) {
|
|
|
|
|
runner.distanceDonations =
|
|
|
|
|
current_donations.filter((d) => d.runner?.id == runner.id) || [];
|
|
|
|
|
certificateRunners.push(runner);
|
|
|
|
|
// check if runner.distance is 0, if so, and include0runners is false, skip this runner
|
|
|
|
|
if (
|
|
|
|
|
!include0runners &&
|
|
|
|
|
(runner.distance === 0 || runner.distance === null)
|
|
|
|
|
) {
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
certificateRunners.push(runner);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
await documentServer
|
|
|
|
|
.generateCertificates(certificateRunners, locale)
|
|
|
|
@ -161,20 +185,36 @@
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
{#if certificates_show}
|
|
|
|
|
<button
|
|
|
|
|
on:click={() => {
|
|
|
|
|
generateCertificates("de");
|
|
|
|
|
}}
|
|
|
|
|
class="w-full justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-blue-600 text-base font-medium text-white hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 sm:w-auto sm:text-sm mb-1 lg:mb-0"
|
|
|
|
|
>
|
|
|
|
|
{$_("generate-runner-certificates")}: DE
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
|
|
|
|
on:click={() => {
|
|
|
|
|
generateCertificates("en");
|
|
|
|
|
}}
|
|
|
|
|
class="w-full justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-blue-600 text-base font-medium text-white hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 sm:w-auto sm:text-sm mb-1 lg:mb-0"
|
|
|
|
|
>
|
|
|
|
|
{$_("generate-runner-certificates")}: EN
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
|
|
|
|
on:click={() => {
|
|
|
|
|
generateCertificates("de", true);
|
|
|
|
|
}}
|
|
|
|
|
class="w-full justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-blue-600 text-base font-medium text-white hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 sm:w-auto sm:text-sm mb-1 lg:mb-0"
|
|
|
|
|
>
|
|
|
|
|
{$_("generate-runner-certificates")}: DE
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
|
|
|
|
on:click={() => {
|
|
|
|
|
generateCertificates("de", false);
|
|
|
|
|
}}
|
|
|
|
|
class="w-full justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-blue-600 text-base font-medium text-white hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 sm:w-auto sm:text-sm mb-1 lg:mb-0"
|
|
|
|
|
>
|
|
|
|
|
{$_("generate-runner-certificates")}: DE [{$_('exclude_0m_runners_certificate')}]
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
|
|
|
|
on:click={() => {
|
|
|
|
|
generateCertificates("en", true);
|
|
|
|
|
}}
|
|
|
|
|
class="w-full justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-blue-600 text-base font-medium text-white hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 sm:w-auto sm:text-sm mb-1 lg:mb-0"
|
|
|
|
|
>
|
|
|
|
|
{$_("generate-runner-certificates")}: EN
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
|
|
|
|
on:click={() => {
|
|
|
|
|
generateCertificates("en", false);
|
|
|
|
|
}}
|
|
|
|
|
class="w-full justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-blue-600 text-base font-medium text-white hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 sm:w-auto sm:text-sm mb-1 lg:mb-0"
|
|
|
|
|
>
|
|
|
|
|
{$_("generate-runner-certificates")}: EN [{$_('exclude_0m_runners_certificate')}]
|
|
|
|
|
</button>
|
|
|
|
|
{/if}
|
|
|
|
|