diff --git a/frontend/pages/settings/letterheads.vue b/frontend/pages/settings/letterheads.vue index f91746f..5906474 100644 --- a/frontend/pages/settings/letterheads.vue +++ b/frontend/pages/settings/letterheads.vue @@ -26,8 +26,23 @@ const documentTypeOptions = computed(() => const getDocumentTypeLabel = (type) => dataStore.documentTypesForCreation?.[type]?.label || type -const getFileForLetterhead = (letterhead) => - files.value.find((file) => file.path === letterhead.path) +const normalizePath = (path) => + String(path || "").trim().replace(/^\/+/, "") + +const getFileForLetterhead = (letterhead) => { + const letterheadPath = normalizePath(letterhead?.path) + if (!letterheadPath) return null + + return files.value.find((file) => normalizePath(file.path) === letterheadPath) || null +} + +const getFileNameForLetterhead = (letterhead) => { + const file = getFileForLetterhead(letterhead) + if (file?.name) return file.name + + const path = normalizePath(letterhead?.path) + return path ? decodeURIComponent(path.split("/").pop()) : null +} const sortedLetterheads = computed(() => [...letterheads.value].sort((a, b) => { @@ -94,7 +109,7 @@ const uploadLetterheadPdf = async () => { const formData = new FormData() formData.append("file", selectedFile.value) - formData.append("meta", JSON.stringify({ type: "Briefpapier" })) + formData.append("meta", JSON.stringify({ filename: selectedFile.value.name })) return await useNuxtApp().$api("/api/files/upload", { method: "POST", @@ -216,9 +231,12 @@ onMounted(refreshData) variant="ghost" @click.stop="downloadLetterhead(row.original)" > - PDF + {{ getFileNameForLetterhead(row.original) || "PDF" }} - Nicht zugeordnet + + {{ getFileNameForLetterhead(row.original) }} + + Keine Datei hinterlegt