Skip to content

Commit e4e4589

Browse files
authored
Add configurable home route (#25)
1 parent bc908a5 commit e4e4589

File tree

15 files changed

+73
-31
lines changed

15 files changed

+73
-31
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,5 @@ By default, the application is available at: `{APP_URL}/log-viewer`.
8383
- [Modifying monolog configuration](docs/modifying-monolog-configuration.md)
8484
- [Disabling the default monolog configuration](docs/disabling-default-monolog-configuration.md)
8585
- [Adding additional log files](docs/adding-additional-log-files.md)
86+
- [Configuring the back home url](docs/configuring-the-back-home-route.md)
8687
- [Full configuration reference](docs/configuration-reference.md)

docs/configuration-reference.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Out of the box, [Log viewer](../README.md) will have the following configuration
77
```yaml
88
fd_log_viewer:
99
enable_default_monolog: true
10+
home_route: null
1011

1112
log_files:
1213
monolog:
@@ -35,6 +36,13 @@ fd_log_viewer:
3536
Out of the box the bundle is configured with a default monolog configuration. Set this to `false` to override this behaviour.
3637
<br><br>
3738

39+
### home_route
40+
41+
**type**: `string|null`. Default: `null`
42+
43+
The name of the route that will be used as url for the back button. If null the back button will redirect to `https://your-domain/`.
44+
<br><br>
45+
3846
### log_files
3947

4048
**type**: `array<string, mixed>`
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Configuring the home route
2+
3+
By default, the back button will redirect to the `/` route. You can change this by setting the `home_route` option in the configuration:
4+
5+
```yaml
6+
# config/packages/fd_log_viewer.yaml
7+
fd_log_viewer:
8+
home_route: App\Controller\HomeController
9+
```

frontend/src/LogViewer.vue

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22
import FileTree from '@/components/FileTree.vue'
33
import {useRoute} from 'vue-router';
44
5-
const route = useRoute();
5+
const route = useRoute();
6+
const homeUri = document.head.querySelector<HTMLMetaElement>('[name=home-uri]')!.content;
67
</script>
78

89
<template>
910
<div class="slv-sidebar h-100 overflow-hidden">
10-
<header class="slv-header-height bg-body">
11-
<h3 class="d-block text-center slv-app-title">
11+
<header class="slv-header-height slv-header bg-body position-relative">
12+
<a :href="homeUri" class="slv-back text-decoration-none">
13+
<i class="bi bi-arrow-left-short"></i>Back
14+
</a>
15+
16+
<h4 class="d-block text-center slv-app-title m-0">
1217
<i class="bi bi-substack slv-icon-color"></i>
13-
Log viewer
14-
</h3>
18+
Log viewer </h4>
1519
</header>
1620

1721
<FileTree/>
@@ -20,11 +24,24 @@ const route = useRoute();
2024
</template>
2125

2226
<style scoped>
27+
.slv-app-title {
28+
color: rgb(2, 132, 199);
29+
height: var(--slv-min-header-height);
30+
line-height: var(--slv-min-header-height);
31+
}
32+
2333
.slv-sidebar {
2434
display: grid;
2535
grid-template-rows: auto 1fr;
2636
}
2737
38+
.slv-back {
39+
position: absolute;
40+
left: 0;
41+
height: var(--slv-min-header-height);
42+
line-height: var(--slv-min-header-height);
43+
}
44+
2845
.slv-icon-color {
2946
color: #fff;
3047
}

frontend/src/assets/main.scss

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,13 @@
3030
}
3131
}
3232

33-
.slv-app-title {
34-
color: rgb(2, 132, 199)
35-
}
36-
3733
.slv-body-grid {
3834
display: grid;
3935
grid-template-columns: minmax(var(--slv-min-sidebar-width), min(25%, var(--slv-max-sidebar-width))) 1fr;
4036
}
4137

4238
.slv-header-height {
39+
box-sizing: border-box;
4340
min-height: var(--slv-min-header-height);
4441
}
4542

frontend/src/main.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@ const app = createApp(LogViewer);
1818

1919
app.use(createPinia());
2020
app.use(router(baseUri));
21-
2221
app.mount('#log-viewer');

src/Controller/IndexController.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
class IndexController extends AbstractController
1515
{
1616
public function __construct(
17+
private readonly ?string $homeRoute,
1718
private readonly JsonManifestAssetLoader $assetLoader,
1819
private readonly RouteService $routeService,
1920
private readonly LogFolderOutputProvider $folderOutputProvider
@@ -34,9 +35,10 @@ public function __invoke(): Response
3435
return $this->render(
3536
'@FDLogViewer/index.html.twig',
3637
[
37-
'base_uri' => $baseUri,
38-
'folders' => $folders,
39-
'assets' => [
38+
'base_uri' => $baseUri,
39+
'home_route' => $this->homeRoute,
40+
'folders' => $folders,
41+
'assets' => [
4042
'style' => $this->assetLoader->getUrl('style.css'),
4143
'js' => $this->assetLoader->getUrl('src/main.ts')
4244
],

src/DependencyInjection/Configuration.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public function getConfigTreeBuilder(): TreeBuilder
3333
->scalarNode('type')
3434
->info("The type of log file: monolog, nginx, apache, or the service id of an implementation of `LogFileParserInterface`")
3535
->end()
36+
->scalarNode('home_route')
37+
->info("The name of the route to redirect to when clicking the back button")
38+
->end()
3639
->scalarNode('name')->info("The pretty name to show for these log files")->defaultNull()->end()
3740
->arrayNode('finder')
3841
->children()

src/DependencyInjection/Extension.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public function load(array $configs, ContainerBuilder $container): void
4848

4949
$mergedConfigs = $this->processConfiguration(new Configuration(), $configs);
5050

51+
$container->setParameter('fd.symfony.log.viewer.log_files_config.home_route', $mergedConfigs['home_route'] ?? null);
52+
5153
// add defaults
5254
if ($mergedConfigs['enable_default_monolog']) {
5355
$mergedConfigs = Arrays::merge($mergedConfigs, self::DEFAULT_MONOLOG_CONFIG);

src/Resources/config/services.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
->autowire()
4141
->autoconfigure();
4242

43-
$services->set(IndexController::class)->tag('controller.service_arguments');
43+
$services->set(IndexController::class)
44+
->arg('$homeRoute', '%fd.symfony.log.viewer.log_files_config.home_route%')
45+
->tag('controller.service_arguments');
4446
$services->set(FoldersController::class)->tag('controller.service_arguments');
4547
$services->set(LogRecordsController::class)->tag('controller.service_arguments');
4648
$services->set(DownloadFileController::class)->tag('controller.service_arguments');

0 commit comments

Comments
 (0)