Skip to content

Commit

Permalink
[BUGFIX] Use middleware to inject the loading overlay, split JS into …
Browse files Browse the repository at this point in the history
…specific modules
  • Loading branch information
vertexvaar committed Nov 17, 2023
1 parent 020c11e commit 0dcee19
Show file tree
Hide file tree
Showing 19 changed files with 419 additions and 294 deletions.
89 changes: 89 additions & 0 deletions Classes/Middleware/InjectLoadingOverlayMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

declare(strict_types=1);

namespace In2code\In2publishCore\Middleware;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use TYPO3\CMS\Core\Http\StreamFactory;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;

use function str_starts_with;
use function strpos;
use function strtolower;
use function substr;

class InjectLoadingOverlayMiddleware implements MiddlewareInterface
{
protected const CODE = <<<HTML
<div class="in2publish-loading-overlay in2publish-loading-overlay--hidden">
<div class="in2publish-loading-overlay--spinner">
<div class="rect1"></div>
<div class="rect2"></div>
<div class="rect3"></div>
<div class="rect4"></div>
<div class="rect5"></div>
</div>
</div>
HTML;
protected const SUPPORTED_PATHS = [
'/typo3/module/web/',
'/typo3/module/file/in2publish',
'/typo3/module/site/in2publish',
'/typo3/module/tools/in2publish',
'/typo3/module/in2publish',
];

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
if (!$this->isInSupportedPath($request)) {
return $handler->handle($request);
}

/** @var PageRenderer $pageRenderer */
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
$pageRenderer->addCssFile(
'EXT:in2publish_core/Resources/Public/Css/LoadingOverlay.css',
'stylesheet',
'all',
'',
false,
);
$pageRenderer->loadRequireJsModule('TYPO3/CMS/In2publishCore/LoadingOverlay');
$pageRenderer->addInlineLanguageLabelFile('EXT:in2publish_core/Resources/Private/Language/locallang_js.xlf');

$response = $handler->handle($request);

if ($response->getStatusCode() >= 200 && $response->getStatusCode() < 300) {
$body = $response->getBody();
if ($body->isSeekable()) {
$body->rewind();
}
$contents = $body->getContents();

$offset = strpos($contents, '<body>') + 6;
$contents = substr($contents, 0, $offset) . self::CODE . substr($contents, $offset);

$streamFactory = GeneralUtility::makeInstance(StreamFactory::class);
$newBody = $streamFactory->createStream($contents);
$response = $response->withBody($newBody);
}

return $response;
}

