feat(#3): Add PDF caching
This commit is contained in:
@@ -24,6 +24,15 @@
|
||||
<UBadge :color="getStatusColor(version.status)">
|
||||
{{ getStatusLabel(version.status) }}
|
||||
</UBadge>
|
||||
<UButton
|
||||
icon="i-lucide-file-text"
|
||||
size="sm"
|
||||
color="neutral"
|
||||
variant="outline"
|
||||
:label="$t('versions.openPdf')"
|
||||
:to="`/api/application-forms/${applicationFormId}/versions/${version.versionNumber}/pdf`"
|
||||
target="_blank"
|
||||
/>
|
||||
<UButton
|
||||
icon="i-lucide-git-compare"
|
||||
size="sm"
|
||||
|
||||
@@ -1,30 +1,46 @@
|
||||
import type { ApplicationFormDto } from '~~/.api-client'
|
||||
|
||||
export async function useApplicationFormNavigation(applicationFormId: string) {
|
||||
const { t } = useI18n()
|
||||
const { getApplicationFormById } = useApplicationForm()
|
||||
const { getVersions } = useApplicationFormVersion()
|
||||
|
||||
const { data, error, refresh } = await useAsyncData<ApplicationFormDto>(
|
||||
const applicationFormAsync = useAsyncData<ApplicationFormDto>(
|
||||
`application-form-${applicationFormId}`,
|
||||
async () => await getApplicationFormById(applicationFormId),
|
||||
{ deep: true }
|
||||
)
|
||||
|
||||
if (error.value) {
|
||||
throw createError({ statusText: error.value.message })
|
||||
const versionsAsync = useAsyncData(
|
||||
`application-form-${applicationFormId}-versions-nav`,
|
||||
async () => await getVersions(applicationFormId),
|
||||
{ deep: false }
|
||||
)
|
||||
|
||||
await Promise.all([applicationFormAsync, versionsAsync])
|
||||
|
||||
if (applicationFormAsync.error.value) {
|
||||
throw createError({ statusText: applicationFormAsync.error.value.message })
|
||||
}
|
||||
|
||||
const applicationForm = computed<ApplicationFormDto>(() => data?.value as ApplicationFormDto)
|
||||
const applicationForm = computed<ApplicationFormDto>(() => applicationFormAsync.data.value as ApplicationFormDto)
|
||||
|
||||
const latestVersionNumber = computed<number | null>(() => {
|
||||
const versions = versionsAsync.data.value ?? []
|
||||
if (versions.length === 0) return null
|
||||
return Math.max(...versions.map((v) => v.versionNumber ?? 0))
|
||||
})
|
||||
|
||||
const navigationLinks = computed(() => [
|
||||
[
|
||||
{
|
||||
label: 'Formular',
|
||||
label: t('applicationForms.tabs.form'),
|
||||
icon: 'i-lucide-file',
|
||||
to: `/application-forms/${applicationForm.value.id}/0`,
|
||||
exact: true
|
||||
},
|
||||
{
|
||||
label: 'Versionen',
|
||||
label: t('applicationForms.tabs.versions'),
|
||||
icon: 'i-lucide-file-clock',
|
||||
to: `/application-forms/${applicationForm.value.id}/versions`,
|
||||
exact: true
|
||||
@@ -32,16 +48,23 @@ export async function useApplicationFormNavigation(applicationFormId: string) {
|
||||
],
|
||||
[
|
||||
{
|
||||
label: 'Vorschau',
|
||||
label: t('applicationForms.tabs.preview'),
|
||||
icon: 'i-lucide-file-text',
|
||||
to: `/api/application-forms/${applicationForm.value.id}/pdf`,
|
||||
target: '_blank'
|
||||
to: `/api/application-forms/${applicationForm.value.id}/versions/${latestVersionNumber.value}/pdf`,
|
||||
target: '_blank',
|
||||
disabled: Boolean(versionsAsync.error.value) || latestVersionNumber.value === null
|
||||
}
|
||||
]
|
||||
])
|
||||
|
||||
function updateApplicationForm(updatedForm: ApplicationFormDto) {
|
||||
data.value = updatedForm
|
||||
applicationFormAsync.data.value = updatedForm
|
||||
// Refresh the versions list so the Preview link points to the latest version.
|
||||
void versionsAsync.refresh()
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
await Promise.all([applicationFormAsync.refresh(), versionsAsync.refresh()])
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -49,6 +72,6 @@ export async function useApplicationFormNavigation(applicationFormId: string) {
|
||||
navigationLinks,
|
||||
refresh,
|
||||
updateApplicationForm,
|
||||
error
|
||||
error: applicationFormAsync.error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,11 @@
|
||||
"next": "Weiter",
|
||||
"save": "Speichern",
|
||||
"submit": "Einreichen"
|
||||
},
|
||||
"tabs": {
|
||||
"form": "Formular",
|
||||
"versions": "Versionen",
|
||||
"preview": "Vorschau"
|
||||
}
|
||||
},
|
||||
"templates": {
|
||||
@@ -64,6 +69,7 @@
|
||||
"unknownError": "Unbekannter Fehler",
|
||||
"compare": "Vergleichen",
|
||||
"restore": "Wiederherstellen",
|
||||
"openPdf": "PDF öffnen",
|
||||
"restored": "Erfolg",
|
||||
"restoredDescription": "Das Formular wurde auf die ausgewählte Version zurückgesetzt.",
|
||||
"restoreError": "Version konnte nicht wiederhergestellt werden",
|
||||
|
||||
@@ -37,6 +37,11 @@
|
||||
"next": "Next",
|
||||
"save": "Save",
|
||||
"submit": "Submit"
|
||||
},
|
||||
"tabs": {
|
||||
"form": "Form",
|
||||
"versions": "Versions",
|
||||
"preview": "Preview"
|
||||
}
|
||||
},
|
||||
"templates": {
|
||||
@@ -64,6 +69,7 @@
|
||||
"unknownError": "Unknown error",
|
||||
"compare": "Compare",
|
||||
"restore": "Restore",
|
||||
"openPdf": "Open PDF",
|
||||
"restored": "Success",
|
||||
"restoredDescription": "The form has been restored to the selected version.",
|
||||
"restoreError": "Version could not be restored",
|
||||
|
||||
Reference in New Issue
Block a user