Allow to export all attachment_types via the new element dialog.

This commit is contained in:
Jan Böhmer 2019-04-11 19:09:22 +02:00
parent 70c12e47a2
commit a46bcd229b
2 changed files with 75 additions and 2 deletions

View file

@ -33,6 +33,7 @@ namespace App\Controller;
use App\Entity\AttachmentType; use App\Entity\AttachmentType;
use App\Entity\NamedDBElement;
use App\Entity\StructuralDBElement; use App\Entity\StructuralDBElement;
use App\Form\BaseEntityAdminForm; use App\Form\BaseEntityAdminForm;
use App\Form\ExportType; use App\Form\ExportType;
@ -73,6 +74,7 @@ class AttachmentTypeController extends AbstractController
/** /**
* @Route("/new", name="attachment_type_new") * @Route("/new", name="attachment_type_new")
* @Route("/")
* *
* @return \Symfony\Component\HttpFoundation\Response * @return \Symfony\Component\HttpFoundation\Response
*/ */
@ -126,7 +128,7 @@ class AttachmentTypeController extends AbstractController
} }
/** /**
* @Route("/export") * @Route("/export", name="attachment_type_export_all")
* @param Request $request * @param Request $request
* @param SerializerInterface $serializer * @param SerializerInterface $serializer
* @param EntityManagerInterface $em * @param EntityManagerInterface $em
@ -198,7 +200,22 @@ class AttachmentTypeController extends AbstractController
//If view option is not specified, then download the file. //If view option is not specified, then download the file.
if (!$request->get('view')) { if (!$request->get('view')) {
$filename = "export_" . $entity->getName() . "_" . $level . "." . $format; if ($entity instanceof NamedDBElement) {
$entity_name = $entity->getName();
} elseif (is_array($entity)) {
if (empty($entity)) {
throw new \InvalidArgumentException('$entity must not be empty!');
}
//Use the class name of the first element for the filename
$reflection = new \ReflectionClass($entity[0]);
$entity_name = $reflection->getShortName();
} else {
throw new \InvalidArgumentException('$entity type is not supported!');
}
$filename = "export_" . $entity_name . "_" . $level . "." . $format;
// Create the disposition of the file // Create the disposition of the file
$disposition = $response->headers->makeDisposition( $disposition = $response->headers->makeDisposition(

View file

@ -43,6 +43,8 @@
<li class="nav-item"><a data-toggle="tab" class="link-anchor nav-link" href="#info">{% trans %}infos.label{% endtrans %}</a></li> <li class="nav-item"><a data-toggle="tab" class="link-anchor nav-link" href="#info">{% trans %}infos.label{% endtrans %}</a></li>
{% if entity.id %} {% if entity.id %}
<li class="nav-item"><a data-toggle="tab" class="link-anchor nav-link" href="#export">{% trans %}export.label{% endtrans %}</a> </li> <li class="nav-item"><a data-toggle="tab" class="link-anchor nav-link" href="#export">{% trans %}export.label{% endtrans %}</a> </li>
{% else %}
<li class="nav-item"><a data-toggle="tab" class="link-anchor nav-link" href="#import_export">{% trans %}import_export.label{% endtrans %}</a> </li>
{% endif %} {% endif %}
</ul> </ul>
@ -143,6 +145,60 @@
</div> </div>
</form> </form>
</div> </div>
{% else %} {# For new element we have a combined import/export tab #}
<div id="import_export" class="tab-pane fade">
<hr>
<fieldset>
<legend>{% trans %}export_all.label{% endtrans %}</legend>
<form class="form-horizontal" data-no-ajax method="post" action="{{ path('attachment_type_export_all') }}">
<div class="form-row">
<label class="col-form-label col-md-2">{% trans %}export.format{% endtrans %}</label>
<div class="col">
<select class="form-control" name="format">
<option value="json">JSON</option>
<option value="xml">XML</option>
<option value="csv">CSV</option>
<option value="yaml">YAML</option>
</select>
</div>
</div>
<div class="form-row mt-2">
<label class="col-form-label col-md-2">{% trans %}export.level{% endtrans %}</label>
<div class="col">
<select class="form-control" name="level">
<option value="simple">{% trans %}export.level.simple{% endtrans %}</option>
<option value="extended" selected>{% trans %}export.level.extended{% endtrans %}</option>
<option value="full">{% trans %}export.level.full{% endtrans %}</option>
</select>
</div>
</div>
<div class="form-row mt-2">
<div class="offset-2 col">
<div class="form-check abc-checkbox">
<input class="form-check-input" name="include_children" id="include_children" type="checkbox" checked>
<label class="form-check-label" for="include_children">
{% trans %}export.include_children{% endtrans %}
</label>
</div>
</div>
</div>
<div class="form-row mt-2">
<div class="offset-2 col">
<button type="submit" class="btn btn-primary">{% trans %}export.btn{% endtrans %}</button>
</div>
</div>
</form>
</fieldset>
</div>
{% endif %} {% endif %}
</div> </div>