From f0cab56ca0315be025cc24ac40340ccd183eb3b8 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Sat, 13 Nov 2021 23:32:25 +0100 Subject: [PATCH] add html preview file --- config/packages/app.yaml | 1 + src/Controller/StlMeshController.php | 4 ++++ src/Form/StlFileType.php | 22 +++++++++++++++++++++- src/Form/StlMeshType.php | 3 +++ templates/page/mesh/viewer.html.twig | 4 ++++ 5 files changed, 33 insertions(+), 1 deletion(-) diff --git a/config/packages/app.yaml b/config/packages/app.yaml index 3d301b3..0140a5a 100644 --- a/config/packages/app.yaml +++ b/config/packages/app.yaml @@ -72,6 +72,7 @@ core: - application/octet-stream - application/msword - text/plain + - text/html - text/css - application/sla path_locked: diff --git a/src/Controller/StlMeshController.php b/src/Controller/StlMeshController.php index 6f675cb..a031562 100644 --- a/src/Controller/StlMeshController.php +++ b/src/Controller/StlMeshController.php @@ -56,6 +56,10 @@ class StlMeshController extends PageController throw $this->createNotFoundException(); } + if (isset($file['htmlPreviewFile'])) { + $file['htmlPreviewFile'] = file_get_contents($file['htmlPreviewFile']); + } + return $this->render('page/mesh/viewer.html.twig', [ 'mesh' => $stlMesh, 'file' => $file, diff --git a/src/Form/StlFileType.php b/src/Form/StlFileType.php index 0d2d6f0..28ece0b 100644 --- a/src/Form/StlFileType.php +++ b/src/Form/StlFileType.php @@ -24,6 +24,9 @@ class StlFileType extends AbstractType 'required' => true, 'attr' => [ ], + 'row_attr' => [ + 'class' => 'col-md-6', + ], 'constraints' => [ new NotBlank(), ], @@ -34,8 +37,25 @@ class StlFileType extends AbstractType 'file', FilePickerType::class, [ - 'label' => false, + 'label' => 'Fichier STL', 'required' => true, + 'row_attr' => [ + 'class' => 'col-md-6', + ], + 'constraints' => [ + ], + ] + ); + + $builder->add( + 'htmlPreviewFile', + FilePickerType::class, + [ + 'label' => 'Rendu HTML', + 'required' => false, + 'row_attr' => [ + 'class' => 'col-md-6', + ], 'constraints' => [ ], ] diff --git a/src/Form/StlMeshType.php b/src/Form/StlMeshType.php index 629373c..0a6b854 100644 --- a/src/Form/StlMeshType.php +++ b/src/Form/StlMeshType.php @@ -67,6 +67,9 @@ class StlMeshType extends AbstractType 'required' => false, 'attr' => [ ], + 'row_attr' => [ + 'class' => 'col-md-6', + ], 'constraints' => [ ], ] diff --git a/templates/page/mesh/viewer.html.twig b/templates/page/mesh/viewer.html.twig index cd2cb2f..7376c11 100644 --- a/templates/page/mesh/viewer.html.twig +++ b/templates/page/mesh/viewer.html.twig @@ -1,3 +1,6 @@ +{% if not file.htmlPreviewFile is empty %} + {{ file.htmlPreviewFile|raw }} +{% else %} @@ -14,3 +17,4 @@ +{% endif %}