Add export functionality to batch select and fix errors

This commit is contained in:
barisgit 2025-08-01 23:12:08 +02:00 committed by Jan Böhmer
parent facfb37383
commit 1fb137e89f
5 changed files with 10 additions and 5 deletions

View file

@ -92,7 +92,7 @@ class EntityExporter
$options = $resolver->resolve($options); $options = $resolver->resolve($options);
//Handle Excel formats by converting from CSV //Handle Excel formats by converting from CSV
if (in_array($options['format'], ['xlsx', 'xls'])) { if (in_array($options['format'], ['xlsx', 'xls'], true)) {
return $this->exportToExcel($entities, $options); return $this->exportToExcel($entities, $options);
} }

View file

@ -346,7 +346,7 @@ class EntityImporter
$this->configureOptions($resolver); $this->configureOptions($resolver);
$options = $resolver->resolve($options); $options = $resolver->resolve($options);
if (in_array($options['format'], ['xlsx', 'xls'])) { if (in_array($options['format'], ['xlsx', 'xls'], true)) {
$this->logger->info('Converting Excel file to CSV', [ $this->logger->info('Converting Excel file to CSV', [
'filename' => $file->getFilename(), 'filename' => $file->getFilename(),
'format' => $options['format'], 'format' => $options['format'],

View file

@ -30,13 +30,11 @@ use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit; use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part; use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot; use App\Entity\Parts\PartLot;
use App\Repository\PartRepository;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException; use InvalidArgumentException;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Contracts\Translation\TranslatableInterface;
use function Symfony\Component\Translation\t; use function Symfony\Component\Translation\t;
@ -100,7 +98,7 @@ implode(',', array_map(static fn (PartLot $lot) => $lot->getID(), $part->getPart
//When action starts with "export_" we have to redirect to the export controller //When action starts with "export_" we have to redirect to the export controller
$matches = []; $matches = [];
if (preg_match('/^export_(json|yaml|xml|csv)$/', $action, $matches)) { if (preg_match('/^export_(json|yaml|xml|csv|xlsx)$/', $action, $matches)) {
$ids = implode(',', array_map(static fn (Part $part) => $part->getID(), $selected_parts)); $ids = implode(',', array_map(static fn (Part $part) => $part->getID(), $selected_parts));
$level = match ($target_id) { $level = match ($target_id) {
2 => 'extended', 2 => 'extended',

View file

@ -72,6 +72,7 @@
<option {% if not is_granted('@parts.read') %}disabled{% endif %} value="export_csv" data-url="{{ path('select_export_level')}}" data-turbo="false">{% trans %}part_list.action.export_csv{% endtrans %}</option> <option {% if not is_granted('@parts.read') %}disabled{% endif %} value="export_csv" data-url="{{ path('select_export_level')}}" data-turbo="false">{% trans %}part_list.action.export_csv{% endtrans %}</option>
<option {% if not is_granted('@parts.read') %}disabled{% endif %} value="export_yaml" data-url="{{ path('select_export_level')}}" data-turbo="false">{% trans %}part_list.action.export_yaml{% endtrans %}</option> <option {% if not is_granted('@parts.read') %}disabled{% endif %} value="export_yaml" data-url="{{ path('select_export_level')}}" data-turbo="false">{% trans %}part_list.action.export_yaml{% endtrans %}</option>
<option {% if not is_granted('@parts.read') %}disabled{% endif %} value="export_xml" data-url="{{ path('select_export_level')}}" data-turbo="false">{% trans %}part_list.action.export_xml{% endtrans %}</option> <option {% if not is_granted('@parts.read') %}disabled{% endif %} value="export_xml" data-url="{{ path('select_export_level')}}" data-turbo="false">{% trans %}part_list.action.export_xml{% endtrans %}</option>
<option {% if not is_granted('@parts.read') %}disabled{% endif %} value="export_xlsx" data-url="{{ path('select_export_level')}}" data-turbo="false">{% trans %}part_list.action.export_xlsx{% endtrans %}</option>
</optgroup> </optgroup>
</select> </select>

View file

@ -10906,6 +10906,12 @@ Element 1 -&gt; Element 1.2]]></target>
<target>Export to XML</target> <target>Export to XML</target>
</segment> </segment>
</unit> </unit>
<unit id="xLSXExport" name="part_list.action.export_xlsx">
<segment state="translated">
<source>part_list.action.export_xlsx</source>
<target>Export to Excel</target>
</segment>
</unit>
<unit id="w0AgPEI" name="parts.import.title"> <unit id="w0AgPEI" name="parts.import.title">
<segment state="translated"> <segment state="translated">
<source>parts.import.title</source> <source>parts.import.title</source>