Auto-reload the log view, and scroll to bottom.

Includes a button to disable the automatic reloading (useful when inspecting some lines in the middle).

Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>
This commit is contained in:
Pablo Zmdl
2026-02-20 14:22:57 +01:00
parent 1ddaa30b0f
commit 862a17ab4e
2 changed files with 35 additions and 7 deletions

View File

@@ -11,6 +11,7 @@ use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use AIO\Data\ConfigurationManager;
use Slim\Psr7\NonBufferedBody;
use Slim\Views\Twig;
readonly class DockerController {
private const string TOP_CONTAINER = 'nextcloud-aio-apache';
@@ -76,13 +77,8 @@ readonly class DockerController {
$logs = 'Container not found.';
}
$body = $response->getBody();
$body->write($logs);
return $response
->withStatus(200)
->withHeader('Content-Type', 'text/plain; charset=utf-8')
->withHeader('Content-Disposition', 'inline');
$view = Twig::fromRequest($request);
return $view->render($response, 'log.twig', ['logContent' => $logs]);
}
public function StartBackupContainerBackup(Request $request, Response $response, array $args) : Response {

32
php/templates/log.twig Normal file
View File

@@ -0,0 +1,32 @@
<html lang="en">
<head>
<style>
button {
position: fixed;
top: 1rem;
right: 1rem;
font-size: 1.3rem;
}
</style>
<script>
document.addEventListener("DOMContentLoaded", () => {
// Give the browser a short moment to render all text and calculate the scrollHeight, to avoid
// problems with scrolling to the bottom.
setTimeout(() => window.scrollTo(0, document.body.scrollHeight), 100);
const reloadTimer = setTimeout(() => location.reload(), 10000);
const button = document.querySelector('button');
document.querySelector('button').addEventListener('click', (event) => {
event.preventDefault();
clearTimeout(reloadTimer);
button.disabled = true;
button.textContent = 'Reloading was disabled';
});
});
</script>
</head>
<body>
<button>Disable auto-reloading</button>
<pre>{{ logContent }}</pre>
<div id="bottom"></div>
</body>
</html>