From 9adbde0308393eddfbf5deac98e083777cf1bd96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 26 May 2025 10:35:27 +0200 Subject: [PATCH] Add export configuration comparison and update options logic Introduced a method to compare export generation options with saved exports, enabling detection of configuration differences. Updated template logic to conditionally adjust UI elements based on configuration discrepancies. This enhances flexibility when managing saved export options. --- .../Entity/ExportGeneration.php | 26 ++++++++++- .../views/ExportGeneration/wait.html.twig | 45 ++++++++++--------- 2 files changed, 49 insertions(+), 22 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Entity/ExportGeneration.php b/src/Bundle/ChillMainBundle/Entity/ExportGeneration.php index ede2943bd..a8d4e274b 100644 --- a/src/Bundle/ChillMainBundle/Entity/ExportGeneration.php +++ b/src/Bundle/ChillMainBundle/Entity/ExportGeneration.php @@ -54,6 +54,13 @@ class ExportGeneration implements TrackCreationInterface private array $options = [], #[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_IMMUTABLE, nullable: true)] private ?\DateTimeImmutable $deleteAt = null, + + /** + * The related saved export. + * + * Note that, in some case, the options of this ExportGenration are not equals to the options of the saved export. + * This happens when the options of the saved export are updated. + */ #[ORM\ManyToOne(targetEntity: SavedExport::class)] #[ORM\JoinColumn(nullable: true)] private ?SavedExport $savedExport = null, @@ -118,9 +125,24 @@ class ExportGeneration implements TrackCreationInterface return null !== $this->savedExport; } - public static function fromSavedExport(SavedExport $savedExport, ?\DateTimeImmutable $deletedAt = null): self + /** + * Compares the options of the saved export and the current export generation. + * + * Return false if the current export generation's options are not equal to the one in the saved export. This may + * happens when we update the configuration of a saved export. + */ + public function isConfigurationDifferentFromSavedExport(): bool { - $generation = new self($savedExport->getExportAlias(), $savedExport->getOptions(), $deletedAt, $savedExport); + if (!$this->isLinkedToSavedExport()) { + return false; + } + + return $this->savedExport->getOptions() !== $this->getOptions(); + } + + public static function fromSavedExport(SavedExport $savedExport, ?\DateTimeImmutable $deletedAt = null, ?array $overrideOptions = null): self + { + $generation = new self($savedExport->getExportAlias(), $overrideOptions ?? $savedExport->getOptions(), $deletedAt, $savedExport); $generation->getStoredObject()->setTitle($savedExport->getTitle()); return $generation; diff --git a/src/Bundle/ChillMainBundle/Resources/views/ExportGeneration/wait.html.twig b/src/Bundle/ChillMainBundle/Resources/views/ExportGeneration/wait.html.twig index 89af3a70e..a93edf965 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/ExportGeneration/wait.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/ExportGeneration/wait.html.twig @@ -10,7 +10,10 @@ {{ encore_entry_link_tags('page_download_exports') }} {% endblock %} + {% block title exportGeneration.linkedToSavedExport ? exportGeneration.savedExport.title : 'Download export' %} + {% block content %} +

{{ block('title') }}

- {% if not exportGeneration.isLinkedToSavedExport %} + {% if not exportGeneration.linkedToSavedExport %}
  • {{ 'Save'|trans }}
  • {% else %} -
  • - +
  • + {% endif %} {% endif %} {% endblock content %}