Scan/OCR improvements: Scan New Asset button, barcode scanner fix, serial number OCR search
- Add 'Scan New Asset' button after scanning/OCR'ing an existing asset in both barcode and OCR modes (with resetBarcodeScanner/resetOcrScanner) - Show scan results in-place instead of navigating away from Find Asset tab - Fix barcode scanner: remove TRY_HARDER hint (too slow on mobile), reduce from 13 formats to 7 focused 1D formats, add ZXing library load check - Extend camera fail timeout from 5s to 10s for slow mobile browsers - Show matched_assets from OCR serial number cross-reference even when no machine_id pattern is detected (previously showed 'No machine ID') - Display serial/ID DB matches alongside machine_id results when both exist - Add null-safety to all new reset functions
This commit is contained in:
+34
-8
@@ -2974,6 +2974,25 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showFallbackCameraError(extraMsg) {
|
||||||
|
// Show just the manual search fallback without re-creating placeholder
|
||||||
|
const fallback = document.getElementById('manualSearchFallback');
|
||||||
|
if (fallback) {
|
||||||
|
fallback.style.display = 'block';
|
||||||
|
fallback.innerHTML = `
|
||||||
|
<div style="background:var(--red-bg);color:var(--red);padding:10px;border-radius:8px;margin-bottom:10px;font-size:13px;">
|
||||||
|
<strong>Camera unavailable</strong><br>
|
||||||
|
${extraMsg}
|
||||||
|
</div>
|
||||||
|
<div style="font-size:12px;color:var(--text2);margin-bottom:6px;">Enter ID manually:</div>
|
||||||
|
<input type="text" id="manualBarcodeInput" class="input-field" placeholder="Connect ID or barcode..." onkeypress="if(event.key==='Enter')handleManualBarcode()">
|
||||||
|
<button class="btn btn-primary btn-sm" onclick="handleManualBarcode()" style="margin-top:6px;width:100%;">Search</button>
|
||||||
|
<button class="btn btn-outline btn-sm" onclick="startScanning()" style="margin-top:6px;width:100%;">Try camera again</button>
|
||||||
|
`;
|
||||||
|
setTimeout(() => document.getElementById('manualBarcodeInput')?.focus(), 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function stopScanning() {
|
function stopScanning() {
|
||||||
scanningActive = false;
|
scanningActive = false;
|
||||||
if (codeReader) {
|
if (codeReader) {
|
||||||
@@ -3085,9 +3104,10 @@
|
|||||||
|
|
||||||
function resetBarcodeScanner() {
|
function resetBarcodeScanner() {
|
||||||
// Reset the scan result UI and restart barcode scanner
|
// Reset the scan result UI and restart barcode scanner
|
||||||
document.getElementById('scanResult').style.display = 'none';
|
const sr = document.getElementById('scanResult');
|
||||||
document.getElementById('scanResult').innerHTML = '';
|
if (sr) { sr.style.display = 'none'; sr.innerHTML = ''; }
|
||||||
document.getElementById('checkinCard').style.display = 'none';
|
const cc = document.getElementById('checkinCard');
|
||||||
|
if (cc) cc.style.display = 'none';
|
||||||
setScanStatus('Ready — scan another barcode', 'success');
|
setScanStatus('Ready — scan another barcode', 'success');
|
||||||
stopScanning();
|
stopScanning();
|
||||||
// Re-show the camera placeholder
|
// Re-show the camera placeholder
|
||||||
@@ -3096,7 +3116,8 @@
|
|||||||
ph.style.display = 'block';
|
ph.style.display = 'block';
|
||||||
ph.innerHTML = '<span class="cam-icon">' + gi('📷') + '</span><div class="cam-hint">Tap to start camera</div>';
|
ph.innerHTML = '<span class="cam-icon">' + gi('📷') + '</span><div class="cam-hint">Tap to start camera</div>';
|
||||||
}
|
}
|
||||||
document.getElementById('cameraVideo').style.display = 'none';
|
const cv = document.getElementById('cameraVideo');
|
||||||
|
if (cv) cv.style.display = 'none';
|
||||||
const fallback = document.getElementById('manualSearchFallback');
|
const fallback = document.getElementById('manualSearchFallback');
|
||||||
if (fallback) fallback.style.display = 'none';
|
if (fallback) fallback.style.display = 'none';
|
||||||
scanningActive = false;
|
scanningActive = false;
|
||||||
@@ -3108,10 +3129,12 @@
|
|||||||
function resetOcrScanner() {
|
function resetOcrScanner() {
|
||||||
// Reset the OCR result UI and restart OCR camera
|
// Reset the OCR result UI and restart OCR camera
|
||||||
stopOcrCamera();
|
stopOcrCamera();
|
||||||
document.getElementById('ocrResult').style.display = 'none';
|
const or = document.getElementById('ocrResult');
|
||||||
document.getElementById('ocrResult').innerHTML = '';
|
if (or) { or.style.display = 'none'; or.innerHTML = ''; }
|
||||||
document.getElementById('ocrGpsBadge').style.display = 'none';
|
const og = document.getElementById('ocrGpsBadge');
|
||||||
document.getElementById('ocrCameraArea').style.display = 'block';
|
if (og) og.style.display = 'none';
|
||||||
|
const oca = document.getElementById('ocrCameraArea');
|
||||||
|
if (oca) oca.style.display = 'block';
|
||||||
setOcrStatus('Point camera at the machine sticker and tap capture', 'success');
|
setOcrStatus('Point camera at the machine sticker and tap capture', 'success');
|
||||||
const ph = document.getElementById('ocrPlaceholder');
|
const ph = document.getElementById('ocrPlaceholder');
|
||||||
if (ph) {
|
if (ph) {
|
||||||
@@ -3161,6 +3184,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<div style="font-size:12px;color:var(--text3);margin-top:8px;">
|
<div style="font-size:12px;color:var(--text3);margin-top:8px;">
|
||||||
Try OCR scanning the sticker, or search in the Assets tab.
|
Try OCR scanning the sticker, or search in the Assets tab.
|
||||||
|
</div>
|
||||||
|
<div style="margin-top:10px;">
|
||||||
|
<button class="btn btn-primary btn-sm" onclick="resetBarcodeScanner()" style="width:100%;">Scan New</button>
|
||||||
</div>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user