From 57081856c4ac226aa06200290aec7e649e4dc40c Mon Sep 17 00:00:00 2001 From: Davide Di Modica Date: Tue, 5 Nov 2024 18:43:42 +0100 Subject: [PATCH] feat: add pdf output on case report --- .../src/api/endpoints/incidentManagement.ts | 5 +- .../cases/CaseReportButton.vue | 67 +++++++++++++------ .../cases/CaseReportTemplateManager.vue | 10 ++- .../cases/CaseReportTemplateSelect.vue | 1 + 4 files changed, 57 insertions(+), 26 deletions(-) diff --git a/frontend/src/api/endpoints/incidentManagement.ts b/frontend/src/api/endpoints/incidentManagement.ts index 220c0b9a..f9e6f0fc 100644 --- a/frontend/src/api/endpoints/incidentManagement.ts +++ b/frontend/src/api/endpoints/incidentManagement.ts @@ -388,8 +388,9 @@ export default { `/incidents/db_operations/case-report-template/do-default-template-exists` ) }, - generateCaseReport(payload: CaseReportPayload) { - return HttpClient.post(`/incidents/report/generate-report-docx`, payload, { + generateCaseReport(payload: CaseReportPayload, type: "docx" | "pdf") { + const url = type === "docx" ? `/incidents/report/generate-report-docx` : `/incidents/report/generate-report-pdf` + return HttpClient.post(url, payload, { responseType: "blob" }) }, diff --git a/frontend/src/components/incidentManagement/cases/CaseReportButton.vue b/frontend/src/components/incidentManagement/cases/CaseReportButton.vue index d3ff2c69..c88999ee 100644 --- a/frontend/src/components/incidentManagement/cases/CaseReportButton.vue +++ b/frontend/src/components/incidentManagement/cases/CaseReportButton.vue @@ -10,7 +10,7 @@ v-model:show="showForm" display-directive="show" preset="card" - :style="{ maxWidth: 'min(600px, 90vw)', minHeight: 'min(270px, 90vh)', overflow: 'hidden' }" + :style="{ maxWidth: 'min(600px, 90vw)', minHeight: 'min(240px, 90vh)', overflow: 'hidden' }" title="Generate Report" :bordered="false" segmented @@ -21,18 +21,20 @@ - - - - .docx - - - -
+ + + + + .{{ reportType }} + + + + +
Reset >(getClearForm()) const formRef = ref(null) +const reportType = computed<"docx" | "pdf" | null>(() => { + const ext = form.value.template_name?.split(".").pop()?.toLowerCase() || null + switch (ext) { + case "docx": + return "docx" + case "html": + return "pdf" + default: + return null + } +}) const rules: FormRules = { template_name: { @@ -142,25 +156,34 @@ function resetForm() { } function exportCases() { - if (!form.value.file_name || !form.value.template_name) return + if (!form.value.file_name || !form.value.template_name || !reportType.value) return exporting.value = true + const extension = reportType.value === "pdf" ? "pdf" : "docx" + const mimeType = + reportType.value === "pdf" + ? "application/pdf" + : "application/vnd.openxmlformats-officedocument.wordprocessingml.document" + const fileName = form.value.file_name - ? `${form.value.file_name}.docx` - : `case:${caseId}_report_${formatDate(new Date(), dFormats.datetimesec)}.docx` + ? `${form.value.file_name}.${extension}` + : `case:${caseId}_report_${formatDate(new Date(), dFormats.datetimesec)}.${extension}` Api.incidentManagement - .generateCaseReport({ - case_id: caseId, - file_name: form.value.file_name, - template_name: form.value.template_name - }) + .generateCaseReport( + { + case_id: caseId, + file_name: form.value.file_name, + template_name: form.value.template_name + }, + reportType.value + ) .then(res => { if (res.data) { saveAs( new Blob([res.data], { - type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" + type: mimeType }), fileName ) diff --git a/frontend/src/components/incidentManagement/cases/CaseReportTemplateManager.vue b/frontend/src/components/incidentManagement/cases/CaseReportTemplateManager.vue index f7e452c1..cfbdb8db 100644 --- a/frontend/src/components/incidentManagement/cases/CaseReportTemplateManager.vue +++ b/frontend/src/components/incidentManagement/cases/CaseReportTemplateManager.vue @@ -29,14 +29,20 @@ v-model:file-list="fileList" :max="1" :disabled="uploading" - accept="application/vnd.openxmlformats-officedocument.wordprocessingml.document, .docx, .DOCX" + accept="application/vnd.openxmlformats-officedocument.wordprocessingml.document, .docx, .DOCX, text/html, .html, .HTML" >
Click or drag a file to this area to upload
-

Only .docx files are accepted

+

+ Only + .docx + and + .html + files are accepted +

diff --git a/frontend/src/components/incidentManagement/cases/CaseReportTemplateSelect.vue b/frontend/src/components/incidentManagement/cases/CaseReportTemplateSelect.vue index 83604af9..e62eed2a 100644 --- a/frontend/src/components/incidentManagement/cases/CaseReportTemplateSelect.vue +++ b/frontend/src/components/incidentManagement/cases/CaseReportTemplateSelect.vue @@ -7,6 +7,7 @@ clearable :loading="loadingOptions" class="overflow-hidden" + to="body" />