feat(documents): allow archiving inbox documents
All checks were successful
Build and Release FEDEO / verify (push) Successful in 57s
Build and Release FEDEO / build-and-release (push) Successful in 5m56s

This commit is contained in:
2026-10-02 17:12:05 +02:00
parent 09a002d600
commit 1885bfc521
6 changed files with 243 additions and 13 deletions

View File

@@ -36,6 +36,12 @@ const previewDocument = ref<InboxDocument | null>(null)
const filingDocument = ref<InboxDocument | null>(null)
const filingLoading = ref(false)
const filingSaving = ref(false)
const archiveOpen = ref(false)
const archiveTarget = ref<InboxDocument | null>(null)
const archiveSaving = ref(false)
const archiveError = ref("")
let archiveVersion = 0
const documentBusy = computed(() => filingSaving.value || archiveSaving.value)
const filingError = ref("")
const filingFolders = ref<FilingFolder[]>([])
const filingTypes = ref<FilingType[]>([])
@@ -80,7 +86,7 @@ const folderOptions = computed(() => {
return [{ id: "root", name: "Dateien (Hauptebene)" }, ...filingFolders.value
.map(folder => ({ id: folder.id, name: path(folder) })).sort((a, b) => a.name.localeCompare(b.name, "de"))]
})
const canFile = computed(() => Boolean(filingDocument.value && !filingLoading.value && !filingSaving.value
const canFile = computed(() => Boolean(filingDocument.value && !filingLoading.value && !documentBusy.value
&& (filingFolder.value === "root" || selectedFolder.value)
&& filingTypes.value.some(type => type.id === filingType.value)
&& (!fixedType.value || filingType.value === selectedFolder.value?.standardFiletype)))
@@ -225,6 +231,7 @@ const removeAssignment = (kind: string) => {
const openPreview = (entry: InboxDocument) => openFiling(entry)
const openFiling = async (entry: InboxDocument) => {
if (disposed || documentBusy.value) return
suggestionVersion++
clearTimeout(suggestionTimer)
suggestionController?.abort()
@@ -278,6 +285,44 @@ const openFiling = async (entry: InboxDocument) => {
}
}
const removeInboxEntry = (id: string) => {
// Discard older list responses that still contain the completed document.
requestVersion++
clearTimeout(pollTimer)
if (documents.value.some(document => document.id === id)) total.value = Math.max(0, total.value - 1)
documents.value = documents.value.filter(document => document.id !== id)
page.value = Math.min(page.value, Math.max(1, Math.ceil(total.value / pageSize)))
void inboxCount.refresh()
if (previewDocument.value?.id === id) previewOpen.value = false
}
const openArchive = (entry: InboxDocument) => {
if (disposed || documentBusy.value || !auth.activeTenant) return
archiveTarget.value = entry
archiveError.value = ""
archiveOpen.value = true
}
const archiveDocument = async () => {
const entry = archiveTarget.value
if (!entry || !archiveOpen.value || disposed || documentBusy.value || !auth.activeTenant) return
const version = ++archiveVersion
archiveSaving.value = true
archiveError.value = ""
try {
await $api(`/api/document-inbox/${entry.id}/archive`, { method: "POST" })
if (disposed || version !== archiveVersion) return
removeInboxEntry(entry.id)
archiveOpen.value = false
toast.add({ title: "Dokument archiviert", description: `${entry.name} wurde aus der Ablage entfernt.`, color: "success" })
await load(true)
} catch (cause: any) {
if (!disposed && version === archiveVersion) archiveError.value = cause?.data?.error || cause?.data?.message || "Das Dokument konnte nicht archiviert werden."
} finally {
if (version === archiveVersion) archiveSaving.value = false
}
}
const fileDocument = async () => {
if (!canFile.value) return
const entry = filingDocument.value!
@@ -288,14 +333,7 @@ const fileDocument = async () => {
try {
await $api(`/api/document-inbox/${entry.id}/file`, { method: "POST", body: { folder, type: filingType.value, assignments: { ...assignmentChanges.value } } })
if (disposed || version !== filingVersion) return
// Cancel pending polling responses before removing the successfully filed entry.
requestVersion++
clearTimeout(pollTimer)
documents.value = documents.value.filter(document => document.id !== entry.id)
total.value = Math.max(0, total.value - 1)
page.value = Math.min(page.value, Math.max(1, Math.ceil(total.value / pageSize)))
void inboxCount.refresh()
previewOpen.value = false
removeInboxEntry(entry.id)
toast.add({ title: "Dokument abgelegt", description: `${entry.name} ist unter Dateien verfügbar.`, color: "success" })
await load(true)
} catch (cause: any) {
@@ -429,7 +467,15 @@ watch(previewOpen, open => {
filingLoading.value = false
}
})
watch(archiveOpen, open => {
if (!open) { archiveTarget.value = null; archiveError.value = "" }
})
watch(() => auth.activeTenant, () => {
archiveVersion++
archiveOpen.value = false
archiveTarget.value = null
archiveError.value = ""
archiveSaving.value = false
requestVersion++
setupVersion++
filingVersion++
@@ -455,6 +501,7 @@ watch(() => auth.activeTenant, () => {
onMounted(() => { origin.value = window.location.origin; load() })
onBeforeUnmount(() => {
disposed = true
archiveVersion++
requestVersion++
setupVersion++
filingVersion++
@@ -507,7 +554,12 @@ onBeforeUnmount(() => {
</td>
<td class="whitespace-nowrap px-4 py-4 text-muted">{{ dayjs(entry.receivedAt).format('DD.MM.YYYY HH:mm') }}</td>
<td class="whitespace-nowrap px-4 py-4 text-muted">{{ formatSize(entry.size) }}</td>
<td class="px-4 py-4"><div class="flex justify-end gap-1"><UButton icon="i-heroicons-folder-arrow-down" variant="soft" :aria-label="`${entry.name} ablegen`" @click="openFiling(entry)">Ablegen</UButton><UButton icon="i-heroicons-eye" color="neutral" variant="ghost" :aria-label="`${entry.name} als Vorschau anzeigen`" @click="openPreview(entry)">Vorschau</UButton><UButton icon="i-heroicons-arrow-down-tray" color="neutral" variant="ghost" :aria-label="`${entry.name} herunterladen`" @click="fileAction(entry, true)" /></div></td>
<td class="px-4 py-4"><div class="flex justify-end gap-1">
<UButton icon="i-heroicons-folder-arrow-down" variant="soft" :aria-label="`${entry.name} ablegen`" :disabled="documentBusy" @click="openFiling(entry)">Ablegen</UButton>
<UButton icon="i-heroicons-eye" color="neutral" variant="ghost" :aria-label="`${entry.name} als Vorschau anzeigen`" :disabled="documentBusy" @click="openPreview(entry)">Vorschau</UButton>
<UButton icon="i-heroicons-arrow-down-tray" color="neutral" variant="ghost" :aria-label="`${entry.name} herunterladen`" @click="fileAction(entry, true)" />
<UButton icon="i-heroicons-archive-box" color="neutral" variant="ghost" :aria-label="`${entry.name} archivieren`" :disabled="documentBusy" @click="openArchive(entry)">Archivieren</UButton>
</div></td>
</tr>
</tbody>
</table>
@@ -522,7 +574,7 @@ onBeforeUnmount(() => {
</div>
</UDashboardPanelContent>
<UModal v-model:open="previewOpen" :title="previewDocument?.name || 'Dokumentvorschau'" description="Dokument prüfen und mit Ordner und Typ ablegen." :dismissible="!filingSaving" :close="!filingSaving" :ui="{ content: 'w-[calc(100vw-2rem)] max-w-7xl h-[90dvh]', body: 'min-h-0 flex-1 overflow-y-auto lg:overflow-hidden p-0 sm:p-0', title: 'break-all pr-8', footer: 'flex-wrap justify-end' }">
<UModal v-model:open="previewOpen" :title="previewDocument?.name || 'Dokumentvorschau'" description="Dokument prüfen und mit Ordner und Typ ablegen." :dismissible="!documentBusy" :close="!documentBusy" :ui="{ content: 'w-[calc(100vw-2rem)] max-w-7xl h-[90dvh]', body: 'min-h-0 flex-1 overflow-y-auto lg:overflow-hidden p-0 sm:p-0', title: 'break-all pr-8', footer: 'flex-wrap justify-end' }">
<template #body>
<div class="lg:flex lg:h-full lg:min-h-0">
<div class="h-[50dvh] min-w-0 lg:h-full lg:flex-1">
@@ -597,6 +649,7 @@ onBeforeUnmount(() => {
</template>
<template #footer>
<template v-if="previewDocument">
<UButton icon="i-heroicons-archive-box" color="neutral" variant="ghost" :disabled="documentBusy" @click="openArchive(previewDocument)">Archivieren</UButton>
<UButton icon="i-heroicons-arrow-top-right-on-square" color="neutral" variant="ghost" @click="fileAction(previewDocument, false)">In neuem Tab öffnen</UButton>
<UButton icon="i-heroicons-arrow-down-tray" color="neutral" variant="outline" @click="fileAction(previewDocument, true)">Herunterladen</UButton>
<UButton type="submit" form="inbox-preview-filing" icon="i-heroicons-folder-arrow-down" :loading="filingSaving" :disabled="!canFile">Übernehmen und ablegen</UButton>
@@ -604,6 +657,17 @@ onBeforeUnmount(() => {
</template>
</UModal>
<UModal v-model:open="archiveOpen" title="Dokument archivieren" description="Das Dokument verschwindet aus der Ablage. Die Originaldatei bleibt im Archiv erhalten." :dismissible="!archiveSaving" :close="!archiveSaving">
<template #body>
<p class="break-all font-medium">{{ archiveTarget?.name }}</p>
<UAlert v-if="archiveError" class="mt-4" :title="archiveError" color="error" variant="subtle" />
</template>
<template #footer>
<UButton color="neutral" variant="outline" :disabled="archiveSaving" @click="archiveOpen = false">Abbrechen</UButton>
<UButton icon="i-heroicons-archive-box" :loading="archiveSaving" :disabled="!archiveTarget || filingSaving" @click="archiveDocument">Archivieren</UButton>
</template>
</UModal>
<UModal v-model:open="setupOpen" title="Scanner einrichten" description="Verbinde deinen Epson-Scanner mit der Dokumentenablage dieses Mandanten.">
<template #body>
<div class="space-y-5">