From 57a9f52fa13beaecc8d82e15238bb1ba30020cef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 20 Aug 2021 17:56:52 +0200 Subject: [PATCH] allow to close editor --- .../DocGeneratorTemplateController.php | 11 +++-- .../components/AddEvaluation.vue | 3 +- .../ChillWopiBundle/chill.webpack.config.js | 6 +++ .../ChillWopiBundle/src/Controller/Test.php | 6 ++- .../src/Resources/public/page/editor/index.js | 46 +++++++++++++++++++ .../Resources/public/page/editor/index.scss | 19 ++++++++ .../Resources/views/Editor/embedded.html.twig | 36 +++++++++++++++ .../src/Resources/views/Editor/page.html.twig | 33 +++++++++++++ 8 files changed, 154 insertions(+), 6 deletions(-) create mode 100644 src/Bundle/ChillWopiBundle/chill.webpack.config.js create mode 100644 src/Bundle/ChillWopiBundle/src/Resources/public/page/editor/index.js create mode 100644 src/Bundle/ChillWopiBundle/src/Resources/public/page/editor/index.scss create mode 100644 src/Bundle/ChillWopiBundle/src/Resources/views/Editor/embedded.html.twig create mode 100644 src/Bundle/ChillWopiBundle/src/Resources/views/Editor/page.html.twig diff --git a/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php b/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php index a8feb11c4..f8fd69431 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php +++ b/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php @@ -9,6 +9,7 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluatio use Chill\PersonBundle\Entity\SocialWork\Evaluation; use GuzzleHttp\Exception\TransferException; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\HeaderUtils; @@ -60,8 +61,11 @@ class DocGeneratorTemplateController extends AbstractController */ public function generateDocFromTemplateAction( \ChampsLibres\AsyncUploaderBundle\TempUrl\TempUrlGeneratorInterface $tempUrlGenerator, - DocGeneratorTemplate $template, string $entityClassName, int $entityId): Response - { + DocGeneratorTemplate $template, + string $entityClassName, + int $entityId, + Request $request + ): Response { $getUrlGen = $tempUrlGenerator->generate( 'GET', $template->getFile()); @@ -134,7 +138,8 @@ class DocGeneratorTemplateController extends AbstractController $em->flush(); return $this->redirectToRoute('chill_wopi_file_edit', [ - 'fileId' => $genDocName + 'fileId' => $genDocName, + 'returnPath' => $request->query->get('returnPath', "/") ]); } } catch (TransferException $e) { diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/AddEvaluation.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/AddEvaluation.vue index 2129be398..3321a8005 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/AddEvaluation.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/AddEvaluation.vue @@ -109,7 +109,8 @@ export default { this.toggleEditEvaluation(); }, buildEditLink(storedObject) { - return `/wopi/edit/${storedObject.filename}`; + return `/fr/chill_wopi/edit/${storedObject.filename}?returnPath=` + encodeURIComponent( + window.location.pathname + window.location.search + window.location.hash); }, } } diff --git a/src/Bundle/ChillWopiBundle/chill.webpack.config.js b/src/Bundle/ChillWopiBundle/chill.webpack.config.js new file mode 100644 index 000000000..1c4b53fe1 --- /dev/null +++ b/src/Bundle/ChillWopiBundle/chill.webpack.config.js @@ -0,0 +1,6 @@ +// this file loads all assets from the Chill person bundle +module.exports = function(encore, entries) +{ + encore.addEntry('page_wopi_editor', __dirname + '/src/Resources/public/page/editor/index.js'); + //home/julien/dev/département-vendee/chill/vendor/chill-project/chill-bundles/src/Bundle/ChillWopiBundle/src/Resources/public/page/editor/index.js +}; diff --git a/src/Bundle/ChillWopiBundle/src/Controller/Test.php b/src/Bundle/ChillWopiBundle/src/Controller/Test.php index db035c428..202af20aa 100644 --- a/src/Bundle/ChillWopiBundle/src/Controller/Test.php +++ b/src/Bundle/ChillWopiBundle/src/Controller/Test.php @@ -16,6 +16,7 @@ use Chill\WopiBundle\Service\Controller\ResponderInterface; use Exception; use loophp\psr17\Psr17Interface; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Security; @@ -61,7 +62,7 @@ final class Test $storedObject = $this->storedObjectRepository->findOneBy(['filename' => $fileId]); if (null === $storedObject) { - throw new Exception(sprintf('Unable to find object named %s', $fileId)); + throw new NotFoundHttpException(sprintf('Unable to find object named %s', $fileId)); } if ([] === $discoverExtension = $this->wopiDiscovery->discoverMimeType($storedObject->getType())) { @@ -86,6 +87,7 @@ final class Test ], UrlGeneratorInterface::ABSOLUTE_URL ), + 'closebutton' => 1 ] ) ); @@ -93,7 +95,7 @@ final class Test return $this ->responder ->render( - '@Wopi/Editor/page.html.twig', + '@ChillWopi/Editor/page.html.twig', $configuration ); diff --git a/src/Bundle/ChillWopiBundle/src/Resources/public/page/editor/index.js b/src/Bundle/ChillWopiBundle/src/Resources/public/page/editor/index.js new file mode 100644 index 000000000..613a51d63 --- /dev/null +++ b/src/Bundle/ChillWopiBundle/src/Resources/public/page/editor/index.js @@ -0,0 +1,46 @@ +require('./index.scss'); + +window.addEventListener('DOMContentLoaded', function(e) { + let frameholder = document.getElementById('frameholder'); + let office_frame = document.createElement('iframe'); + office_frame.name = 'office_frame'; + office_frame.id = 'office_frame'; + + // The title should be set for accessibility + office_frame.title = 'Office Frame'; + + // This attribute allows true fullscreen mode in slideshow view + // when using PowerPoint's 'view' action. + office_frame.setAttribute('allowfullscreen', 'true'); + + // The sandbox attribute is needed to allow automatic redirection to the O365 sign-in page in the business user flow + office_frame.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-forms allow-popups allow-top-navigation allow-popups-to-escape-sandbox'); + frameholder.appendChild(office_frame); + + document.getElementById('office_form').submit(); + console.log(office_frame); + + const url = new URL(editor_url); + const editor_domain = url.origin; + + window.addEventListener("message", function(message) { + if (message.origin !== editor_domain) { + return; + } + + let data = JSON.parse(message.data); + + if ('UI_Close' === data.MessageId) { + closeEditor(); + } + }); + +}); + +function closeEditor() { + let + params = new URLSearchParams(window.location.search), + returnPath = params.get('returnPath'); + + window.location.assign(returnPath); +} diff --git a/src/Bundle/ChillWopiBundle/src/Resources/public/page/editor/index.scss b/src/Bundle/ChillWopiBundle/src/Resources/public/page/editor/index.scss new file mode 100644 index 000000000..b8dc8f158 --- /dev/null +++ b/src/Bundle/ChillWopiBundle/src/Resources/public/page/editor/index.scss @@ -0,0 +1,19 @@ +body { + margin: 0; + padding: 0; + overflow: hidden; + -ms-content-zooming: none; +} + +#office_frame { + width: 100%; + height: 100%; + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + margin: 0; + border: none; + display: block; +} diff --git a/src/Bundle/ChillWopiBundle/src/Resources/views/Editor/embedded.html.twig b/src/Bundle/ChillWopiBundle/src/Resources/views/Editor/embedded.html.twig new file mode 100644 index 000000000..5d13f453a --- /dev/null +++ b/src/Bundle/ChillWopiBundle/src/Resources/views/Editor/embedded.html.twig @@ -0,0 +1,36 @@ + + +
+ + +
+ + + + diff --git a/src/Bundle/ChillWopiBundle/src/Resources/views/Editor/page.html.twig b/src/Bundle/ChillWopiBundle/src/Resources/views/Editor/page.html.twig new file mode 100644 index 000000000..6534dfd30 --- /dev/null +++ b/src/Bundle/ChillWopiBundle/src/Resources/views/Editor/page.html.twig @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + {{ encore_entry_link_tags('page_wopi_editor') }} + {{ encore_entry_script_tags('page_wopi_editor') }} + + + + +
+ + +
+ + + + +