Layout for export list

This commit is contained in:
2025-04-14 10:58:52 +02:00
parent 35f5501489
commit 2842548c17
4 changed files with 111 additions and 33 deletions

View File

@@ -11,14 +11,23 @@ declare(strict_types=1);
namespace Chill\MainBundle\Controller;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Export\ExportManager;
use Chill\MainBundle\Repository\ExportGenerationRepository;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
use Twig\Environment;
final readonly class ExportIndexController
{
public function __construct(private ExportManager $exportManager, private Environment $twig) {}
public function __construct(
private ExportManager $exportManager,
private Environment $twig,
private ExportGenerationRepository $exportGenerationRepository,
private Security $security,
) {}
/**
* Render the list of available exports.
@@ -26,11 +35,22 @@ final readonly class ExportIndexController
#[Route(path: '/{_locale}/exports/', name: 'chill_main_export_index')]
public function indexAction(ExportController $exportController): Response
{
$user = $this->security->getUser();
if (!$user instanceof User) {
throw new AccessDeniedHttpException('Only regular user can see this page');
}
$exports = $this->exportManager->getExportsGrouped(true);
$lastExecutions = [];
foreach ($this->exportManager->getExports() as $alias => $export) {
$lastExecutions[$alias] = $this->exportGenerationRepository->findExportGenerationByAliasAndUser($alias, $user, 5);
}
return new Response(
$this->twig->render('@ChillMain/Export/layout.html.twig', [
'grouped_exports' => $exports,
'last_executions' => $lastExecutions,
]),
);
}