diff --git a/app/Http/Controllers/PdfController.php b/app/Http/Controllers/PdfController.php index d94f58e26e934f107eb0056272379cf39471287d..efba771ef56399f59efc8a1c3210d4eee2dd448c 100644 --- a/app/Http/Controllers/PdfController.php +++ b/app/Http/Controllers/PdfController.php @@ -34,15 +34,7 @@ public function ActionPlanPdf() ->orderBy('updated_at', 'DESC') ->first(); - if (!$evaluation) { - abort(404); - } - - $collectionAction = collect($evaluation->measureLevels)->filter(function (MeasureLevel $ml) { - return null !== $ml->expected_level && $ml->actual_level < 3 && $ml->actual_level !== $ml->expected_level; - }); - $actionSorted = $collectionAction->sortBy('end_date'); - $actionSorted = $actionSorted->values()->all(); + $actionSorted = $this->getActionSorted($evaluation); $data = [ 'organization' => $organization, @@ -152,35 +144,36 @@ public function PolitiqueSecuritePdf() return Storage::download('politique_securite/' . $filename, 'Politique de sécurité - ' . date('Y-m-d') . '.pdf'); } - public function DossierCyberSecuritePdf(GraphDataRepository $repository) + public function DossierCyberSecuritePdf(GraphDataRepository $repository, $organization_id, $evaluation_id = null) { - $organization_id = request()->route()->parameters['organization_id']; - $authUser = Auth::user(); $isAdmin = $authUser && (User::ROLE_ADMIN === $authUser->role); $organization = Organization::with('referent')->where('id', $organization_id) ->first(); - $evaluation = Evaluation::where('organization_id', $organization_id) - ->where('status', Evaluation::STATUS_DONE) - ->where('reference', env('REFERENTIEL_VERSION')) - ->with('dangerLevels') - ->with('measureLevels') - ->with('measureLevels.measure') - ->with('organization') - ->orderBy('updated_at', 'DESC') - ->first(); - - if (!$evaluation) { - abort(404); + if ($evaluation_id) { + $evaluation = Evaluation::where('organization_id', $organization_id) + ->where('id', $evaluation_id) +// ->where('status', Evaluation::STATUS_DONE) + ->with('dangerLevels') + ->with('measureLevels') + ->with('measureLevels.measure') + ->with('organization') + ->first(); + } else { + $evaluation = Evaluation::where('organization_id', $organization_id) + ->where('status', Evaluation::STATUS_DONE) + ->where('reference', env('REFERENTIEL_VERSION')) + ->with('dangerLevels') + ->with('measureLevels') + ->with('measureLevels.measure') + ->with('organization') + ->orderBy('updated_at', 'DESC') + ->first(); } - $collectionAction = collect($evaluation->measureLevels)->filter(function (MeasureLevel $ml) { - return null !== $ml->expected_level && $ml->actual_level < 3 && $ml->actual_level !== $ml->expected_level; - }); - $actionSorted = $collectionAction->sortBy('end_date'); - $actionSorted = $actionSorted->values()->all(); + $actionSorted = $this->getActionSorted($evaluation); $dangerLevels = DangerLevel::all(); @@ -229,4 +222,18 @@ public function DossierCyberSecuritePdf(GraphDataRepository $repository) return Storage::download('dossier_cybersecurite/' . $filename, 'Dossier cybersécurité - ' . date('Y-m-d') . '.pdf'); } + + public function getActionSorted(Evaluation|null $evaluation): array + { + if (!$evaluation) { + abort(404); + } + + $collectionAction = collect($evaluation->measureLevels)->filter(function (MeasureLevel $ml) { + return null !== $ml->expected_level && $ml->actual_level < 3 && $ml->actual_level !== $ml->expected_level; + }); + $actionSorted = $collectionAction->sortBy('end_date'); + + return $actionSorted->values()->all(); + } } diff --git a/resources/js/components/Evaluations/List.vue b/resources/js/components/Evaluations/List.vue index b454c098d6dc234d3a504b7e8a8dac053aae57ba..28d8f1925c163c927a73a1c36b60532cce89ffd2 100644 --- a/resources/js/components/Evaluations/List.vue +++ b/resources/js/components/Evaluations/List.vue @@ -137,13 +137,14 @@ ><i class="fas fa-pen" /> Modifier</button> </span> - <button - v-else + <a + v-else-if="props.row.status === 2" class="btn btn-light btn-xs" - @click.prevent="downloadPdf(props.row)" + :href="`/pdf/dossierCyberSecurite/${props.row.organization_id}/${props.row.id}`" + target="_blank" > <i class="fas fa-clipboard-list" /> Rapport - </button> + </a> <button v-if="!isUser()" class="btn btn-light btn-xs" @@ -396,9 +397,6 @@ export default { if (confirm(`Souhaitez-vous supprimer l'évaluation du ${item.updated_at.format('DD/MM/YYYY')} ?`)) { this.$store.dispatch('deleteEvaluation', item) } - }, - downloadPdf(item) { - alert('Fonctionnalité en attente'); } } } diff --git a/resources/js/components/Evaluations/Single/View/index.vue b/resources/js/components/Evaluations/Single/View/index.vue index 29b7dd03ae8866eeecd7efd755eb9568886805f0..1404e3dcf86f7e02037986ce27356f58b8231631 100644 --- a/resources/js/components/Evaluations/Single/View/index.vue +++ b/resources/js/components/Evaluations/Single/View/index.vue @@ -3,9 +3,13 @@ <button class="btn btn-outline-primary" @click.prevent="$router.push('/evaluations')"> <i class="fas fa-arrow-left"></i> Retour à la liste des évaluations </button> - <button class="btn btn-outline-primary" @click.prevent="alert('Pas encore implémenté')"> + <a + class="btn btn-outline-primary" + :href="`/pdf/dossierCyberSecurite/${evaluation.organization_id}/${evaluation.id}`" + target="_blank" + > <i class="fas fa-print"></i> Imprimer l'évaluation - </button> + </a> <button v-if="user && user.data && user.data.role <= $store.state.user.roles.ROLE_MANAGER" class="btn btn-outline-primary" diff --git a/routes/web.php b/routes/web.php index e88a88c2ca0bf0d6770ba20a2ec5314d07d14b39..409fba5606f3ca19ffb2a0a6428956792cac429a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -31,7 +31,7 @@ Route::middleware('auth:sanctum')->prefix('/pdf')->group(function () { Route::get('/planAction/{organization_id}', [PdfController::class, 'ActionPlanPdf'])->name('pdf.plan_action'); Route::get('/politiqueSecurite/{organization_id}', [PdfController::class, 'PolitiqueSecuritePdf'])->name('pdf.politique_securite'); - Route::get('/dossierCyberSecurite/{organization_id}', [PdfController::class, 'DossierCyberSecuritePdf'])->name('pdf.dossier_cyber_securite'); + Route::get('/dossierCyberSecurite/{organization_id}/{evaluation_id?}', [PdfController::class, 'DossierCyberSecuritePdf'])->name('pdf.dossier_cyber_securite'); }); Route::middleware('auth:sanctum')->get('/{any}', function () {