mirror of
https://github.com/danbulant/Portfolio
synced 2026-05-27 05:51:56 +00:00
Merge pull request #115 from EETagent/download_csv
(frontend) download csv on admin page
This commit is contained in:
commit
70edff49a5
2 changed files with 41 additions and 3 deletions
|
|
@ -120,3 +120,23 @@ export const apiFetchCandidate = async (id: number, fetchSsr?: Fetch): Promise<C
|
||||||
throw errorHandler(e, 'Failed to fetch candidate data');
|
throw errorHandler(e, 'Failed to fetch candidate data');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// SSR compatible
|
||||||
|
// List all candidates /admin/list/candidates
|
||||||
|
export const apiListCandidatesCSV = async (
|
||||||
|
fetchSsr?: Fetch,
|
||||||
|
): Promise<Blob> => {
|
||||||
|
const apiFetch = fetchSsr || fetch;
|
||||||
|
try {
|
||||||
|
const res = await apiFetch(API_URL + '/admin/list/candidates_csv', {
|
||||||
|
method: 'GET',
|
||||||
|
credentials: 'include'
|
||||||
|
});
|
||||||
|
if (res.status != 200) {
|
||||||
|
throw Error(await res.text());
|
||||||
|
}
|
||||||
|
return await res.blob();
|
||||||
|
} catch (e) {
|
||||||
|
throw errorHandler(e, 'List candidates CSV failed');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -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">
|
||||||
|
|
@ -113,7 +131,7 @@
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<Table candidates={candidatesTable} on:delete={(event) => deleteCandidate(event.detail.id)} />
|
<Table candidates={candidatesTable} on:delete={(event) => deleteCandidate(event.detail.id)} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue