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.
This commit is contained in:
Julien Fastré 2025-05-26 10:35:27 +02:00
parent fe31cfd544
commit 9adbde0308
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
2 changed files with 49 additions and 22 deletions

View File

@ -54,6 +54,13 @@ class ExportGeneration implements TrackCreationInterface
private array $options = [], private array $options = [],
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_IMMUTABLE, nullable: true)] #[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_IMMUTABLE, nullable: true)]
private ?\DateTimeImmutable $deleteAt = null, 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\ManyToOne(targetEntity: SavedExport::class)]
#[ORM\JoinColumn(nullable: true)] #[ORM\JoinColumn(nullable: true)]
private ?SavedExport $savedExport = null, private ?SavedExport $savedExport = null,
@ -118,9 +125,24 @@ class ExportGeneration implements TrackCreationInterface
return null !== $this->savedExport; 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()); $generation->getStoredObject()->setTitle($savedExport->getTitle());
return $generation; return $generation;

View File

@ -10,7 +10,10 @@
{{ encore_entry_link_tags('page_download_exports') }} {{ encore_entry_link_tags('page_download_exports') }}
{% endblock %} {% endblock %}
{% block title exportGeneration.linkedToSavedExport ? exportGeneration.savedExport.title : 'Download export' %}
{% block content %} {% block content %}
<h1>{{ block('title') }}</h1>
<div id="app" <div id="app"
data-export-generation-id="{{ exportGeneration.id | escape('html_attr') }}" data-export-generation-id="{{ exportGeneration.id | escape('html_attr') }}"
data-export-generation-date="{{ exportGeneration.createdAt.format('Ymd-His') }}" data-export-generation-date="{{ exportGeneration.createdAt.format('Ymd-His') }}"
@ -23,34 +26,36 @@
{{ 'export.generation.Come back later'|trans|chill_return_path_label }} {{ 'export.generation.Come back later'|trans|chill_return_path_label }}
</a> </a>
</li> </li>
{% if not exportGeneration.isLinkedToSavedExport %} {% if not exportGeneration.linkedToSavedExport %}
<li> <li>
<a href="{{ chill_path_add_return_path('chill_main_export_saved_create_from_export_generation', {'id': exportGeneration.id}) }}" class="btn btn-save"> <a href="{{ chill_path_add_return_path('chill_main_export_saved_create_from_export_generation', {'id': exportGeneration.id}) }}" class="btn btn-save">
{{ 'Save'|trans }} {{ 'Save'|trans }}
</a> </a>
</li> </li>
{% else %} {% else %}
<li> {% if exportGeneration.configurationDifferentFromSavedExport %}
<div class="dropdown"> <li>
<button class="btn btn-save dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">{{ 'Save'|trans }}</button> <div class="dropdown">
<ul class="dropdown-menu dropdown-menu-end"> <button class="btn btn-save dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">{{ 'Save'|trans }}</button>
<li class="dropdown-item"> <ul class="dropdown-menu dropdown-menu-end">
<a href="{{ chill_path_add_return_path('chill_main_export_saved_create_from_export_generation', {'id': exportGeneration.id, 'title': exportGeneration.savedExport.title ~ ' (' ~ 'saved_export.Duplicated'|trans ~ ' ' ~ null|format_datetime('short', 'medium') ~ ')'}) }}" class="btn">
<i class="bi bi-copy"></i> {{ 'saved_export.Save to new saved export'|trans }}
</a>
</li>
{% if is_granted('CHILL_MAIN_EXPORT_SAVED_EDIT', exportGeneration.savedExport) %}
<li class="dropdown-item"> <li class="dropdown-item">
<form method="POST" action="{{ path('chill_main_export_saved_options_edit', {'savedExport': exportGeneration.savedExport.id, 'exportGeneration': exportGeneration.id }) }}"> <a href="{{ chill_path_add_return_path('chill_main_export_saved_create_from_export_generation', {'id': exportGeneration.id, 'title': exportGeneration.savedExport.title ~ ' (' ~ 'saved_export.Duplicated'|trans ~ ' ' ~ null|format_datetime('short', 'medium') ~ ')'}) }}" class="btn">
<button type="submit" class="btn"> <i class="bi bi-copy"></i> {{ 'saved_export.Save to new saved export'|trans }}
<i class="bi bi-floppy"></i> {{ 'saved_export.Update current saved export'|trans }} </a>
</button>
</form>
</li> </li>
{% endif %} {% if is_granted('CHILL_MAIN_EXPORT_SAVED_EDIT', exportGeneration.savedExport) %}
</ul> <li class="dropdown-item">
</div> <form method="POST" action="{{ path('chill_main_export_saved_options_edit', {'savedExport': exportGeneration.savedExport.id, 'exportGeneration': exportGeneration.id }) }}">
</li> <button type="submit" class="btn">
<i class="bi bi-floppy"></i> {{ 'saved_export.Update current saved export'|trans }}
</button>
</form>
</li>
{% endif %}
</ul>
</div>
</li>
{% endif %}
{% endif %} {% endif %}
</ul> </ul>
{% endblock content %} {% endblock content %}