mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
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:
parent
fe31cfd544
commit
9adbde0308
@ -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;
|
||||
|
@ -10,7 +10,10 @@
|
||||
{{ encore_entry_link_tags('page_download_exports') }}
|
||||
{% endblock %}
|
||||
|
||||
{% block title exportGeneration.linkedToSavedExport ? exportGeneration.savedExport.title : 'Download export' %}
|
||||
|
||||
{% block content %}
|
||||
<h1>{{ block('title') }}</h1>
|
||||
<div id="app"
|
||||
data-export-generation-id="{{ exportGeneration.id | escape('html_attr') }}"
|
||||
data-export-generation-date="{{ exportGeneration.createdAt.format('Ymd-His') }}"
|
||||
@ -23,34 +26,36 @@
|
||||
{{ 'export.generation.Come back later'|trans|chill_return_path_label }}
|
||||
</a>
|
||||
</li>
|
||||
{% if not exportGeneration.isLinkedToSavedExport %}
|
||||
{% if not exportGeneration.linkedToSavedExport %}
|
||||
<li>
|
||||
<a href="{{ chill_path_add_return_path('chill_main_export_saved_create_from_export_generation', {'id': exportGeneration.id}) }}" class="btn btn-save">
|
||||
{{ 'Save'|trans }}
|
||||
</a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li>
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-save dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">{{ 'Save'|trans }}</button>
|
||||
<ul class="dropdown-menu dropdown-menu-end">
|
||||
<li class="dropdown-item">
|
||||
<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) %}
|
||||
{% if exportGeneration.configurationDifferentFromSavedExport %}
|
||||
<li>
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-save dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">{{ 'Save'|trans }}</button>
|
||||
<ul class="dropdown-menu dropdown-menu-end">
|
||||
<li class="dropdown-item">
|
||||
<form method="POST" action="{{ path('chill_main_export_saved_options_edit', {'savedExport': exportGeneration.savedExport.id, 'exportGeneration': exportGeneration.id }) }}">
|
||||
<button type="submit" class="btn">
|
||||
<i class="bi bi-floppy"></i> {{ 'saved_export.Update current saved export'|trans }}
|
||||
</button>
|
||||
</form>
|
||||
<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>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
</li>
|
||||
{% if is_granted('CHILL_MAIN_EXPORT_SAVED_EDIT', exportGeneration.savedExport) %}
|
||||
<li class="dropdown-item">
|
||||
<form method="POST" action="{{ path('chill_main_export_saved_options_edit', {'savedExport': exportGeneration.savedExport.id, 'exportGeneration': exportGeneration.id }) }}">
|
||||
<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 %}
|
||||
</ul>
|
||||
{% endblock content %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user