From 775802ef676daac2eb766fd36d897bd4a9f79928 Mon Sep 17 00:00:00 2001 From: Mohamed-Hacene Date: Wed, 15 May 2024 19:13:12 +0200 Subject: [PATCH] feat: add frontend export function --- .../core/templates/core/action_plan_pdf.html | 2 ++ frontend/messages/en.json | 3 +- .../[id=uuid]/+page.svelte | 28 +++++++++++++++++-- .../[id=uuid]/action-plan/+page.svelte | 9 ++++++ .../action-plan/export/pdf/+server.ts | 22 +++++++++++++++ 5 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 frontend/src/routes/(app)/compliance-assessments/[id=uuid]/action-plan/export/pdf/+server.ts diff --git a/backend/core/templates/core/action_plan_pdf.html b/backend/core/templates/core/action_plan_pdf.html index 875c2dfd5..11c3d3ac8 100644 --- a/backend/core/templates/core/action_plan_pdf.html +++ b/backend/core/templates/core/action_plan_pdf.html @@ -16,6 +16,8 @@

Action plan

{% trans "Project" %}: {{ compliance_assessment.project.name }}

/

{% trans "Audit" %}: {{ compliance_assessment.name }} - {{ compliance_assessment.version }}

+

/

+

{% trans "Framework" %}: {{ compliance_assessment.framework }}

{% trans "Associated applied controls" %}:

{% trans "Separated by status and sorted by eta" %}

diff --git a/frontend/messages/en.json b/frontend/messages/en.json index a9aecab19..16cd0cd8f 100644 --- a/frontend/messages/en.json +++ b/frontend/messages/en.json @@ -519,5 +519,6 @@ "actionPlan": "Action plan", "noStatus": "No status", "actionPlanHelpText": "Separated by status and sorted by eta", - "requirementsCount": "Requirements count" + "requirementsCount": "Requirements count", + "asZIP": "as ZIP" } diff --git a/frontend/src/routes/(app)/compliance-assessments/[id=uuid]/+page.svelte b/frontend/src/routes/(app)/compliance-assessments/[id=uuid]/+page.svelte index e96ee0975..8ac67b039 100644 --- a/frontend/src/routes/(app)/compliance-assessments/[id=uuid]/+page.svelte +++ b/frontend/src/routes/(app)/compliance-assessments/[id=uuid]/+page.svelte @@ -2,7 +2,8 @@ import { page } from '$app/stores'; import RecursiveTreeView from '$lib/components/TreeView/RecursiveTreeView.svelte'; import { breadcrumbObject } from '$lib/utils/stores'; - import type { TreeViewNode } from '@skeletonlabs/skeleton'; + import type { PopupSettings, TreeViewNode } from '@skeletonlabs/skeleton'; + import { popup } from '@skeletonlabs/skeleton'; import type { PageData } from './$types'; import TreeViewItemContent from './TreeViewItemContent.svelte'; import TreeViewItemLead from './TreeViewItemLead.svelte'; @@ -103,6 +104,12 @@ expandedNodes = $expandedNodesState; $: expandedNodesState.set(expandedNodes); + + const popupDownload: PopupSettings = { + event: 'click', + target: 'popupDownload', + placement: 'bottom' + };
@@ -183,9 +190,24 @@
- {m.exportButton()}{m.exportButton()} +
+

{m.complianceAssessment()}

+ ... {m.asZIP()} +

{m.actionPlan()}

+ ... {m.asPDF()} +
{#if canEditObject} {data.compliance_assessment.name} - {data.compliance_assessment.version}

+

/

+

+ {m.framework()}: + {data.compliance_assessment.framework.str} +

diff --git a/frontend/src/routes/(app)/compliance-assessments/[id=uuid]/action-plan/export/pdf/+server.ts b/frontend/src/routes/(app)/compliance-assessments/[id=uuid]/action-plan/export/pdf/+server.ts new file mode 100644 index 000000000..41a8d50ed --- /dev/null +++ b/frontend/src/routes/(app)/compliance-assessments/[id=uuid]/action-plan/export/pdf/+server.ts @@ -0,0 +1,22 @@ +import { BASE_API_URL } from '$lib/utils/constants'; + +import { error } from '@sveltejs/kit'; +import type { RequestHandler } from './$types'; +export const GET: RequestHandler = async ({ fetch, params }) => { + const URLModel = 'compliance-assessments'; + const endpoint = `${BASE_API_URL}/${URLModel}/${params.id}/action_plan_pdf/`; + + const res = await fetch(endpoint); + if (!res.ok) { + error(400, 'Error fetching the PDF file'); + } + + const fileName = `AP-${params.id}-${new Date().toISOString()}.pdf`; + + return new Response(await res.blob(), { + headers: { + 'Content-Type': 'text/pdf', + 'Content-Disposition': `attachment; filename="${fileName}"` + } + }); +};