protected function isInSupportedPath(ServerRequestInterface $request): bool
{
$requestPath = strtolower($request->getUri()->getPath());
foreach (self::SUPPORTED_PATHS as $path) {
if (str_starts_with($requestPath, $path)) {
return true;
}
}
return false;
}
}
6 changes: 3 additions & 3 deletions Configuration/Backend/Modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
$backendModulesToRegister['in2publish_core_m1'] = [
'parent' => 'web',
'position' => [],
'access' => 'user,group',
'access' => 'user',
'workspaces' => 'live',
'path' => '/module/in2publish_core/m1',
'labels' => 'LLL:EXT:in2publish_core/Resources/Private/Language/locallang_mod1.xlf',
Expand All @@ -59,7 +59,7 @@
$backendModulesToRegister['in2publish_core_m3'] = [
'parent' => 'file',
'position' => [],
'access' => 'user,group',
'access' => 'user',
'workspaces' => 'live',
'path' => '/module/in2publish_core/m3',
'labels' => 'LLL:EXT:in2publish_core/Resources/Private/Language/locallang_mod3.xlf',
Expand Down Expand Up @@ -93,7 +93,7 @@
$backendModulesToRegister['in2publish_core_m5'] = [
'parent' => 'site',
'position' => ['after' => 'redirects'],
'access' => 'user,group',
'access' => 'user',
'workspaces' => 'live',
'path' => '/module/in2publish_core/m5',
'labels' => 'LLL:EXT:in2publish_core/Resources/Private/Language/locallang_mod5.xlf',
Expand Down
7 changes: 6 additions & 1 deletion Configuration/RequestMiddlewares.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
declare(strict_types=1);

use In2code\In2publishCore\Features\MetricsAndDebug\Middleware\MetricsAndDebugMiddleware;
use In2code\In2publishCore\Middleware\InjectLoadingOverlayMiddleware;

return [
'backend' => [
'in2code/in2publish/debugging' => [
'in2code/in2publish_core/debugging' => [
'target' => MetricsAndDebugMiddleware::class,
'after' => 'typo3/cms-core/response-propagation',
],
'in2code/in2publish_core/inject-loading-overlay' => [
'target' => InjectLoadingOverlayMiddleware::class,
'after' => 'typo3/cms-core/response-propagation',
],
],
];
22 changes: 18 additions & 4 deletions Resources/Private/Language/de.locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@
<source>Publish page &quot;%s&quot; and its subpages.</source>
<target>Veröffentlichen der Seite &quot;%s&quot; und ihrer Unterseiten</target>
</trans-unit>
<trans-unit id="confirm_publish_all_pages" resname="confirm_publish_all_pages">
<source>Do you really want to publish all pages?</source>
<target>Möchten Sie wirklich alle Seiten veröffentlichen?</target>
</trans-unit>
<trans-unit id="confirm_publish_pages" resname="confirm_publish_pages">
<source>Do you really want to publish this page?</source>
<target>Möchten Sie diese Seite wirklich veröffentlichen?</target>
Expand Down Expand Up @@ -472,6 +468,24 @@
<source>The record &quot;%s&quot; is a target of the shortcut record &quot;%s&quot;. The target must be published before the shortcut record can be published.</source>
<target>Der Datensatz &quot;%s&quot; ist ein Ziel des Verknüpfungsdatensatzes &quot;%s&quot;. Das Ziel muss veröffentlicht werden, bevor der Verknüpfungsdatensatz veröffentlicht werden kann.</target>
</trans-unit>
<trans-unit id="tx_in2publishcore.modal.publish.page_with_dependencies.text">
<source>This page has unmet dependencies. Since you cannot access the dependencies, it is possible to publish this page anyway. However, there is no guarantee that the page will look exactly the same as on Local.
You can see the dependencies in the details of the page.</source>
<target state="translated">Diese Seite hat unerfüllte Abhängigkeiten. Da Sie auf die Abhängigkeiten nicht zugreifen können ist es möglich, diese Seite trotzdem zu veröffentlichen. Allerdings ohne Garantie, dass die Seite exakt so aussieht wie auf Local.
Sie können die Abhängigkeiten in den Details der Seite einsehen.</target>
</trans-unit>
<trans-unit id="tx_in2publishcore.actions.publish">
<source>Publish</source>
<target state="translated">Veröffentlichen</target>
</trans-unit>
<trans-unit id="tx_in2publishcore.action.abort">
<source>Abort</source>
<target state="translated">Abbrechen</target>
</trans-unit>
<trans-unit id="tx_in2publishcore.modal.publish.title">
<source>Confirm publish</source>
<target state="translated">Veröffentlichung bestätigen</target>
</trans-unit>
</body>
</file>
</xliff>
6 changes: 0 additions & 6 deletions Resources/Private/Language/de.locallang_js.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@
<source>Are you sure you want to publish the folder $name$? This cannot be reversed.</source>
<target state="translated">Möchten Sie den Ordner $name$ wirklich veröffentlichen? Dies kann nicht rückgängig gemacht werden.</target>
</trans-unit>
<trans-unit id="tx_in2publishcore.modal.publish.page_with_dependencies.text">
<source>This page has unmet dependencies. Since you cannot access the dependencies, it is possible to publish this page anyway. However, there is no guarantee that the page will look exactly the same as on Local.
You can see the dependencies in the details of the page.</source>
<target state="translated">Diese Seite hat unerfüllte Abhängigkeiten. Da Sie auf die Abhängigkeiten nicht zugreifen können ist es möglich, diese Seite trotzdem zu veröffentlichen. Allerdings ohne Garantie, dass die Seite exakt so aussieht wie auf Local.
Sie können die Abhängigkeiten in den Details der Seite einsehen.</target>
</trans-unit>
</body>
</file>
</xliff>
16 changes: 13 additions & 3 deletions Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@
<trans-unit id="label_publish_all_pages" resname="label_publish_all_pages">
<source>Publish page &quot;%s&quot; and its subpages.</source>
</trans-unit>
<trans-unit id="confirm_publish_all_pages" resname="confirm_publish_all_pages">
<source>Do you really want to publish all pages?</source>
</trans-unit>
<trans-unit id="confirm_publish_pages" resname="confirm_publish_pages">
<source>Do you really want to publish this page?</source>
</trans-unit>
Expand Down Expand Up @@ -355,6 +352,19 @@
<trans-unit id="record.reason.shortcut_record" resname="record.reason.shortcut_record">
<source>The record &quot;%s&quot; is a target of the shortcut record &quot;%s&quot;. The target must be published before the shortcut record can be published.</source>
</trans-unit>
<trans-unit id="tx_in2publishcore.modal.publish.page_with_dependencies.text">
<source>This page has unmet dependencies. Since you cannot access the dependencies, it is possible to publish this page anyway. However, there is no guarantee that the page will look exactly the same as on Local.
You can see the dependencies in the details of the page.</source>
</trans-unit>
<trans-unit id="tx_in2publishcore.actions.publish">
<source>Publish</source>
</trans-unit>
<trans-unit id="tx_in2publishcore.action.abort">
<source>Abort</source>
</trans-unit>
<trans-unit id="tx_in2publishcore.modal.publish.title">
<source>Confirm publish</source>
</trans-unit>
</body>
</file>
</xliff>
4 changes: 0 additions & 4 deletions Resources/Private/Language/locallang_js.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
<trans-unit id="tx_in2publishcore.modal.publish.folder.text">
<source>Are you sure you want to publish the folder $name$? This cannot be reversed.</source>
</trans-unit>
<trans-unit id="tx_in2publishcore.modal.publish.page_with_dependencies.text">
<source>This page has unmet dependencies. Since you cannot access the dependencies, it is possible to publish this page anyway. However, there is no guarantee that the page will look exactly the same as on Local.
You can see the dependencies in the details of the page.</source>
</trans-unit>
</body>
</file>
</xliff>
2 changes: 0 additions & 2 deletions Resources/Private/Layouts/File.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:render partial="LoadingOverlay"/>

<f:flashMessages/>

<f:render section="Main"/>
Expand Down
1 change: 0 additions & 1 deletion Resources/Private/Layouts/Record.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<div class="in2publish-module">
<div id="typo3-inner-docbody">
<div class="container container-full">
<f:render partial="LoadingOverlay"/>
<f:flashMessages />
<div class="in2publish-backend">
<f:render section="content"/>
Expand Down
9 changes: 0 additions & 9 deletions Resources/Private/Partials/LoadingOverlay.html

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:link.action
action="publishRecord"
class="in2publish-link-publish"
class="in2publish-link-publish js-in2publish-loading-overlay"
arguments="{id:record.id}"
title="{f:translate(key:'publish_pages', default:'Publish this page')}"
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:variable name="easy-modal-title" value="{f:translate(key: 'tx_in2publishcore.modal.publish.title')}" />
<f:variable name="easy-modal-content" value="{f:translate(key: 'tx_in2publishcore.modal.publish.page_with_dependencies.text')}" />
<f:variable name="easy-modal-severity" value="1" />
<f:link.action
action="publishRecord"
class="in2publish-link-publish js-publish-trigger"
class="in2publish-link-publish js-in2publish-confirmation-modal"
arguments="{id:record.id}"
title="{f:translate(key:'publish_pages', default:'Publish this page')}"
data="{type: 'page_with_dependencies', severity: '1'}"
data="{easy-modal-title: easy-modal-title, easy-modal-content: easy-modal-content, easy-modal-severity: easy-modal-severity}"
>
<i class="in2publish-icon-publish"></i>
</f:link.action>
Expand Down
64 changes: 64 additions & 0 deletions Resources/Private/Sass/LoadingOverlay.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
@import "compass";
@import "Settings";

.in2publish-loading-overlay {
background-color: $scorpion;
height: 100%;
position: fixed;
z-index: 100000;
text-align: center;
opacity: 0.3;
top: 0;
left: 0;
right: 0;
bottom: 0;
filter: blur(0);
}

.in2publish-loading-overlay--hidden {
display: none;
}

.in2publish-loading-overlay--spinner {
position: relative;
top: 30%;
margin: 100px auto;
width: 50px;
height: 30px;
text-align: center;
font-size: 10px;

> div {
background-color: $white;
height: 100%;
width: 6px;
display: inline-block;

-webkit-animation: stretchdelay 1.2s infinite ease-in-out;
animation: stretchdelay 1.2s infinite ease-in-out;
}

.rect2 {
-webkit-animation-delay: -1.1s;
animation-delay: -1.1s;
}

.rect3 {
-webkit-animation-delay: -1.0s;
animation-delay: -1.0s;
}

.rect4 {
-webkit-animation-delay: -0.9s;
animation-delay: -0.9s;
}

.rect5 {
-webkit-animation-delay: -0.8s;
animation-delay: -0.8s;
}
}

body:has(.in2publish-loading-overlay--active) > *:not(.in2publish-loading-overlay) {
filter: blur(3px);
}
Loading

0 comments on commit 0dcee19

Please sign in to comment.