mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-01-20 17:19:34 +00:00
fix scanning of part-db barcodes to redirect to storage location or part lots. made scan result messages conditional for parts or other non-part barcodes
This commit is contained in:
parent
052780c865
commit
3b1ea8275f
3 changed files with 90 additions and 52 deletions
|
|
@ -321,36 +321,44 @@ class ScanController extends AbstractController
|
|||
|
||||
$decoded = $scan->getDecodedForInfoMode();
|
||||
|
||||
// Resolve part (or null)
|
||||
$part = $this->barcodeParser->resolvePartOrNull($scan);
|
||||
|
||||
// Determine if this barcode resolves to *anything* (part, lot->part, storelocation)
|
||||
$redirectUrl = null;
|
||||
if ($part !== null) {
|
||||
// Redirector knows how to route parts, lots, and storelocations.
|
||||
$targetFound = false;
|
||||
|
||||
try {
|
||||
$redirectUrl = $this->barcodeParser->getRedirectURL($scan);
|
||||
$targetFound = true;
|
||||
} catch (EntityNotFoundException) {
|
||||
$targetFound = false;
|
||||
}
|
||||
|
||||
// Build template vars
|
||||
// Only resolve Part for part-like targets. Storelocation scans should remain null here.
|
||||
$part = null;
|
||||
$partName = null;
|
||||
$partUrl = null;
|
||||
$locations = [];
|
||||
$createUrl = null;
|
||||
|
||||
if ($part !== null) {
|
||||
$partName = $part->getName();
|
||||
$partUrl = $this->generateUrl('app_part_show', ['id' => $part->getID()]);
|
||||
$locations = $this->buildLocationsForPart($part);
|
||||
} else {
|
||||
if ($targetFound) {
|
||||
$part = $this->barcodeParser->resolvePartOrNull($scan);
|
||||
|
||||
if ($part instanceof Part) {
|
||||
$partName = $part->getName();
|
||||
$partUrl = $this->generateUrl('app_part_show', ['id' => $part->getID()]);
|
||||
$locations = $this->buildLocationsForPart($part);
|
||||
}
|
||||
}
|
||||
|
||||
// Create link only when NOT found (vendor codes)
|
||||
$createUrl = null;
|
||||
if (!$targetFound) {
|
||||
$createUrl = $this->buildCreateUrlForScanResult($scan, $locale);
|
||||
}
|
||||
|
||||
// Render one fragment that shows:
|
||||
// - decoded info (optional if you kept it)
|
||||
// - part info + locations when found
|
||||
// - create link when not found
|
||||
// Render fragment (use openUrl for universal "Open" link)
|
||||
$html = $this->renderView('label_system/scanner/augmented_result.html.twig', [
|
||||
'decoded' => $decoded,
|
||||
'found' => ($part !== null),
|
||||
'found' => $targetFound,
|
||||
'openUrl' => $redirectUrl,
|
||||
'partName' => $partName,
|
||||
'partUrl' => $partUrl,
|
||||
'locations' => $locations,
|
||||
|
|
@ -359,7 +367,7 @@ class ScanController extends AbstractController
|
|||
|
||||
return new JsonResponse([
|
||||
'ok' => true,
|
||||
'found' => ($part !== null),
|
||||
'found' => $targetFound,
|
||||
'redirectUrl' => $redirectUrl, // client redirects only when infoMode=false
|
||||
'html' => $html,
|
||||
'infoMode' => $infoMode,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,14 @@
|
|||
<hr>
|
||||
|
||||
<div class="d-flex align-items-center mb-2">
|
||||
<h4 class="mb-0 me-2">{% trans %}label_scanner.part_info.title{% endtrans %}</h4>
|
||||
<h4 class="mb-0 me-2">
|
||||
{% if found and partName %}
|
||||
{% trans %}label_scanner.part_info.title{% endtrans %}
|
||||
{% else %}
|
||||
{% trans %}label_scanner.scan_result.title{% endtrans %}
|
||||
{% endif %}
|
||||
</h4>
|
||||
|
||||
|
||||
{% if createUrl %}
|
||||
<a class="btn btn-primary ms-2 mb-2"
|
||||
|
|
@ -15,42 +22,53 @@
|
|||
</div>
|
||||
|
||||
{% if found %}
|
||||
<div class="alert alert-success mb-2">
|
||||
{{ partName }}
|
||||
{% if partUrl %}
|
||||
— <a href="{{ partUrl }}" target="_blank">{% trans %}open{% endtrans %}</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="alert alert-success mb-2 d-flex align-items-center justify-content-between">
|
||||
<div>
|
||||
{% if partName %}
|
||||
{{ partName }}
|
||||
{% else %}
|
||||
{% trans %}label_scanner.target_found{% endtrans %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if locations is not empty %}
|
||||
<table class="table table-sm mb-2 w-auto">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">{% trans %}part_lots.storage_location{% endtrans %}</th>
|
||||
<th scope="col" class="text-end" style="width: 6rem;">
|
||||
{% trans %}part_lots.amount{% endtrans %}
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for loc in locations %}
|
||||
{% if openUrl %}
|
||||
<a href="{{ openUrl }}" target="_blank" class="btn btn-sm btn-outline-success">
|
||||
{% trans %}open{% endtrans %}
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if partName %}
|
||||
{% if locations is not empty %}
|
||||
<table class="table table-sm mb-2 w-auto">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>
|
||||
<ul class="structural_link d-inline">
|
||||
{% for crumb in loc.breadcrumb %}
|
||||
<li><a href="{{ crumb.url }}" target="_blank">{{ crumb.name }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</td>
|
||||
<td class="text-end" style="width: 6rem;">
|
||||
{% if loc.qty is not null %}<strong>{{ loc.qty }}</strong>{% else %}<span class="text-muted">—</span>{% endif %}
|
||||
</td>
|
||||
<th scope="col">{% trans %}part_lots.storage_location{% endtrans %}</th>
|
||||
<th scope="col" class="text-end" style="width: 6rem;">
|
||||
{% trans %}part_lots.amount{% endtrans %}
|
||||
</th>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<div class="text-muted mb-2">{% trans %}label_scanner.no_locations{% endtrans %}</div>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for loc in locations %}
|
||||
<tr>
|
||||
<td>
|
||||
<ul class="structural_link d-inline">
|
||||
{% for crumb in loc.breadcrumb %}
|
||||
<li><a href="{{ crumb.url }}" target="_blank">{{ crumb.name }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</td>
|
||||
<td class="text-end" style="width: 6rem;">
|
||||
{% if loc.qty is not null %}<strong>{{ loc.qty }}</strong>{% else %}<span class="text-muted">—</span>{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<div class="text-muted mb-2">{% trans %}label_scanner.no_locations{% endtrans %}</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<div class="alert alert-warning mb-2">
|
||||
|
|
|
|||
|
|
@ -12051,6 +12051,18 @@ Please note, that you can not impersonate a disabled user. If you try you will g
|
|||
<target>Part information</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="k9lvxgf" name="label_scanner.target_found">
|
||||
<segment state="translated">
|
||||
<source>label_scanner.target_found</source>
|
||||
<target>Item Found</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="kd6G2gf" name="label_scanner.scan_result.title">
|
||||
<segment state="translated">
|
||||
<source>label_scanner.scan_result.title</source>
|
||||
<target>Scan result</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="kG2vk5p" name="label_scanner.no_locations">
|
||||
<segment state="translated">
|
||||
<source>label_scanner.no_locations</source>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue