From ad82685c02b56e848b3ace2581ebd52239d43a86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 6 Jun 2023 10:49:00 +0200 Subject: [PATCH] allow to edit existing saved export with new export options --- .../Controller/ExportController.php | 33 +++++++++++++++++-- .../Export/ExportFormHelper.php | 1 - .../Resources/views/Export/download.html.twig | 32 +++++++++++++----- .../translations/messages.fr.yml | 1 + 4 files changed, 55 insertions(+), 12 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Controller/ExportController.php b/src/Bundle/ChillMainBundle/Controller/ExportController.php index 2ad6377a6..e8ee9b97b 100644 --- a/src/Bundle/ChillMainBundle/Controller/ExportController.php +++ b/src/Bundle/ChillMainBundle/Controller/ExportController.php @@ -127,6 +127,7 @@ class ExportController extends AbstractController 'alias' => $alias, 'export' => $export, 'export_group' => $this->getExportGroup($export), + 'saved_export' => $savedExport, ]; if ($formater instanceof \Chill\MainBundle\Export\Formatter\CSVListFormatter) { @@ -245,6 +246,28 @@ class ExportController extends AbstractController } } + /** + * @Route("/{_locale}/export/saved/update-from-key/{id}/{key}", name="chill_main_export_saved_edit_options_from_key") + */ + public function editSavedExportOptionsFromKey(SavedExport $savedExport, string $key): Response + { + $this->denyAccessUnlessGranted('ROLE_USER'); + $user = $this->getUser(); + + if (!$user instanceof User) { + throw new AccessDeniedHttpException(); + } + + $data = $this->rebuildRawData($key); + + $savedExport + ->setOptions($data); + + $this->entityManager->flush(); + + return $this->redirectToRoute('chill_main_export_saved_edit', ['id' => $savedExport->getId()]); + } + /** * @Route("/{_locale}/export/save-from-key/{alias}/{key}", name="chill_main_export_save_from_key") */ @@ -478,7 +501,9 @@ class ExportController extends AbstractController if (null === $dataFormatter && $export instanceof \Chill\MainBundle\Export\ExportInterface) { return $this->redirectToRoute('chill_main_export_new', [ - 'alias' => $alias, 'step' => $this->getNextStep('generate', $export, true), + 'alias' => $alias, + 'step' => $this->getNextStep('generate', $export, true), + 'from_saved' => $savedExport?->getId() ?? '', ]); } @@ -499,7 +524,11 @@ class ExportController extends AbstractController $this->session->remove('formatter_step_raw'); $this->session->remove('formatter_step'); - return $this->redirectToRoute('chill_main_export_download', ['key' => $key, 'alias' => $alias]); + return $this->redirectToRoute('chill_main_export_download', [ + 'key' => $key, + 'alias' => $alias, + 'from_saved' => $savedExport?->getId(), + ]); } private function rebuildData($key, ?SavedExport $savedExport) diff --git a/src/Bundle/ChillMainBundle/Export/ExportFormHelper.php b/src/Bundle/ChillMainBundle/Export/ExportFormHelper.php index 3deb2acbc..c2127fb36 100644 --- a/src/Bundle/ChillMainBundle/Export/ExportFormHelper.php +++ b/src/Bundle/ChillMainBundle/Export/ExportFormHelper.php @@ -147,7 +147,6 @@ final readonly class ExportFormHelper SavedExport $savedExport, array $formOptions ): array { - dump(__METHOD__); $builder = $this->formFactory ->createBuilder( FormType::class, diff --git a/src/Bundle/ChillMainBundle/Resources/views/Export/download.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Export/download.html.twig index 1e69c5a49..bd7dbf7e9 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Export/download.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Export/download.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 @@ -19,7 +19,7 @@ {% extends "@ChillMain/layout.html.twig" %} {% block title "Download export"|trans ~ export.title|trans %} - + {% block js %} {% endblock %} - + {% block content %}
- + {{ include('@ChillMain/Export/_breadcrumb.html.twig') }} - +

{{ export.title|trans }}

{{ "Download export"|trans }}

- +
{{ 'Back to the list'|trans }} {% if not app.request.query.has('prevent_save') %} + {% if saved_export is null %}
  • {{ 'Save'|trans }}
  • + {% else %} +
  • + +
  • + {% endif %} {% endif %}
    -{% endblock content %} \ No newline at end of file +{% endblock content %} diff --git a/src/Bundle/ChillMainBundle/translations/messages.fr.yml b/src/Bundle/ChillMainBundle/translations/messages.fr.yml index 4a85db149..bbe3d23fb 100644 --- a/src/Bundle/ChillMainBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillMainBundle/translations/messages.fr.yml @@ -601,6 +601,7 @@ saved_export: update_title_and_description: Modifier le titre et la description update_filters_aggregators_and_execute: Modifier les filtres et regroupements et télécharger execute: Télécharger + Update existing: Mettre à jour le rapport enregistré existant absence: # single letter for absence