diff --git a/static/index.html b/static/index.html index 5fe3371..53a6399 100644 --- a/static/index.html +++ b/static/index.html @@ -2621,16 +2621,19 @@ try { const ocrData = await ocrImageClient(file); if (ocrData && ocrData.machine_id) { + document.getElementById('scanMachineId').value = ocrData.machine_id; if (ocrEl) ocrEl.innerHTML = `✅ Machine ID: ${esc(ocrData.machine_id)}` + (ocrData.confidence === 'low' ? ' ⚠️ Low confidence' : ''); + // Auto-lookup like barcode scan — route to confirm card or new asset form + handleBarcode(ocrData.machine_id); } else { - if (ocrEl) ocrEl.innerHTML = '❌ No machine ID detected. '; + if (ocrEl) ocrEl.innerHTML = '❌ No machine ID detected. '; } } catch (ocrErr) { if (ocrEl) ocrEl.textContent = '❌ OCR failed: ' + ocrErr.message; } - // Extract GPS from EXIF + // Extract GPS from EXIF — fall back to device GPS if stripped const gpsEl = document.getElementById('scanGpsResult'); try { const gps = await extractGpsFromPhoto(file); @@ -2638,13 +2641,34 @@ pickedPhotoGps = gps; if (gpsEl) { gpsEl.style.display = 'block'; - gpsEl.innerHTML = `📍 GPS: ${gps.lat.toFixed(6)}, ${gps.lng.toFixed(6)}`; + gpsEl.innerHTML = `📍 GPS: ${gps.lat.toFixed(6)}, ${gps.lng.toFixed(6)} (from photo)`; } } else { + // EXIF GPS stripped by browser — try device GPS if (gpsEl) { + gpsEl.innerHTML = '📍 No GPS in photo — trying device location...'; gpsEl.style.display = 'block'; - gpsEl.innerHTML = '📍 No GPS data in photo'; } + navigator.geolocation.getCurrentPosition( + pos => { + const lat = pos.coords.latitude; + const lng = pos.coords.longitude; + const acc = pos.coords.accuracy; + pickedPhotoGps = { lat, lng, accuracy: acc }; + AppState.gpsLat = lat; + AppState.gpsLng = lng; + AppState.gpsAcc = acc; + if (gpsEl) { + gpsEl.innerHTML = `📍 GPS: ${lat.toFixed(6)}, ${lng.toFixed(6)} (from device)`; + } + }, + err => { + if (gpsEl) { + gpsEl.innerHTML = `📍 No GPS — ${err.message}. Enter manually after creating.`; + } + }, + { enableHighAccuracy: true, timeout: 10000 } + ); } } catch (gpsErr) { if (gpsEl) { @@ -2667,6 +2691,9 @@ if (pickedPhotoGps) { payload.latitude = pickedPhotoGps.lat; payload.longitude = pickedPhotoGps.lng; + } else if (AppState.gpsLat) { + payload.latitude = AppState.gpsLat; + payload.longitude = AppState.gpsLng; } api('/api/connect-label', {