Merge branch 'print-recipe-fix' into 'develop'
fix: recipe printsheet is now downloaded See merge request ldc-web/projets/lionor!44
This commit is contained in:
commit
a30b3b5ca4
6 changed files with 25 additions and 42 deletions
|
|
@ -105,8 +105,27 @@ class RecipesController extends Controller
|
|||
'date' => \now()->format('Y-m-d')
|
||||
]);
|
||||
|
||||
return $this->generateRecipePdf($publishedRecipe, $title)
|
||||
->stream("docrecipe.pdf");
|
||||
/**
|
||||
* ! Réponse mano car en fait \Mccarlosen\LaravelMpdf\LaravelMpdf
|
||||
* ! ne retourne pas vraiemnt une http response, mais provoque une 500
|
||||
* ! apres avoir header et echo dans le corps de la réponse php (Nasty trick)
|
||||
*
|
||||
* (From LeGauloisPro)
|
||||
*/
|
||||
return \response(
|
||||
$this->generateRecipePdf($publishedRecipe, $title)->download($filename),
|
||||
200,
|
||||
[
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Content-disposition' => "inline; filename=\"{$filename}\"",
|
||||
'Cache-Control' => 'public, must-revalidate, max-age=0',
|
||||
'Pragma' => 'public',
|
||||
// * For glory
|
||||
'X-Generator' => 'mPDF',
|
||||
'Expires' => 'Sat, 26 Jul 1997 05:00:00 GMT',
|
||||
'Last-Modified' => gmdate('D, d M Y H:i:s') . ' GMT',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ class SecureHeaders
|
|||
'https://yl.s-web.fr',
|
||||
'https://api-adresse.data.gouv.fr'
|
||||
]) . ';',
|
||||
"img-src * data: blob:;",
|
||||
"img-src 'self' data: blob:;",
|
||||
// ! Blob required for printjs
|
||||
'frame-src ' . implode(' ', [
|
||||
'https://www.google.com/recaptcha/',
|
||||
|
|
|
|||
7
package-lock.json
generated
7
package-lock.json
generated
|
|
@ -33,7 +33,6 @@
|
|||
"leaflet": "^1.9.4",
|
||||
"postcss-discard-comments": "^5.1.2",
|
||||
"prettier": "latest",
|
||||
"print-js": "^1.6.0",
|
||||
"resolve-url-loader": "^5.0.0",
|
||||
"sass": "latest",
|
||||
"slugify": "^1.6.6",
|
||||
|
|
@ -5654,12 +5653,6 @@
|
|||
"url": "https://github.com/prettier/prettier?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/print-js": {
|
||||
"version": "1.6.0",
|
||||
"resolved": "https://registry.npmjs.org/print-js/-/print-js-1.6.0.tgz",
|
||||
"integrity": "sha512-BfnOIzSKbqGRtO4o0rnj/K3681BSd2QUrsIZy/+WdCIugjIswjmx3lDEZpXB2ruGf9d4b3YNINri81+J0FsBWg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/process": {
|
||||
"version": "0.11.10",
|
||||
"resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz",
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@
|
|||
"leaflet": "^1.9.4",
|
||||
"postcss-discard-comments": "^5.1.2",
|
||||
"prettier": "latest",
|
||||
"print-js": "^1.6.0",
|
||||
"resolve-url-loader": "^5.0.0",
|
||||
"sass": "latest",
|
||||
"slugify": "^1.6.6",
|
||||
|
|
|
|||
|
|
@ -1,33 +1,4 @@
|
|||
import printJS from "print-js";
|
||||
|
||||
window.addEventListener("DOMContentLoaded", () => {
|
||||
const eltsButtonPrintRecipe = document.getElementsByClassName(
|
||||
"btn-printing"
|
||||
) as HTMLCollectionOf<HTMLButtonElement>;
|
||||
|
||||
// @ts-ignore
|
||||
window.printJS = printJS;
|
||||
|
||||
for (const eltButtonPrintRecipe of eltsButtonPrintRecipe) {
|
||||
eltButtonPrintRecipe.addEventListener("click", function () {
|
||||
const pathname = window.location.pathname;
|
||||
const pathnameAsArray = pathname.split("/");
|
||||
const itemName = pathnameAsArray[pathnameAsArray.length - 1];
|
||||
setTimeout(() => {
|
||||
// ! Seule solution: imprimer un pdf spécifique pour avoir le rendu souhaité.
|
||||
// @ts-ignore
|
||||
printJS({
|
||||
printable:
|
||||
"recette/" + itemName +
|
||||
"/print-recipe",
|
||||
type: "pdf",
|
||||
showModal: true,
|
||||
modalMessage: "Récupération du document..."
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// * FANCYBOX ACTIVATION
|
||||
window.Fancybox.bind("[data-fancybox]", {
|
||||
// Custom options
|
||||
|
|
|
|||
|
|
@ -136,8 +136,9 @@
|
|||
{!! clean($recipeModel->preparation) !!}
|
||||
</div>
|
||||
<div>
|
||||
<a class="btn btn-secondary text-uppercase btn-printing" href="#"
|
||||
title="{{ __('Imprimer la recette') }}"><i class="fa fa-print me-2"></i>{{ __('Imprimer') }}</a>
|
||||
<a class="btn btn-secondary text-uppercase btn-printing"
|
||||
href="{{ route('recipes.print-recipe', $recipeModel) }}" title="{{ __('Imprimer la recette') }}"><i
|
||||
class="fa fa-print me-2"></i>{{ __('Imprimer') }}</a>
|
||||
<span class="share position-relative">
|
||||
<button class="btn btn-secondary text-uppercase" id="shareBtn"><i
|
||||
class="fa fa-share-alt me-2"></i>{{ __('Partager') }}</button>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue