From 5a7bc239d2f93ced9ebdc5b113fe27d0d8d3899c Mon Sep 17 00:00:00 2001 From: Philipp Dormann Date: Wed, 28 May 2025 13:49:21 +0200 Subject: [PATCH] feat(GenerateRunnerCertificates): support skipping runners without scans --- .../GenerateRunnerCertificates.svelte | 92 +++++++++++++------ src/locales/de.json | 1 + src/locales/en.json | 1 + 3 files changed, 68 insertions(+), 26 deletions(-) diff --git a/src/components/pdf_generation/GenerateRunnerCertificates.svelte b/src/components/pdf_generation/GenerateRunnerCertificates.svelte index b7eb4aae..c93e5395 100644 --- a/src/components/pdf_generation/GenerateRunnerCertificates.svelte +++ b/src/components/pdf_generation/GenerateRunnerCertificates.svelte @@ -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 @@ {#if certificates_show} - - + + + + {/if} diff --git a/src/locales/de.json b/src/locales/de.json index 6348f466..b5947143 100644 --- a/src/locales/de.json +++ b/src/locales/de.json @@ -232,6 +232,7 @@ "error-whyile-copying-to-clipboard": "Fehler beim Kopieren in die Zwischenablage", "error_on_login": "😢Fehler beim Login", "everything-concerning-your-profile": "Alles zu deinem Profil", + "exclude_0m_runners_certificate": "ohne 0m Läufer", "existing-donor": "Existierende Sponsor:in", "faq": "FAQ", "fast_card_replacement": "Karten-Schnellzusweisung (Mit Mobilgeräteunterstützung)", diff --git a/src/locales/en.json b/src/locales/en.json index 0f73a4e3..15f2789b 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -232,6 +232,7 @@ "error-whyile-copying-to-clipboard": "Error while copying to clipboard", "error_on_login": "Error on login", "everything-concerning-your-profile": "Everything concerning your profile", + "exclude_0m_runners_certificate": "exclude runners without scans", "existing-donor": "Existing Donor", "faq": "FAQ", "fast_card_replacement": "Fast card replacement (with mobile support)",