mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-01-20 09:09:33 +00:00
Added possibility to just show all information contained in a barcode
This commit is contained in:
parent
f78532ae8a
commit
e5d91dc8fc
7 changed files with 88 additions and 5 deletions
|
|
@ -77,13 +77,21 @@ class ScanController extends AbstractController
|
|||
$mode = $form['mode']->getData();
|
||||
}
|
||||
|
||||
$infoModeData = null;
|
||||
|
||||
if ($input !== null) {
|
||||
try {
|
||||
$scan_result = $this->barcodeNormalizer->scanBarcodeContent($input, $mode ?? null);
|
||||
try {
|
||||
return $this->redirect($this->barcodeParser->getRedirectURL($scan_result));
|
||||
} catch (EntityNotFoundException) {
|
||||
$this->addFlash('success', 'scan.qr_not_found');
|
||||
//Perform a redirect if the info mode is not enabled
|
||||
if (!$form['info_mode']->getData()) {
|
||||
try {
|
||||
return $this->redirect($this->barcodeParser->getRedirectURL($scan_result));
|
||||
} catch (EntityNotFoundException) {
|
||||
$this->addFlash('success', 'scan.qr_not_found');
|
||||
}
|
||||
} else { //Otherwise retrieve infoModeData
|
||||
$infoModeData = $scan_result->getDecodedForInfoMode();
|
||||
|
||||
}
|
||||
} catch (InvalidArgumentException) {
|
||||
$this->addFlash('error', 'scan.format_unknown');
|
||||
|
|
@ -92,6 +100,7 @@ class ScanController extends AbstractController
|
|||
|
||||
return $this->render('label_system/scanner/scanner.html.twig', [
|
||||
'form' => $form,
|
||||
'infoModeData' => $infoModeData,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ namespace App\Form\LabelSystem;
|
|||
|
||||
use App\Services\LabelSystem\BarcodeScanner\BarcodeSourceType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\EnumType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
|
|
@ -55,6 +56,8 @@ class ScanDialogType extends AbstractType
|
|||
{
|
||||
$builder->add('input', TextType::class, [
|
||||
'label' => 'scan_dialog.input',
|
||||
//Do not trim the input, otherwise this damages Format06 barcodes which end with non-printable characters
|
||||
'trim' => false,
|
||||
'attr' => [
|
||||
'autofocus' => true,
|
||||
'id' => 'scan_dialog_input',
|
||||
|
|
@ -74,7 +77,11 @@ class ScanDialogType extends AbstractType
|
|||
BarcodeSourceType::USER_DEFINED => 'scan_dialog.mode.user',
|
||||
BarcodeSourceType::EIGP114 => 'scan_dialog.mode.eigp'
|
||||
},
|
||||
]);
|
||||
|
||||
$builder->add('info_mode', CheckboxType::class, [
|
||||
'label' => 'scan_dialog.info_mode',
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
$builder->add('submit', SubmitType::class, [
|
||||
|
|
|
|||
|
|
@ -25,5 +25,12 @@ namespace App\Services\LabelSystem\BarcodeScanner;
|
|||
|
||||
interface BarcodeScanResultInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns all data that was decoded from the barcode in a format, that can be shown in a table to the user.
|
||||
* The return values of this function are not meant to be parsed by code again, but should just give a information
|
||||
* to the user.
|
||||
* The keys of the returned array are the first column of the table and the values are the second column.
|
||||
* @return array<string, string|int|float|null>
|
||||
*/
|
||||
public function getDecodedForInfoMode(): array;
|
||||
}
|
||||
|
|
@ -308,4 +308,25 @@ class EIGP114BarcodeScanResult implements BarcodeScanResultInterface
|
|||
|
||||
return new self($results);
|
||||
}
|
||||
|
||||
public function getDecodedForInfoMode(): array
|
||||
{
|
||||
$tmp = [
|
||||
'Barcode type' => 'EIGP114',
|
||||
'Guessed vendor from barcode' => $this->guessBarcodeVendor() ?? 'Unknown',
|
||||
];
|
||||
|
||||
//Iterate over all fields of this object and add them to the array if they are not null
|
||||
foreach($this as $key => $value) {
|
||||
//Skip data key
|
||||
if ($key === 'data') {
|
||||
continue;
|
||||
}
|
||||
if($value !== null) {
|
||||
$tmp[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
}
|
||||
|
|
@ -37,4 +37,13 @@ class LocalBarcodeScanResult implements BarcodeScanResultInterface
|
|||
public readonly BarcodeSourceType $source_type,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getDecodedForInfoMode(): array
|
||||
{
|
||||
return [
|
||||
'Barcode type' => $this->source_type->name,
|
||||
'Target type' => $this->target_type->name,
|
||||
'Target ID' => $this->target_id,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -23,4 +23,22 @@
|
|||
|
||||
{{ form_end(form) }}
|
||||
|
||||
|
||||
{% if infoModeData %}
|
||||
<hr>
|
||||
<h4>{% trans %}label_scanner.decoded_info.title{% endtrans %}</h4>
|
||||
|
||||
<table class="table table-striped table-hover table-bordered table-sm">
|
||||
<tbody>
|
||||
{% for key, value in infoModeData %}
|
||||
<tr>
|
||||
<td>{{ key }}</td>
|
||||
<td><code>{{ value }}</code></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
|||
|
|
@ -12281,5 +12281,17 @@ Please note, that you can not impersonate a disabled user. If you try you will g
|
|||
<target>EIGP 114 barcode (e.g. the datamatrix codes on digikey and mouser orders)</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="QSMS_Bd" name="scan_dialog.info_mode">
|
||||
<segment>
|
||||
<source>scan_dialog.info_mode</source>
|
||||
<target>Info mode (Decode barcode and show its contents, but do not redirect to part)</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="k5Gvkgp" name="label_scanner.decoded_info.title">
|
||||
<segment>
|
||||
<source>label_scanner.decoded_info.title</source>
|
||||
<target>Decoded information</target>
|
||||
</segment>
|
||||
</unit>
|
||||
</file>
|
||||
</xliff>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue