diff --git a/src/Bundle/ChillMainBundle/Controller/ExportIndexController.php b/src/Bundle/ChillMainBundle/Controller/ExportIndexController.php index 51cd04833..d65a6c55e 100644 --- a/src/Bundle/ChillMainBundle/Controller/ExportIndexController.php +++ b/src/Bundle/ChillMainBundle/Controller/ExportIndexController.php @@ -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, ]), ); } diff --git a/src/Bundle/ChillMainBundle/Repository/ExportGenerationRepository.php b/src/Bundle/ChillMainBundle/Repository/ExportGenerationRepository.php index 4482f2972..7b6cbf13c 100644 --- a/src/Bundle/ChillMainBundle/Repository/ExportGenerationRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/ExportGenerationRepository.php @@ -14,6 +14,8 @@ namespace Chill\MainBundle\Repository; use Chill\DocStoreBundle\Entity\StoredObject; use Chill\DocStoreBundle\Repository\AssociatedEntityToStoredObjectInterface; use Chill\MainBundle\Entity\ExportGeneration; +use Chill\MainBundle\Entity\SavedExport; +use Chill\MainBundle\Entity\User; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; @@ -37,4 +39,38 @@ class ExportGenerationRepository extends ServiceEntityRepository implements Asso ->getQuery() ->getOneOrNullResult(); } + + /** + * @return list + */ + public function findExportGenerationByAliasAndUser(string $alias, User $user, int $limit = 100, int $offset = 0): array + { + return $this->createQueryBuilder('e') + ->where('e.createdBy = :user') + ->andWhere('e.exportAlias LIKE :alias') + ->orderBy('e.createdAt', 'DESC') + ->setParameter('user', $user) + ->setParameter('alias', $alias) + ->setFirstResult($offset) + ->setMaxResults($limit) + ->getQuery() + ->getResult(); + } + + /** + * @return list + */ + public function findExportGenerationBySavedExportAndUser(SavedExport $savedExport, User $user, int $limit = 100, int $offset = 0): array + { + return $this->createQueryBuilder('e') + ->where('e.createdBy = :user') + ->andWhere('e.savedExport = :savedExport') + ->orderBy('e.createdAt', 'DESC') + ->setParameter('user', $user) + ->setParameter('savedExport', $savedExport) + ->setFirstResult($offset) + ->setMaxResults($limit) + ->getQuery() + ->getResult(); + } } diff --git a/src/Bundle/ChillMainBundle/Resources/views/Export/layout.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Export/layout.html.twig index 873ace4ac..9f5b5e99f 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Export/layout.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Export/layout.html.twig @@ -1,5 +1,5 @@ {# - * Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS, + * Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS, / * * This program is free software: you can redistribute it and/or modify @@ -20,6 +20,49 @@ {% block title %}{{ 'Exports list'|trans }}{% endblock %} +{% block css %} + {{ parent() }} + +{% endblock %} + +{% macro render_export_card(export, export_alias, generations) %} +
+
+
+

{{ export.title|trans }}

+

{{ export.description|trans }}

+
+ {% if generations|length > 0 %} +
    + {% for generation in generations %} +
  • + {{ generation.createdAt|format_datetime('short', 'short') }} + {% if generation.status == 'pending' %} +  {{ 'export.generation.Export generation is pending_short'|trans }} + {% elseif generation.status == 'failure' %} +  {{ 'export.generation.Error_short'|trans }} + {% endif %} +
  • + {% endfor %} +
+ {% endif %} + +
+
+{% endmacro %} {% block content %} @@ -28,45 +71,23 @@
- + {% for group, exports in grouped_exports %}{% if group != '_' %} -

{{ group|trans }}

-
+

{{ group|trans }}

+
{% for export_alias, export in exports %} -
-
-

{{ export.title|trans }}

-

{{ export.description|trans }}

-

- - {{ 'Create an export'|trans }} - -

-
-
+ {{ _self.render_export_card(export, export_alias, last_executions[export_alias]) }} {% endfor %}
{% endif %}{% endfor %} - + {% if grouped_exports|keys|length > 1 and grouped_exports['_']|length > 0 %} -

{{ 'Ungrouped exports'|trans }}

+

{{ 'Ungrouped exports'|trans }}

{% endif %} - -
+ +
{% for export_alias,export in grouped_exports['_'] %} - -
-
-

{{ export.title|trans }}

-

{{ export.description|trans }}

-

- - {{ 'Create an export'|trans }} - -

-
-
- + {{ _self.render_export_card(export, export_alias, last_executions[export_alias]) }} {% endfor %}
diff --git a/src/Bundle/ChillMainBundle/translations/messages.fr.yml b/src/Bundle/ChillMainBundle/translations/messages.fr.yml index a37f9ed23..10f106e95 100644 --- a/src/Bundle/ChillMainBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillMainBundle/translations/messages.fr.yml @@ -722,6 +722,7 @@ export: Come back later: Retour à l'index Too many retries: Le nombre de vérification de la disponibilité de l'export a échoué. Essayez de recharger la page. Error while generating export: Erreur interne lors de la génération de l'export + Error_short: En erreur Export ready: L'export est prêt à être téléchargé address_helper: id: Identifiant de l'adresse