KI-AGENT: Ergänze Mandantenexport und Import
This commit is contained in:
@@ -8,7 +8,9 @@ const admin = useAdmin()
|
||||
|
||||
const loading = ref(true)
|
||||
const creatingTenant = ref(false)
|
||||
const importingTenant = ref(false)
|
||||
const createTenantModalOpen = ref(false)
|
||||
const importFileInput = ref<HTMLInputElement | null>(null)
|
||||
const tenants = ref<AdminTenant[]>([])
|
||||
const searchString = ref("")
|
||||
|
||||
@@ -89,6 +91,46 @@ const createTenant = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const openImportFileDialog = () => {
|
||||
importFileInput.value?.click()
|
||||
}
|
||||
|
||||
const importTenantExport = async (event: Event) => {
|
||||
const input = event.target as HTMLInputElement
|
||||
const file = input.files?.[0]
|
||||
if (!file || importingTenant.value) return
|
||||
|
||||
importingTenant.value = true
|
||||
|
||||
try {
|
||||
const exportData = JSON.parse(await file.text())
|
||||
const result = await admin.importTenant(exportData)
|
||||
const rowCount = (result.tables || []).reduce((sum, table) => sum + table.rows, 0)
|
||||
|
||||
await fetchTenants()
|
||||
|
||||
toast.add({
|
||||
title: "Mandantenimport abgeschlossen",
|
||||
description: `Tenant ${result.tenantId}: ${rowCount} Datensätze und ${result.files?.restored || 0} Dateien verarbeitet.`,
|
||||
color: "green",
|
||||
})
|
||||
|
||||
if (result.tenantId) {
|
||||
await router.push(`/administration/tenants/${result.tenantId}`)
|
||||
}
|
||||
} catch (err: any) {
|
||||
console.error("[administration/tenants/import]", err)
|
||||
toast.add({
|
||||
title: "Mandant konnte nicht importiert werden",
|
||||
description: err?.data?.error || err?.message || "Unbekannter Fehler",
|
||||
color: "red",
|
||||
})
|
||||
} finally {
|
||||
importingTenant.value = false
|
||||
input.value = ""
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
if (!auth.user?.is_admin) {
|
||||
await router.push("/")
|
||||
@@ -111,6 +153,22 @@ onMounted(async () => {
|
||||
<UButton icon="i-heroicons-plus" @click="createTenantModalOpen = true">
|
||||
Tenant
|
||||
</UButton>
|
||||
<input
|
||||
ref="importFileInput"
|
||||
type="file"
|
||||
accept="application/json,.json"
|
||||
class="hidden"
|
||||
@change="importTenantExport"
|
||||
>
|
||||
<UButton
|
||||
icon="i-heroicons-arrow-up-tray"
|
||||
color="warning"
|
||||
variant="soft"
|
||||
:loading="importingTenant"
|
||||
@click="openImportFileDialog"
|
||||
>
|
||||
Import
|
||||
</UButton>
|
||||
</template>
|
||||
</UDashboardNavbar>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user