Added runnercard generation for teams

ref #94
This commit is contained in:
Nicolai Ort 2021-03-26 15:58:39 +01:00
parent c907486c4d
commit 23e0b53107
2 changed files with 34 additions and 13 deletions

View File

@ -90,11 +90,13 @@
duration: -1, duration: -1,
}).showToast(); }).showToast();
const current_cards = await RunnerCardService.runnerCardControllerGetAll(); const current_cards = await RunnerCardService.runnerCardControllerGetAll();
let cards = [] let cards = [];
for(let runner of generate_runners){ for (let runner of generate_runners) {
let card = current_cards.find((c)=>c.runner?.id == runner.id) let card = current_cards.find((c) => c.runner?.id == runner.id);
if(!card){ if (!card) {
card = await RunnerCardService.runnerCardControllerPost({runner: runner.id}); card = await RunnerCardService.runnerCardControllerPost({
runner: runner.id,
});
} }
cards.push(card); cards.push(card);
} }
@ -130,12 +132,12 @@
a.click(); a.click();
a.remove(); a.remove();
toast.hideToast(); toast.hideToast();
Toastify({ Toastify({
text: $_("pdf-successfully-generated"), text: $_("pdf-successfully-generated"),
duration: 3500, duration: 3500,
backgroundColor: backgroundColor:
"linear-gradient(to right, #00b09b, #96c93d)", "linear-gradient(to right, #00b09b, #96c93d)",
}).showToast(); }).showToast();
}) })
.catch((err) => {}); .catch((err) => {});
} }
@ -146,19 +148,30 @@
duration: -1, duration: -1,
}).showToast(); }).showToast();
let count = 0; let count = 0;
const current_cards = await RunnerCardService.runnerCardControllerGetAll();
for await (const t of generate_teams) { for await (const t of generate_teams) {
count++; count++;
const runners = await RunnerTeamService.runnerTeamControllerGetRunners( const runners = await RunnerTeamService.runnerTeamControllerGetRunners(
t.id 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( fetch(
`${config.baseurl}/documents/contracts?locale=${locale}&download=true&key=${config.documentserver_key}`, `${config.baseurl}/documents/cards?locale=${locale}&download=true&key=${config.documentserver_key}`,
{ {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify(runners), body: JSON.stringify(cards),
} }
) )
.then((response) => { .then((response) => {
@ -175,6 +188,7 @@
} }
}) })
.then((blob) => { .then((blob) => {
count++;
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;

View File

@ -8,11 +8,15 @@
import ConfirmTeamDeletion from "./ConfirmTeamDeletion.svelte"; import ConfirmTeamDeletion from "./ConfirmTeamDeletion.svelte";
import { clickOutside } from "../base/outsideclick"; import { clickOutside } from "../base/outsideclick";
import GenerateSponsoringContracts from "../pdf_generation/GenerateSponsoringContracts.svelte"; import GenerateSponsoringContracts from "../pdf_generation/GenerateSponsoringContracts.svelte";
import GenerateRunnerCards from "../pdf_generation/GenerateRunnerCards.svelte";
$: searchvalue = ""; $: searchvalue = "";
$: active_deletes = []; $: active_deletes = [];
$: sponsoring_contracts_show = current_teams.some( $: sponsoring_contracts_show = current_teams.some(
(r) => r.is_selected === true (r) => r.is_selected === true
); );
$: cards_show = current_teams.some(
(r) => r.is_selected === true
);
$: generate_teams = current_teams.filter((r) => r.is_selected === true); $: generate_teams = current_teams.filter((r) => r.is_selected === true);
export let current_teams = []; export let current_teams = [];
let modal_open = false; let modal_open = false;
@ -54,6 +58,9 @@
<GenerateSponsoringContracts <GenerateSponsoringContracts
bind:sponsoring_contracts_show bind:sponsoring_contracts_show
bind:generate_teams /> bind:generate_teams />
<GenerateRunnerCards
bind:cards_show
bind:generate_teams />
</div> </div>
<div <div
class="shadow border-b border-gray-200 sm:rounded-lg overflow-x-scroll"> class="shadow border-b border-gray-200 sm:rounded-lg overflow-x-scroll">