This commit is contained in:
Constantin Simonis 2024-12-05 10:36:55 +01:00
parent 2123b5464f
commit b9aaff7931
Signed by: csimonis
GPG Key ID: 758DD9C506603183
6 changed files with 63 additions and 23 deletions

View File

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
class EntrypointController extends AbstractController
{
#[Route(path: '/', name: 'app_root', methods: Request::METHOD_GET)]
public function __invoke(): Response
{
return $this->redirectToRoute('app_home');
}
}

View File

@ -3,7 +3,6 @@
namespace App\Controller; namespace App\Controller;
use App\Forms\UploadFileForm; use App\Forms\UploadFileForm;
use App\Objects\UploadedFileData;
use App\Service\FileSystemService; use App\Service\FileSystemService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@ -12,25 +11,12 @@ use Symfony\Component\Routing\Attribute\Route;
class HomeController extends AbstractController class HomeController extends AbstractController
{ {
#[Route(path: '/', name: 'app_home', methods: [Request::METHOD_GET, Request::METHOD_POST])] #[Route(path: '/files', name: 'app_home', methods: [Request::METHOD_GET])]
public function __invoke( public function __invoke(FileSystemService $fileSystemService): Response
FileSystemService $fileSystemService,
Request $request,
): Response
{ {
$fileData = new UploadedFileData();
$form = $this->createForm(UploadFileForm::class, $fileData)->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
dd($form->getData(), $form->getExtraData());
$fileSystemService->uploadFile($fileData->file);
return $this->redirectToRoute('app_home');
}
return $this->render('home.html.twig', [ return $this->render('home.html.twig', [
'content' => $fileSystemService->getDirs(), 'content' => $fileSystemService->getDirs(),
'fileForm' => $form, 'fileForm' => $this->createForm(UploadFileForm::class),
]); ]);
} }
} }

View File

@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace App\Controller;
use App\Forms\UploadFileForm;
use App\Objects\UploadedFileData;
use App\Service\FileSystemService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
class UploadController extends AbstractController
{
#[Route(path: '/upload', name: 'app_upload', methods: Request::METHOD_POST)]
public function __invoke(
FileSystemService $fileSystemService,
Request $request,
): Response
{
$fileData = new UploadedFileData();
$form = $this->createForm(UploadFileForm::class, $fileData)->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$fileSystemService->uploadFile($fileData->file);
}
return $this->redirectToRoute('app_home');
}
}

View File

@ -5,12 +5,19 @@ namespace App\Forms;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\FileType; use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class UploadFileForm extends AbstractType class UploadFileForm extends AbstractType
{ {
public function __construct(private readonly UrlGeneratorInterface $urlGenerator)
{
}
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
{ {
$builder->add('file', FileType::class, [ $builder
->setAction($this->urlGenerator->generate('app_upload'))
->add('file', FileType::class, [
'attr' => ['class' => 'hidden'], 'attr' => ['class' => 'hidden'],
'multiple' => true, 'multiple' => true,
]); ]);

View File

@ -2,8 +2,8 @@
<table class="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400"> <table class="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400">
<thead class="text-xs text-gray-700 uppercase bg-gray-200 dark:bg-gray-700 dark:text-gray-400"> <thead class="text-xs text-gray-700 uppercase bg-gray-200 dark:bg-gray-700 dark:text-gray-400">
<tr> <tr>
<th scope="col" class="px-6 py-3"> <th scope="col" class="px-6 py-3" style="width: 5%;">
-
</th> </th>
<th scope="col" class="px-6 py-3"> <th scope="col" class="px-6 py-3">
name name

View File

@ -4,8 +4,6 @@
{% block body %} {% block body %}
<center class="container mt-5"> <center class="container mt-5">
<h1>Welcome to the File Explorer</h1>
<p>Use the navigation bar to explore the files and directories.</p>
{% include '_partials/_table.html.twig' %} {% include '_partials/_table.html.twig' %}
</center> </center>
{% endblock %} {% endblock %}