Allow to group exports

This commit is contained in:
Julien Fastré 2019-06-18 21:01:32 +02:00
parent b7e71088ac
commit 9c6a3de0ff
5 changed files with 76 additions and 14 deletions

View File

@ -107,10 +107,10 @@ class ExportController extends Controller
{
$exportManager = $this->exportManager;
$exports = $exportManager->getExports(true);
$exports = $exportManager->getExportsGrouped(true);
return $this->render('ChillMainBundle:Export:layout.html.twig', array(
'exports' => $exports
'grouped_exports' => $exports
));
}

View File

@ -231,6 +231,26 @@ class ExportManager
}
}
/**
* Get all exports grouped in an array.
*
* @param bool $whereUserIsGranted
* @return array where keys are the groups's name and value is an array of exports
*/
public function getExportsGrouped($whereUserIsGranted = true): array
{
$groups = [ '_' => [] ];
foreach ($this->getExports($whereUserIsGranted) as $alias => $export) {
if ($export instanceof GroupedExportInterface) {
$groups[$export->getGroup()][$alias] = $export;
} else {
$groups['_'][$alias] = $export;
}
}
return $groups;
}
/**
* Return an export by his alias
*

View File

@ -0,0 +1,16 @@
<?php
/*
*
*/
namespace Chill\MainBundle\Export;
/**
* Add a grouping option to exports.
*
* **usage**: the exports will be grouped under the key given by the `getGroup`
* method.
*/
interface GroupedExportInterface
{
public function getGroup(): string;
}

View File

@ -173,6 +173,7 @@ Choose a format: Choisir un format
#export creation step 'formatter' : choose formatter option
Generate the report: Générer le rapport
No options availables. Your report is fully configured.: Pas d'options disponibles. Votre rapport est déjà configuré.
Ungrouped exports: Autres exports
#export download
Download export: Téléchargement du rapport

View File

@ -25,19 +25,44 @@
<div class="container-export">
<h1>{{ 'Exports list'|trans }}</h1>
<div class="export-list">
{% for export_alias,export in exports %}
<div class="export-list__element">
<h2>{{ export.title|trans }}</h2>
<p>{{ export.description|trans }}</p>
<div>
{% for group, exports in grouped_exports if group != '_' %}
<h2>{{ group }}</h2>
<div class="export-list">
{% for export_alias, export in exports %}
<div class="export-list__element">
<h2>{{ export.title|trans }}</h2>
<p>{{ export.description|trans }}</p>
<p>
<a class="sc-button bt-action" href="{{ path('chill_main_export_new', { 'alias': export_alias } ) }}">
{{ 'Create an export'|trans }}
</a>
</p>
<p>
<a class="sc-button bt-action" href="{{ path('chill_main_export_new', { 'alias': export_alias } ) }}">
{{ 'Create an export'|trans }}
</a>
</p>
</div>
{% endfor %}
</div>
{% endfor %}
{% if grouped_exports|keys|length > 1 %}
<h2>{{ 'Ungrouped exports'|trans }}</h2>
{% endif %}
<div class="export-list">
{% for export_alias,export in grouped_exports['_'] %}
<div class="export-list__element">
<h2>{{ export.title|trans }}</h2>
<p>{{ export.description|trans }}</p>
<p>
<a class="sc-button bt-action" href="{{ path('chill_main_export_new', { 'alias': export_alias } ) }}">
{{ 'Create an export'|trans }}
</a>
</p>
</div>
{% endfor %}
</div>
</div>
{% endfor %}
</div>
</div>
{% endblock %}