allow to edit existing saved export with new export options

This commit is contained in:
Julien Fastré 2023-06-06 10:49:00 +02:00
parent c3ac382711
commit b4614974c0
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
4 changed files with 55 additions and 12 deletions

View File

@ -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)

View File

@ -147,7 +147,6 @@ final readonly class ExportFormHelper
SavedExport $savedExport,
array $formOptions
): array {
dump(__METHOD__);
$builder = $this->formFactory
->createBuilder(
FormType::class,

View File

@ -1,5 +1,5 @@
{#
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
<info@champs-libres.coop> / <http://www.champs-libres.coop>
*
* 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 %}
<script type="text/javascript">
window.addEventListener("DOMContentLoaded", function(e) {
@ -27,20 +27,20 @@ window.addEventListener("DOMContentLoaded", function(e) {
query = window.location.search,
container = document.querySelector("#download_container")
;
chill.download_report(url+query, container);
});
});
</script>
{% endblock %}
{% block content %}
<div class="col-md-10">
{{ include('@ChillMain/Export/_breadcrumb.html.twig') }}
<h1>{{ export.title|trans }}</h1>
<h2>{{ "Download export"|trans }}</h2>
<div id="download_container"
data-alias="{{ alias|escape('html_attr') }}"
{%- if mime_type is defined %}
@ -53,10 +53,24 @@ window.addEventListener("DOMContentLoaded", function(e) {
<li class="cancel"><a href="{{ chill_return_path_or('chill_main_export_index') }}" class="btn btn-cancel">{{ 'Back to the list'|trans }}</a></li>
{% if not app.request.query.has('prevent_save') %}
{% if saved_export is null %}
<li>
<a href="{{ chill_path_add_return_path('chill_main_export_save_from_key', { alias: alias, key: app.request.query.get('key')}) }}" 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">
<li><a href="{{ chill_path_add_return_path('chill_main_export_save_from_key', { alias: alias, key: app.request.query.get('key')}) }}" class="dropdown-item">{{ 'Save'|trans }}</a></li>
<li><a href="{{ chill_path_add_return_path('chill_main_export_saved_edit_options_from_key', { id: saved_export.id(), key: app.request.query.get('key') }) }}" class="dropdown-item">{{ 'saved_export.Update existing'|trans }}</a></li>
</ul>
</div>
</li>
{% endif %}
{% endif %}
</ul>
</div>
{% endblock content %}
{% endblock content %}

View File

@ -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