first commit

This commit is contained in:
2026-01-18 12:23:37 +01:00
commit ae792f4996
124 changed files with 19497 additions and 0 deletions

View File

@@ -0,0 +1,309 @@
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Scanner QR Code - HTT</title>
<script src="https://unpkg.com/html5-qrcode@2.3.8/html5-qrcode.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
background-color: #1a1a2e;
color: white;
min-height: 100vh;
display: flex;
flex-direction: column;
}
.header {
background-color: #16213e;
padding: 16px;
text-align: center;
box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}
.header h1 {
font-size: 1.25rem;
font-weight: 600;
}
.scanner-container {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 20px;
}
#reader {
width: 100%;
max-width: 400px;
border-radius: 12px;
overflow: hidden;
}
#reader video {
border-radius: 12px;
}
.instructions {
text-align: center;
margin-top: 20px;
color: #a0a0a0;
font-size: 0.9rem;
}
.status {
margin-top: 16px;
padding: 12px 24px;
border-radius: 8px;
font-weight: 500;
text-align: center;
}
.status.scanning {
background-color: #0f3460;
color: #4da6ff;
}
.status.success {
background-color: #1e5128;
color: #4ade80;
}
.status.error {
background-color: #5c1a1a;
color: #f87171;
}
.btn {
margin-top: 20px;
padding: 14px 28px;
background-color: #3b82f6;
color: white;
border: none;
border-radius: 8px;
font-size: 1rem;
font-weight: 500;
cursor: pointer;
transition: background-color 0.2s;
}
.btn:hover {
background-color: #2563eb;
}
.btn:disabled {
background-color: #4b5563;
cursor: not-allowed;
}
.camera-switch {
margin-top: 12px;
padding: 10px 20px;
background-color: transparent;
color: #a0a0a0;
border: 1px solid #4b5563;
border-radius: 8px;
font-size: 0.875rem;
cursor: pointer;
}
.camera-switch:hover {
border-color: #6b7280;
color: white;
}
.logo {
font-size: 1.5rem;
font-weight: 700;
color: #3b82f6;
margin-bottom: 4px;
}
.permission-prompt {
text-align: center;
padding: 40px 20px;
}
.permission-prompt p {
margin-bottom: 20px;
color: #a0a0a0;
}
#qr-shaded-region {
border-color: #3b82f6 !important;
}
</style>
</head>
<body>
<div class="header">
<div class="logo">HTT Locator</div>
<h1>Scanner Articoli</h1>
</div>
<div class="scanner-container">
<div id="reader"></div>
<div id="permission-prompt" class="permission-prompt" style="display: none;">
<p>Per scansionare i QR code, consenti l'accesso alla fotocamera.</p>
<button class="btn" onclick="startScanner()">Attiva Fotocamera</button>
</div>
<div id="status" class="status scanning" style="display: none;">
Inquadra il QR Code...
</div>
<p class="instructions" id="instructions">
Posiziona il QR code dell'articolo all'interno del riquadro
</p>
<button id="camera-switch" class="camera-switch" style="display: none;" onclick="switchCamera()">
Cambia fotocamera
</button>
</div>
<script>
let html5QrCode = null;
let currentCamera = 'environment'; // 'environment' = posteriore, 'user' = frontale
let cameras = [];
async function initScanner() {
try {
// Verifica supporto
if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
showStatus('Il tuo browser non supporta l\'accesso alla fotocamera', 'error');
return;
}
// Ottieni lista fotocamere
cameras = await Html5Qrcode.getCameras();
if (cameras && cameras.length > 0) {
startScanner();
if (cameras.length > 1) {
document.getElementById('camera-switch').style.display = 'block';
}
} else {
document.getElementById('permission-prompt').style.display = 'block';
document.getElementById('instructions').style.display = 'none';
}
} catch (err) {
console.error('Errore inizializzazione:', err);
document.getElementById('permission-prompt').style.display = 'block';
document.getElementById('instructions').style.display = 'none';
}
}
async function startScanner() {
document.getElementById('permission-prompt').style.display = 'none';
document.getElementById('instructions').style.display = 'block';
showStatus('Inquadra il QR Code...', 'scanning');
if (html5QrCode) {
try {
await html5QrCode.stop();
} catch (e) {}
}
html5QrCode = new Html5Qrcode("reader");
const config = {
fps: 10,
qrbox: { width: 250, height: 250 },
aspectRatio: 1.0
};
try {
await html5QrCode.start(
{ facingMode: currentCamera },
config,
onScanSuccess,
onScanFailure
);
} catch (err) {
console.error('Errore avvio scanner:', err);
showStatus('Impossibile accedere alla fotocamera. Verifica i permessi.', 'error');
}
}
function onScanSuccess(decodedText, decodedResult) {
// Formato nuovo: id-timestamp (es: 42-1737235200)
const idTimestampRegex = /^\d+-\d+$/;
// Formato vecchio: UUID
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
if (idTimestampRegex.test(decodedText) || uuidRegex.test(decodedText)) {
showStatus('QR Code riconosciuto! Reindirizzamento...', 'success');
// Vibrazione feedback (se supportata)
if (navigator.vibrate) {
navigator.vibrate(200);
}
// Stop scanner
if (html5QrCode) {
html5QrCode.stop().catch(e => console.log(e));
}
// Redirect alla pagina articolo
setTimeout(() => {
window.location.href = '/articolo/' + decodedText;
}, 500);
} else {
// Potrebbe essere un vecchio QR con URL completo
if (decodedText.includes('/articolo/')) {
const match = decodedText.match(/\/articolo\/([^\s\/]+)/i);
if (match && match[1]) {
showStatus('QR Code riconosciuto! Reindirizzamento...', 'success');
if (navigator.vibrate) {
navigator.vibrate(200);
}
if (html5QrCode) {
html5QrCode.stop().catch(e => console.log(e));
}
setTimeout(() => {
window.location.href = '/articolo/' + match[1];
}, 500);
return;
}
}
showStatus('QR Code non valido per questo sistema', 'error');
setTimeout(() => {
showStatus('Inquadra il QR Code...', 'scanning');
}, 2000);
}
}
function onScanFailure(error) {
// Ignora errori di scansione continua (normale quando non c'è QR)
}
function showStatus(message, type) {
const status = document.getElementById('status');
status.textContent = message;
status.className = 'status ' + type;
status.style.display = 'block';
}
async function switchCamera() {
currentCamera = currentCamera === 'environment' ? 'user' : 'environment';
await startScanner();
}
// Avvia scanner al caricamento
document.addEventListener('DOMContentLoaded', initScanner);
</script>
</body>
</html>