diff --git a/Dockerfile b/Dockerfile index 4f54837..40cba40 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,4 +17,4 @@ RUN docker-php-ext-install pdo pdo_mysql mysqli gd opcache intl zip calendar dom RUN pecl install apcu && docker-php-ext-enable apcu WORKDIR /var/www/project -RUN composer install --no-dev --optimize-autoloader --no-suggest --no-progress +RUN composer install --optimize-autoloader --no-suggest --no-progress diff --git a/assets/styles/app.css b/assets/styles/app.css index aba4857..eb9da0d 100644 --- a/assets/styles/app.css +++ b/assets/styles/app.css @@ -1,3 +1,8 @@ body { background-color: transparent; +} + +a:hover { + color: deepskyblue; + text-decoration: underline; } \ No newline at end of file diff --git a/config/packages/twig.yaml b/config/packages/twig.yaml index 3f795d9..e13e04b 100644 --- a/config/packages/twig.yaml +++ b/config/packages/twig.yaml @@ -1,5 +1,7 @@ twig: file_name_pattern: '*.twig' + globals: + routing_service: '@App\Service\Twig\RoutingService' when@test: twig: diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index 22efda8..0b824d6 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -11,11 +11,17 @@ use Symfony\Component\Routing\Attribute\Route; class HomeController extends AbstractController { - #[Route(path: '/files', name: 'app_home', methods: [Request::METHOD_GET])] - public function __invoke(FileSystemService $fileSystemService): Response + #[Route( + path: '/files/{dirs?}', + name: 'app_home', + requirements: ['dirs' => '.+'], + defaults: ['dirs' => ''], + methods: [Request::METHOD_GET] + )] + public function __invoke(FileSystemService $fileSystemService, string $dirs): Response { return $this->render('home.html.twig', [ - 'content' => $fileSystemService->getDirs(), + 'content' => $fileSystemService->getDirs($dirs), 'fileForm' => $this->createForm(UploadFileForm::class), ]); } diff --git a/src/Service/FileSystemService.php b/src/Service/FileSystemService.php index d6cb8f6..6df4667 100644 --- a/src/Service/FileSystemService.php +++ b/src/Service/FileSystemService.php @@ -20,10 +20,10 @@ class FileSystemService /** * @return DirContent[] */ - public function getDirs(): array + public function getDirs(string $dirs): array { $finder = new Finder(); - $finder->in($this->dir); + $finder->in($this->dir . '/' . $dirs); $contents = []; diff --git a/src/Service/Twig/RoutingService.php b/src/Service/Twig/RoutingService.php new file mode 100644 index 0000000..fdca911 --- /dev/null +++ b/src/Service/Twig/RoutingService.php @@ -0,0 +1,23 @@ +attributes->get('dirs', ''); + $dirs = explode('/', $dirsString); + array_pop($dirs); + + return $this->urlGenerator->generate('app_home', ['dirs' => implode('/', $dirs)]); + } +} \ No newline at end of file diff --git a/templates/_partials/_row.html.twig b/templates/_partials/_row.html.twig index cf570e4..680bbdd 100644 --- a/templates/_partials/_row.html.twig +++ b/templates/_partials/_row.html.twig @@ -1,13 +1,24 @@ +{% if file.name == '..' %} + {% set link = routing_service.goBack(app.request) %} +{% else %} + {% set link = path('app_home', {dirs: app.request.attributes.get('dirs', '/') ~ file.name ~ '/'}) %} +{% endif %} + + - {% if file.type == 'dir' %} - {{ ux_icon('folder:closed', {height: '32px', width: '32px'}) }} - {% else %} - {{ ux_icon('file:default', {height: '32px', width: '32px'}) }} - {% endif %} + + {% if file.type == 'dir' %} + {{ ux_icon('folder:closed', {height: '32px', width: '32px'}) }} + {% else %} + {{ ux_icon('file:default', {height: '32px', width: '32px'}) }} + {% endif %} + - {{ file.name }} + + {{ file.name }} + {{ file.size }} diff --git a/templates/_partials/_table.html.twig b/templates/_partials/_table.html.twig index b159d15..5f7c8ed 100644 --- a/templates/_partials/_table.html.twig +++ b/templates/_partials/_table.html.twig @@ -14,6 +14,9 @@ + {% if app.request.requestUri != '/files' %} + {% include '_partials/_row.html.twig' with {file: {name: '..', size: '-', type: 'dir'}} %} + {% endif %} {% for dirContent in content %} {% include '_partials/_row.html.twig' with {file: dirContent} %} {% endfor %} @@ -24,10 +27,12 @@ {{ form_start(fileForm, {'attr': {'data-controller': 'upload-file'}}) }}
-