You've already forked isop-mirror
feat: add export functionality for internships to CSV in admin internships dashboard
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import type { InternshipFilter } from '~/types/internships';
|
||||
import { FetchError } from 'ofetch';
|
||||
|
||||
definePageMeta({
|
||||
middleware: ['sanctum:auth', 'admin-only'],
|
||||
});
|
||||
@@ -20,6 +23,29 @@ const headers = [
|
||||
{ title: 'Stav', key: 'status', align: 'middle' },
|
||||
{ title: 'Operácie', key: 'ops', align: 'middle' },
|
||||
];
|
||||
|
||||
const internshipFilters = ref<InternshipFilter | null>(null);
|
||||
const exportPending = ref(false);
|
||||
const exportAvailable = ref(true);
|
||||
|
||||
const client = useSanctumClient();
|
||||
|
||||
async function requestExport() {
|
||||
exportPending.value = true;
|
||||
|
||||
try {
|
||||
const file = await client<Blob>(`/api/internships/export`, {
|
||||
method: 'GET',
|
||||
});
|
||||
triggerDownload(file, 'internships_export', 'csv');
|
||||
} catch (e) {
|
||||
if (e instanceof FetchError) {
|
||||
alert(`Chyba pri exportovaní: ${e.statusMessage ?? e.message}`);
|
||||
}
|
||||
} finally {
|
||||
exportPending.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -30,7 +56,16 @@ const headers = [
|
||||
<!-- spacer -->
|
||||
<div style="height: 40px;"></div>
|
||||
|
||||
<InternshipListView mode="admin" />
|
||||
<v-btn prepend-icon="mdi-file-export-outline" color="green" class="mr-2 mb-2" @click="requestExport"
|
||||
:disabled="!exportAvailable" :loading="exportPending">
|
||||
<v-tooltip activator="parent" location="top">
|
||||
Exportovať aktuálne zobrazené výsledky do CSV súboru
|
||||
</v-tooltip>
|
||||
Export výsledkov
|
||||
</v-btn>
|
||||
|
||||
<InternshipListView mode="admin" @filterApplied="(filters) => internshipFilters = filters"
|
||||
@itemsAvailable="(available) => exportAvailable = available" />
|
||||
</v-card>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user