mirror of
https://github.com/danbulant/Portfolio
synced 2026-05-27 14:02:14 +00:00
feat: download csv on admin page
This commit is contained in:
parent
0dd7315621
commit
dafb23cde3
1 changed files with 21 additions and 3 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { apiDeleteCandidate, apiListCandidates } from '$lib/@api/admin';
|
import { apiDeleteCandidate, apiListCandidates, apiListCandidatesCSV } from '$lib/@api/admin';
|
||||||
import Home from '$lib/components/icons/Home.svelte';
|
import Home from '$lib/components/icons/Home.svelte';
|
||||||
import TextField from '$lib/components/textfield/TextField.svelte';
|
import TextField from '$lib/components/textfield/TextField.svelte';
|
||||||
import type { CandidatePreview } from '$lib/stores/candidate';
|
import type { CandidatePreview } from '$lib/stores/candidate';
|
||||||
|
|
@ -74,6 +74,19 @@
|
||||||
if (id) await apiDeleteCandidate(id);
|
if (id) await apiDeleteCandidate(id);
|
||||||
getCandidates();
|
getCandidates();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const downloadCSV = async () => {
|
||||||
|
try {
|
||||||
|
const csvBlob = await apiListCandidatesCSV();
|
||||||
|
const url = window.URL.createObjectURL(new Blob([csvBlob]));
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = url;
|
||||||
|
link.setAttribute('download', 'UCHAZECI' + '.csv');
|
||||||
|
link.click();
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if createCandidateModal}
|
{#if createCandidateModal}
|
||||||
|
|
@ -99,9 +112,14 @@
|
||||||
<TextField on:keyup={search} bind:value={searchValue} placeholder="Hledat" />
|
<TextField on:keyup={search} bind:value={searchValue} placeholder="Hledat" />
|
||||||
<button
|
<button
|
||||||
on:click={openCreateCandidateModal}
|
on:click={openCreateCandidateModal}
|
||||||
class="bg-sspsBlue hover:bg-sspsBlueDark ml-3 w-2/5 rounded-lg p-3 py-4 text-xl font-semibold text-white transition-colors duration-300"
|
class="bg-gray-500 hover:bg-gray-600 ml-3 w-2/5 rounded-lg p-3 py-4 text-xl font-semibold text-white transition-colors duration-300"
|
||||||
>Nový uchazeč</button
|
>Nový uchazeč</button
|
||||||
>
|
>
|
||||||
|
<button
|
||||||
|
on:click={downloadCSV}
|
||||||
|
class="bg-gray-500 hover:bg-gray-600 ml-3 w-2/5 rounded-lg p-3 py-4 text-xl font-semibold text-white transition-colors duration-300"
|
||||||
|
>CSV</button
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
{#if scrollTop > 200}
|
{#if scrollTop > 200}
|
||||||
<div class="fixed bottom-8 right-8">
|
<div class="fixed bottom-8 right-8">
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue