From ceda32be23c17c9bc526456fe6ae10ecfc6c867a Mon Sep 17 00:00:00 2001 From: Sebastien Curt <sebastien.curt@tetras-libre.fr> Date: Tue, 12 Apr 2022 13:58:29 +0200 Subject: [PATCH] Inject home controller url to edit.html.twig and project_view.html.twig --- capsule-prototype/index.html | 5 ++-- .../js/online-rekall/RekallApplication.js | 25 ++++++++++------- capsule-prototype/js/online-script.js | 10 +++---- src/Controller/CapsuleController.php | 27 +++++++++++++++---- templates/project/edit.html.twig | 15 +++++++++++ templates/project/project_view.html.twig | 16 +++++++++++ 6 files changed, 74 insertions(+), 24 deletions(-) diff --git a/capsule-prototype/index.html b/capsule-prototype/index.html index eb41085..970c40a 100644 --- a/capsule-prototype/index.html +++ b/capsule-prototype/index.html @@ -41,7 +41,6 @@ <script language="javascript" type='text/javascript' src='../shared/js/iannix.js'></script> <script language="javascript" type='text/javascript' src='../shared/js/online-script.js'></script> - <script type="module" src="../shared/php/rekallApp.js.php"></script> <script language="javascript" type='text/javascript' src="../shared/js/libs/video-js/video.min.js"></script> <link rel="stylesheet" type="text/css" href="../shared/js/libs/video-js/video-js.min.css" /> @@ -84,7 +83,7 @@ <input class="popupFormButton" id="popupFormButtonUpload" type="submit" value="Upload" name="submit"> </div> </div> --> - <a class="displayMode" id="watermarkBox" href="javascript:window.app.rekall.Rekall('openUrl', window.app.urls.memberHome)" title="Open in MemoRekall" target="_parent"><img id="watermark" src="../shared/css/images/watermark.png" /></a> + <a class="displayMode" id="watermarkBox" href="javascript:window.app.rekall.Rekall('openUrl', 'home')" title="Open in MemoRekall" target="_parent"><img id="watermark" src="../shared/css/images/watermark.png" /></a> <!--<a class="displayMode" id="openFullScreenBox" href="http://www.memorekall.fr" alt="Open in MemoRekall" target="_blank"><img id="openFullScreen" src="../shared/css/images/expand.png" /></a>--> <div class="displayMode" id="projectInfoBtn" title="Project informations">i</div> <div id="popupAlertSpace"> @@ -205,7 +204,7 @@ <div id='left_menu' class='flex-col editmode'> <div class='top'> - <a class="left_menu_item dropable" href="javascript:window.app.rekall.Rekall('openUrl', window.app.urls.memberHome)"> + <a class="left_menu_item dropable" href="javascript:window.app.rekall.Rekall('openUrl', 'home')"> <i class="fas fa-home fa-3x left_menu_item_icn"></i> <p>Go back to my capsules</p> </a> diff --git a/capsule-prototype/js/online-rekall/RekallApplication.js b/capsule-prototype/js/online-rekall/RekallApplication.js index e809766..135f373 100644 --- a/capsule-prototype/js/online-rekall/RekallApplication.js +++ b/capsule-prototype/js/online-rekall/RekallApplication.js @@ -6,12 +6,24 @@ 'init', 'setPlaybackRate', 'videoPlayer', - 'rekall' + 'rekall', + 'getUrl' ]; let localOptions = {}; const OPTIONS = { + getUrl: function (){ + if (arguments && localOptions.links && localOptions.links[arguments[0]]) { + return localOptions.links[arguments[0]]; + } + return ''; + }, + init: function (opts) { + if (opts) { + $.extend(localOptions, opts); + } + }, openUrl: function () { if (!arguments) return; @@ -24,10 +36,8 @@ pubSub: function () { return localOptions.PubSub; }, - init: function (opts) { - if (opts) { - $.extend(localOptions, opts); - } + rekall: function () { + return localOptions.Rekall; }, setPlaybackRate: function () { if (arguments.length > 0 && 'number' === typeof arguments[0] && 0 < arguments[0] && arguments[0] < 10) { @@ -40,9 +50,6 @@ } return localOptions._videoPlayer; - }, - rekall: function () { - return localOptions.Rekall; } }; @@ -60,5 +67,5 @@ } } } - app.rekall = new RekallApplication() + app.rekall = new RekallApplication(); })(window.app = window.app || {}) \ No newline at end of file diff --git a/capsule-prototype/js/online-script.js b/capsule-prototype/js/online-script.js index 5a1a1ac..8f53cf8 100644 --- a/capsule-prototype/js/online-script.js +++ b/capsule-prototype/js/online-script.js @@ -19,7 +19,6 @@ $(document).ready(function() { }); window.app.rekall.Rekall().allowProjectDeletion(window.app.Settings.Project.ProjectDeletionEnabled); - rekall.allowProjectDeletion(window.app.Settings.Project.ProjectDeletionEnabled) Utils.actionPrefix = "php/"; Utils.actionSuffix = ".php?r="; @@ -41,8 +40,6 @@ $(document).ready(function() { rekall_common = infos; if(getParameterByName("w") != "") rekall_common.owner.canEdit = false; -// -//rekall_common.owner.canEdit = true; if(rekall_common.owner.canEdit) { //Mode preview or not @@ -310,8 +307,7 @@ function setEditionControls() { $("#left_menu_item_preview").click(function(event){ event.stopPropagation(); - window.open(window.app.urls.memberHome + 'capsule/preview/' + window.location.pathname.replace('/legacy/', '').slice(0, -1), '_blank'); - /*window.open("?w=1", "Preview Rekall", "menubar=no, status=no, scrollbars=no, menubar=no, width=1150, height=560"); */ + window.open(window.app.rekall.Rekall('getUrl', 'projectPreview'), '_blank'); }); $("#popupSettingsBtnDownloadXml").click(function(event){ @@ -558,7 +554,7 @@ function setEditionControls() { setMetaFromDom(keyDoc, "Rekall->Highlight", "true"); var tmpColor = $("#popupNom").css("color"); $(this).attr("isHighlight", "true").addClass("selected"); - $("#popupEdit").addClass("highlightPopup"); + $("#popupEdit").addClass("highlightPopup"); } }); @@ -1086,7 +1082,7 @@ function removeProject() { data: {"remove": 1}, success: function(retour) { rouletteEnd(); - window.app.rekall.Rekall('openUrl', window.app.urls.memberHome); + window.app.rekall.Rekall('openUrl', 'home'); }, error: function() { openAlert("Server error. Try again."); diff --git a/src/Controller/CapsuleController.php b/src/Controller/CapsuleController.php index 894664f..cb9eecf 100755 --- a/src/Controller/CapsuleController.php +++ b/src/Controller/CapsuleController.php @@ -20,6 +20,7 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Uid\Uuid; use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\Translation\TranslatorInterface; @@ -132,7 +133,7 @@ class CapsuleController extends AbstractController } #[Route('/{_locale<%app.supported_locales%>}/capsule/preview/{path}', name:'preview_capsule')] - public function preview(string $path): Response + public function preview(string $path, UrlGeneratorInterface $urlGenerator): Response { $file_path = '../legacy/' . $path; if (!file_exists($file_path)) { @@ -143,12 +144,15 @@ class CapsuleController extends AbstractController return $this->render( 'project/project_view.html.twig', - [ 'url' => $url ] + [ + 'url' => $url, + 'linkHome' => $urlGenerator->generate('home', [], UrlGeneratorInterface::ABSOLUTE_URL) + ] ); } #[Route('/{_locale<%app.supported_locales%>}/capsule/edit/{path}', name:'edit_capsule')] - public function edit(string $path): Response + public function edit(string $path, UrlGeneratorInterface $urlGenerator): Response { $current_user = $this->getUser(); @@ -175,8 +179,21 @@ class CapsuleController extends AbstractController $url = $this->getParameter('app.legacy_external_prefix') . '/' . $capsule->getEditionLink(); return $this->render( - 'project/project_view.html.twig', - [ 'url' => $url ] + 'project/edit.html.twig', + [ + 'url' => $url, + 'linkHome' => $urlGenerator->generate( + 'home', + [], + UrlGeneratorInterface::ABSOLUTE_URL + ) + , + 'linkPreview' => $urlGenerator->generate( + 'preview_capsule', + [ 'path' => $capsule->getLinkPath() ], + UrlGeneratorInterface::ABSOLUTE_URL + ) + ] ); } diff --git a/templates/project/edit.html.twig b/templates/project/edit.html.twig index 78caedf..2faddad 100644 --- a/templates/project/edit.html.twig +++ b/templates/project/edit.html.twig @@ -11,3 +11,18 @@ </iframe> {% endblock %} + +{% block script %} + <script> + window.onload = function (){ + const iframe = document.getElementById('legacyContent').contentWindow; + iframe.app.rekall.Rekall('init', { + links: { + home: '{{ linkHome }}', + projectPreview: '{{ linkPreview }}' + } + } + ); + } + </script> +{% endblock %} \ No newline at end of file diff --git a/templates/project/project_view.html.twig b/templates/project/project_view.html.twig index 613f4be..2a923da 100644 --- a/templates/project/project_view.html.twig +++ b/templates/project/project_view.html.twig @@ -28,6 +28,7 @@ </div> <iframe src="{{ url }}" + id="legacyContent" style="width:100%;height:100%;top:0;left:0;position:absolute" frameborder="0" @@ -36,5 +37,20 @@ allowfullscreen> </iframe> + + {% block script %} + <script> + window.onload = function (){ + const iframe = document.getElementById('legacyContent').contentWindow; + iframe.app.rekall.Rekall('init', { + links: { + home: '{{ linkHome }}' + } + } + ); + } + </script> + {% endblock %} + </body> </html> -- GitLab