diff --git a/assets.db.bak.20260531_110825 b/assets.db.bak.20260531_110825 new file mode 100644 index 0000000..77f7527 Binary files /dev/null and b/assets.db.bak.20260531_110825 differ diff --git a/assets.db.bak.20260531_132122 b/assets.db.bak.20260531_132122 new file mode 100644 index 0000000..87cccc9 Binary files /dev/null and b/assets.db.bak.20260531_132122 differ diff --git a/restart_server.sh b/restart_server.sh index fa69d07..ae29047 100755 --- a/restart_server.sh +++ b/restart_server.sh @@ -1,16 +1,10 @@ #!/bin/bash -# Restart canteen-asset-tracker server cd /home/oplabs/projects/canteen-asset-tracker - -# Kill existing server -pkill -f "python.*server.py" 2>/dev/null || true +pkill -f "uvicorn.*server:app.*8901" 2>/dev/null || true sleep 1 - -# Activate venv and start -source .venv/bin/activate -nohup python server.py > /tmp/canteen-server.log 2>&1 & -echo "Server PID: $!" -sleep 3 - -# Check health -curl -s http://localhost:8901/health 2>/dev/null || curl -s http://localhost:8900/health 2>/dev/null || echo "Health check failed" +python -m uvicorn server:app --host 0.0.0.0 --port 8901 \ + --ssl-keyfile key.pem --ssl-certfile cert.pem --log-level info \ + > /tmp/canteen-server.log 2>&1 & +echo "PID=$!" +sleep 2 +curl -sk https://localhost:8901/health 2>/dev/null diff --git a/static/index.html b/static/index.html index eeaa58d..b5c4ebf 100644 --- a/static/index.html +++ b/static/index.html @@ -2438,9 +2438,13 @@ el.classList.toggle('active', el.dataset.tab === tabId); }); - // Tab lifecycle hooks - if (tabId === 'tabAddAsset') startScanning(); - else stopScanning(); + // Tab lifecycle hooks — start the appropriate scanner + if (tabId === 'tabAddAsset') { + if (addAssetMode === 'ocr') startOcrCamera(); + else startScanning(); + } else { + stopScanning(); + } if (tabId === 'tabAssets') { loadAssets(); } @@ -2553,7 +2557,7 @@ // ═══════════════════════════════════════════════════════════════════════ // ADD ASSET TAB — 3 Modes: Barcode, OCR, Manual // ═══════════════════════════════════════════════════════════════════════ - let addAssetMode = 'barcode'; + let addAssetMode = 'ocr'; let stream = null; let ocrStream = null; let codeReader = null; @@ -2582,6 +2586,8 @@ if (mode === 'barcode') { startScanning(); + } else if (mode === 'ocr') { + startOcrCamera(); } } @@ -3133,7 +3139,8 @@
${esc(data.machine_id)}${methodBadge}
${confLabel}
${data.raw_text ? `
OCR text: ${esc(data.raw_text)}
` : ''} -
🔍 Searching for asset...
`; +
🔍 Searching for asset...
+
`; setOcrStatus('Machine ID found! Searching...', 'working'); // Auto-search the asset @@ -3142,7 +3149,8 @@ el.innerHTML = `
No machine ID detected
Try again with better lighting and focus on the sticker.
- ${data.raw_text ? `
OCR text: ${esc(data.raw_text)}
` : ''}`; + ${data.raw_text ? `
OCR text: ${esc(data.raw_text)}
` : ''} +
`; setOcrStatus('No machine ID found — try again', 'error'); } @@ -3215,15 +3223,17 @@ el.innerHTML += `
${gi("📍")} GPS saved to asset
`; AppState.ocrGpsSaved = false; } - el.innerHTML += `
- + el.innerHTML += `
+ +
`; } catch (e) { if (e.message === 'Asset not found' || e.message.includes('404')) { const el = document.getElementById('ocrResult'); el.innerHTML = `
${esc(machineId)} ❌
-
Machine ID not found in database
`; +
Machine ID not found in database
+
`; setOcrStatus('Asset not found — try scanning the barcode instead', 'error'); } else { setOcrStatus('Lookup error: ' + e.message, 'error'); @@ -3262,6 +3272,18 @@ }; } + // ── Retake OCR photo after capture ────────────────────────────────── + function retakeOcr() { + // Reset the OCR UI for a new capture + document.getElementById('ocrResult').style.display = 'none'; + document.getElementById('ocrResult').innerHTML = ''; + document.getElementById('ocrGpsBadge').style.display = 'none'; + setOcrStatus('', ''); + const camArea = document.getElementById('ocrCameraArea'); + if (camArea) camArea.style.display = ''; + startOcrCamera(); + } + async function captureOcr() { const video = document.getElementById('ocrVideo'); if (!video || !ocrStream) return; @@ -3275,6 +3297,10 @@ // Stop camera after capturing photo stopOcrCamera(); + // Hide the camera viewport entirely — don't show placeholder after capture + const camArea = document.getElementById('ocrCameraArea'); + if (camArea) camArea.style.display = 'none'; + setOcrStatus('Processing OCR...', 'working'); document.getElementById('ocrResult').style.display = 'none';