549 lines
28 KiB
HTML
549 lines
28 KiB
HTML
{% extends "base.html" %}
|
|
|
|
{% block title %}Consola de Acceso QR — Recepción & Seguridad{% endblock %}
|
|
|
|
{% block content %}
|
|
<div class="container-fluid py-3 px-lg-4">
|
|
<!-- Header de Control de Acceso -->
|
|
<div class="d-flex flex-wrap align-items-center justify-content-between gap-3 mb-4">
|
|
<div>
|
|
<div class="d-flex align-items-center gap-2">
|
|
<span class="badge bg-secondary text-white rounded-pill px-3 py-1 fw-semibold">
|
|
<i class="bi bi-qr-code-scan me-1"></i> Control de Acceso
|
|
</span>
|
|
<span class="badge bg-success-subtle text-success border border-success-subtle rounded-pill px-2 py-0">En Línea</span>
|
|
</div>
|
|
<h1 class="h3 fw-bold mt-1 mb-0">Consola de Recepción & Escáner QR</h1>
|
|
<p class="text-muted small mb-0">Identifica a los estudiantes y docentes al ingresar, valida su estado de matrícula e infórmales su aula y piso del día.</p>
|
|
</div>
|
|
|
|
<div class="d-flex align-items-center gap-3">
|
|
<div>
|
|
<label class="small text-muted fw-bold d-block">Punto de Control / Sede Física:</label>
|
|
<select class="form-select form-select-sm rounded-pill px-3 shadow-xs" id="buildingSelect">
|
|
{% for b in buildings %}
|
|
<option value="{{ b.id }}" {% if b.id == defaultBuildingId or (not defaultBuildingId and loop.first) %}selected{% endif %}>
|
|
{{ b.name }}
|
|
</option>
|
|
{% endfor %}
|
|
</select>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row g-4">
|
|
<!-- Columna Izquierda: Escáner Óptico / Pistola USB y Puerto Serial -->
|
|
<div class="col-12 col-lg-5">
|
|
<div class="card border-0 shadow-sm rounded-4 p-4 mb-4">
|
|
<div class="d-flex align-items-center justify-content-between mb-3">
|
|
<h5 class="fw-bold mb-0 text-dark d-flex align-items-center">
|
|
<i class="bi bi-upc-scan me-2 text-primary"></i>Lector Óptico de Acceso
|
|
</h5>
|
|
<span class="small text-success fw-semibold d-flex align-items-center gap-1" id="scannerFocusIndicator" title="El cursor está atrapado permanentemente en este campo para lectura USB directa">
|
|
<span class="scanner-active-dot"></span> Lector Listo
|
|
</span>
|
|
</div>
|
|
|
|
<!-- Banner Informativo de Operación -->
|
|
<div class="p-3 bg-light rounded-4 border mb-3 text-start">
|
|
<div class="d-flex align-items-start gap-2">
|
|
<i class="bi bi-shield-check text-primary fs-5 mt-1"></i>
|
|
<div>
|
|
<div class="fw-bold small text-dark">Modo Alta Velocidad USB HID / COM</div>
|
|
<div class="text-muted small" style="font-size: 0.76rem;">
|
|
El cursor se mantiene retenido permanentemente en el campo de escaneo. Dispara la pistola óptica sobre la credencial QR o DNI físico para registrar el acceso en tiempo real.
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Entrada de Lectura Óptica USB -->
|
|
<form id="manualScanForm" onsubmit="handleManualScan(event)">
|
|
<div class="input-group shadow-sm rounded-pill overflow-hidden border border-2 border-primary mb-2">
|
|
<input type="text" class="form-control rounded-start-pill ps-3 border-0 py-2 fs-6" id="scannerInput"
|
|
placeholder="Escanea con la pistola o escribe el DNI..." autofocus autocomplete="off">
|
|
<button class="btn btn-primary rounded-end-pill px-4 fw-semibold border-0" type="submit">
|
|
<i class="bi bi-arrow-right-circle me-1"></i> Validar
|
|
</button>
|
|
</div>
|
|
<div class="d-flex align-items-center justify-content-between px-2">
|
|
<span class="small text-muted" style="font-size: 0.74rem;">
|
|
<i class="bi bi-info-circle me-1"></i>Captura automática al recibir el delimitador Enter
|
|
</span>
|
|
<button type="button" class="btn btn-link btn-sm text-decoration-none p-0 text-primary small" onclick="focusScannerInput()">
|
|
<i class="bi bi-crosshair me-1"></i>Forzar Foco
|
|
</button>
|
|
</div>
|
|
</form>
|
|
|
|
<!-- Panel de Conexión Serial / Puerto COM (Web Serial API) -->
|
|
<div class="mt-4 pt-3 border-top">
|
|
<div class="d-flex align-items-center justify-content-between mb-2">
|
|
<span class="small fw-bold text-uppercase text-muted">
|
|
<i class="bi bi-usb-symbol me-1 text-primary"></i> Puerto Serie (COM)
|
|
</span>
|
|
<span class="badge bg-secondary-subtle text-secondary rounded-pill px-2 py-1 small" id="serialPortStatusBadge">
|
|
<i class="bi bi-circle-fill text-muted me-1" style="font-size: 0.5rem;"></i> Puerto USB-HID Activo
|
|
</span>
|
|
</div>
|
|
<div class="d-flex align-items-center justify-content-between p-2 rounded-3 bg-body-tertiary border">
|
|
<small class="text-muted" style="font-size: 0.74rem;">
|
|
Dispositivos Seriales COM (Windows / Chromium)
|
|
</small>
|
|
<button type="button" class="btn btn-xs btn-outline-secondary rounded-pill px-3 py-1 text-nowrap" id="btnConnectSerial" onclick="handleSerialConnectClick()">
|
|
<i class="bi bi-link-45deg me-1"></i>Configurar COM
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Columna Derecha: Tarjeta de Validación Instantánea y Aulas del Día -->
|
|
<div class="col-12 col-lg-7">
|
|
<!-- Tarjeta de Resultado en Pantalla Completa -->
|
|
<div class="card border-0 shadow-sm rounded-4 overflow-hidden mb-4" id="resultCard" style="min-height: 380px;">
|
|
<div class="card-header py-3 px-4 bg-light border-0 d-flex align-items-center justify-content-between" id="resultHeader">
|
|
<h5 class="fw-bold mb-0" id="resultStatusText">
|
|
<i class="bi bi-person-badge me-2 text-muted"></i> Esperando lectura...
|
|
</h5>
|
|
<span class="badge bg-secondary rounded-pill px-3 py-1" id="resultTimeBadge">--:--</span>
|
|
</div>
|
|
<div class="card-body p-4 d-flex flex-column justify-content-center text-center" id="resultBody">
|
|
<div class="py-5 text-muted" id="waitingState">
|
|
<i class="bi bi-qr-code-scan display-1 opacity-25 text-primary mb-3 d-block"></i>
|
|
<h4 class="fw-bold text-secondary">Apunta el lector óptico a la credencial</h4>
|
|
<p class="small text-muted max-w-md mx-auto">
|
|
Al detectar la credencial dinámica o física del alumno o docente, el sistema mostrará instantáneamente sus datos de ingreso y las aulas donde cursa hoy.
|
|
</p>
|
|
</div>
|
|
|
|
<!-- Contenedor de Resultado Activo (Oculto inicialmente) -->
|
|
<div id="activeResultState" class="d-none text-start">
|
|
<div class="row align-items-center mb-4">
|
|
<div class="col-auto">
|
|
<div class="rounded-circle bg-primary text-white display-6 fw-bold d-flex align-items-center justify-content-center shadow-sm"
|
|
style="width: 80px; height: 80px;" id="userInitial">
|
|
A
|
|
</div>
|
|
</div>
|
|
<div class="col">
|
|
<div class="badge bg-success rounded-pill px-3 py-1 mb-1" id="matriculaBadge">REGULAR / ACTIVO</div>
|
|
<h3 class="fw-bold mb-0 text-dark" id="userNameText">Nombre del Alumno</h3>
|
|
<div class="text-muted small">
|
|
<span id="userRoleText">ESTUDIANTE</span> • DNI: <strong id="userDniText">12345678</strong>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Sección de Aulas y Clases de Hoy -->
|
|
<div class="p-3 bg-light rounded-4 border mb-3">
|
|
<h6 class="fw-bold text-uppercase text-primary small mb-3">
|
|
<i class="bi bi-compass-fill me-1"></i> Cronograma Áulico del Día de Hoy
|
|
</h6>
|
|
<div id="classesContainer">
|
|
<!-- Inyección dinámica de clases -->
|
|
</div>
|
|
</div>
|
|
|
|
<div class="d-flex align-items-center justify-content-between text-muted small">
|
|
<span id="scanTimestampText"><i class="bi bi-clock me-1"></i> Escaneado a las: --:--</span>
|
|
<span class="badge bg-primary-subtle text-primary border border-primary-subtle rounded-pill px-3 py-1">
|
|
Check-in Registrado
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Tabla de Ingresos Recientes -->
|
|
<div class="card border-0 shadow-sm rounded-4 overflow-hidden">
|
|
<div class="card-header bg-body border-0 py-3 px-4 d-flex align-items-center justify-content-between">
|
|
<h6 class="fw-bold mb-0 text-dark">
|
|
<i class="bi bi-clock-history me-2 text-primary"></i> Últimos Ingresos Registrados en Sede
|
|
</h6>
|
|
<button type="button" class="btn btn-sm btn-link text-decoration-none p-0" onclick="refreshRecentLogs()">
|
|
<i class="bi bi-arrow-clockwise me-1"></i> Actualizar
|
|
</button>
|
|
</div>
|
|
<div class="table-responsive" style="max-height: 250px;">
|
|
<table class="table table-hover table-sm align-middle mb-0" id="recentLogsTable">
|
|
<thead class="table-light small">
|
|
<tr>
|
|
<th class="ps-4">Usuario</th>
|
|
<th>Rol</th>
|
|
<th>DNI</th>
|
|
<th>Sede</th>
|
|
<th>Hora</th>
|
|
<th class="text-center">Estado</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="small" id="recentLogsBody">
|
|
{% if recentLogs and recentLogs | length > 0 %}
|
|
{% for log in recentLogs %}
|
|
<tr>
|
|
<td class="ps-4 fw-semibold">{{ log.user_name }}</td>
|
|
<td><span class="badge bg-light text-dark border">{{ log.user_role or 'ALUMNO' }}</span></td>
|
|
<td>{{ log.user_dni or '--' }}</td>
|
|
<td>{{ log.building_name }}</td>
|
|
<td>{{ log.scanned_time if log.scanned_time else (log.scanned_at | replace('T', ' ') | truncate(16, true, '')) }}</td>
|
|
<td class="text-center">
|
|
{% if log.status == 'AUTORIZADO' %}
|
|
<span class="badge bg-success-subtle text-success">OK</span>
|
|
{% else %}
|
|
<span class="badge bg-danger-subtle text-danger">{{ log.status }}</span>
|
|
{% endif %}
|
|
</td>
|
|
</tr>
|
|
{% endfor %}
|
|
{% else %}
|
|
<tr>
|
|
<td colspan="6" class="text-center py-3 text-muted">Aún no se han registrado ingresos hoy.</td>
|
|
</tr>
|
|
{% endif %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Módulo de Web Serial API para lectores ópticos y escáneres QR (SDD-013) -->
|
|
<script src="/js/serial-scanner.js"></script>
|
|
|
|
<script>
|
|
let isScanningLocked = false;
|
|
let serialScanner = null;
|
|
|
|
// Inicializar SerialBarcodeScanner para Chromium / Windows
|
|
function initSerialScanner() {
|
|
if (typeof SerialBarcodeScanner === 'undefined') return;
|
|
|
|
serialScanner = new SerialBarcodeScanner({
|
|
baudRate: 9600,
|
|
onCodeScanned: function(code) {
|
|
if (!isScanningLocked) {
|
|
isScanningLocked = true;
|
|
playBeep(true);
|
|
verifyToken(code);
|
|
setTimeout(() => { isScanningLocked = false; }, 1500);
|
|
}
|
|
},
|
|
onStatusChanged: function(evt) {
|
|
const badge = document.getElementById('serialPortStatusBadge');
|
|
const btn = document.getElementById('btnConnectSerial');
|
|
if (evt.status === 'CONNECTED') {
|
|
if (badge) {
|
|
badge.className = 'badge bg-success text-white rounded-pill px-2 py-1 small';
|
|
badge.innerHTML = '<i class="bi bi-usb-plug-fill me-1"></i> COM Activo (9600 baud)';
|
|
}
|
|
if (btn) {
|
|
btn.className = 'btn btn-xs btn-outline-danger rounded-pill px-3 py-1 text-nowrap';
|
|
btn.innerHTML = '<i class="bi bi-x-circle me-1"></i>Desconectar';
|
|
}
|
|
} else {
|
|
if (badge) {
|
|
badge.className = 'badge bg-secondary-subtle text-secondary rounded-pill px-2 py-1 small';
|
|
badge.innerHTML = '<i class="bi bi-circle-fill text-muted me-1" style="font-size: 0.5rem;"></i> Puerto USB-HID Activo';
|
|
}
|
|
if (btn) {
|
|
btn.className = 'btn btn-xs btn-outline-secondary rounded-pill px-3 py-1 text-nowrap';
|
|
btn.innerHTML = '<i class="bi bi-link-45deg me-1"></i>Configurar COM';
|
|
}
|
|
}
|
|
},
|
|
onError: function(err) {
|
|
console.warn('[SerialScanner UI] Error:', err);
|
|
}
|
|
});
|
|
|
|
// Comprobar soporte
|
|
if (!serialScanner.isSupported()) {
|
|
const badge = document.getElementById('serialPortStatusBadge');
|
|
const btn = document.getElementById('btnConnectSerial');
|
|
if (badge) {
|
|
badge.className = 'badge bg-body-tertiary text-muted rounded-pill px-2 py-1 small border';
|
|
badge.textContent = 'Modo USB-HID (Chromium requerido para COM)';
|
|
}
|
|
if (btn) btn.disabled = true;
|
|
} else {
|
|
// Intentar auto-conexión a puerto previamente autorizado
|
|
serialScanner.autoConnectIfAuthorized();
|
|
}
|
|
}
|
|
|
|
async function handleSerialConnectClick() {
|
|
if (!serialScanner) initSerialScanner();
|
|
if (!serialScanner.isSupported()) {
|
|
alert('La Web Serial API no está disponible en este navegador. Utiliza Google Chrome o Microsoft Edge en entornos Windows.');
|
|
return;
|
|
}
|
|
|
|
const btn = document.getElementById('btnConnectSerial');
|
|
if (serialScanner.port) {
|
|
await serialScanner.disconnect();
|
|
} else {
|
|
try {
|
|
await serialScanner.requestAndConnect(9600);
|
|
} catch (err) {
|
|
if (err.name !== 'NotFoundError') {
|
|
console.error('Error al conectar puerto COM:', err);
|
|
alert('No se pudo abrir el puerto serie: ' + err.message);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Mantener el cursor forzado permanentemente en el input de la pistola óptica
|
|
function focusScannerInput() {
|
|
const input = document.getElementById('scannerInput');
|
|
if (!input) return;
|
|
const active = document.activeElement;
|
|
// Evitar robar el foco solo si el usuario está activamente en el selector de sedes
|
|
if (active && active.id === 'buildingSelect') return;
|
|
if (active !== input) {
|
|
input.focus();
|
|
}
|
|
updateFocusIndicator(true);
|
|
}
|
|
|
|
function updateFocusIndicator(isFocused) {
|
|
const indicator = document.getElementById('scannerFocusIndicator');
|
|
if (!indicator) return;
|
|
if (isFocused) {
|
|
indicator.className = 'small text-success fw-semibold d-flex align-items-center gap-1';
|
|
indicator.innerHTML = '<span class="scanner-active-dot"></span> Lector Listo';
|
|
} else {
|
|
indicator.className = 'small text-warning fw-semibold d-flex align-items-center gap-1';
|
|
indicator.innerHTML = '<i class="bi bi-exclamation-circle"></i> Haz clic para activar';
|
|
}
|
|
}
|
|
|
|
// Entrada manual o con pistola de código de barras
|
|
function handleManualScan(e) {
|
|
if (e) e.preventDefault();
|
|
const input = document.getElementById('scannerInput');
|
|
if (!input) return;
|
|
let val = input.value.trim();
|
|
if (!val) {
|
|
focusScannerInput();
|
|
return;
|
|
}
|
|
// Normalización para teclados en español / latinoamericano donde la pistola traduce : a Ñ
|
|
val = val.replace(/Ñ/g, ':').replace(/ñ/g, ':');
|
|
verifyToken(val);
|
|
input.value = '';
|
|
setTimeout(focusScannerInput, 50);
|
|
}
|
|
|
|
// Petición AJAX de verificación al Backend BFF
|
|
async function verifyToken(token) {
|
|
const buildingId = document.getElementById('buildingSelect').value;
|
|
|
|
try {
|
|
const resp = await fetch('/reception/verify', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
qr_token: token,
|
|
building_id: buildingId ? parseInt(buildingId, 10) : null
|
|
})
|
|
});
|
|
|
|
const data = await resp.json();
|
|
displayVerificationResult(data);
|
|
refreshRecentLogs();
|
|
} catch (err) {
|
|
console.error('Error verificando:', err);
|
|
displayVerificationResult({
|
|
status: 'DENEGADO',
|
|
message: 'Error de conexión con el validador.',
|
|
todays_classes: []
|
|
});
|
|
} finally {
|
|
setTimeout(focusScannerInput, 150);
|
|
}
|
|
}
|
|
|
|
// Despliegue visual de resultados en pantalla
|
|
function displayVerificationResult(data) {
|
|
const waitingState = document.getElementById('waitingState');
|
|
const activeState = document.getElementById('activeResultState');
|
|
const cardHeader = document.getElementById('resultHeader');
|
|
const statusText = document.getElementById('resultStatusText');
|
|
const timeBadge = document.getElementById('resultTimeBadge');
|
|
|
|
waitingState.classList.add('d-none');
|
|
activeState.classList.remove('d-none');
|
|
|
|
const now = new Date();
|
|
timeBadge.innerText = now.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', second: '2-digit' });
|
|
|
|
if (data.status === 'AUTORIZADO') {
|
|
cardHeader.className = 'card-header py-3 px-4 bg-success text-white border-0 d-flex align-items-center justify-content-between';
|
|
statusText.innerHTML = '<i class="bi bi-check-circle-fill me-2"></i> ACCESO AUTORIZADO';
|
|
document.getElementById('matriculaBadge').className = 'badge bg-success rounded-pill px-3 py-1 mb-1';
|
|
document.getElementById('matriculaBadge').innerText = data.matricula_status || 'ACTIVO';
|
|
} else if (data.status === 'RESTRINGIDO') {
|
|
cardHeader.className = 'card-header py-3 px-4 bg-warning text-dark border-0 d-flex align-items-center justify-content-between';
|
|
statusText.innerHTML = '<i class="bi bi-exclamation-triangle-fill me-2"></i> ACCESO OBSERVADO / RESTRINGIDO';
|
|
document.getElementById('matriculaBadge').className = 'badge bg-warning text-dark rounded-pill px-3 py-1 mb-1';
|
|
document.getElementById('matriculaBadge').innerText = data.matricula_status || 'OBSERVADO';
|
|
} else {
|
|
cardHeader.className = 'card-header py-3 px-4 bg-danger text-white border-0 d-flex align-items-center justify-content-between';
|
|
statusText.innerHTML = '<i class="bi bi-x-circle-fill me-2"></i> ACCESO DENEGADO';
|
|
document.getElementById('matriculaBadge').className = 'badge bg-danger rounded-pill px-3 py-1 mb-1';
|
|
document.getElementById('matriculaBadge').innerText = data.matricula_status || 'NO REGISTRADO';
|
|
}
|
|
|
|
document.getElementById('userNameText').innerText = data.user_name || 'Desconocido';
|
|
document.getElementById('userRoleText').innerText = (data.user_role || 'NO DEFINIDO').toUpperCase();
|
|
document.getElementById('userDniText').innerText = data.user_dni || '--';
|
|
document.getElementById('userInitial').innerText = (data.user_name || '?')[0].toUpperCase();
|
|
document.getElementById('scanTimestampText').innerHTML = `<i class="bi bi-clock me-1"></i> Escaneado: ${now.toLocaleTimeString()}`;
|
|
|
|
// Renderizado del cronograma de aulas de hoy
|
|
const classesContainer = document.getElementById('classesContainer');
|
|
if (data.todays_classes && data.todays_classes.length > 0) {
|
|
classesContainer.innerHTML = data.todays_classes.map(c => `
|
|
<div class="card border border-primary-subtle rounded-3 p-3 mb-2 bg-white shadow-sm">
|
|
<div class="d-flex align-items-start justify-content-between">
|
|
<div>
|
|
<span class="badge bg-primary text-white rounded-pill px-2 py-0 small mb-1">${c.commission_name}</span>
|
|
<h5 class="fw-bold mb-1 text-primary">${c.subject_name}</h5>
|
|
<div class="text-muted small">
|
|
<i class="bi bi-person me-1"></i> Docente: <strong>${c.teacher_name || 'A designar'}</strong>
|
|
</div>
|
|
</div>
|
|
<div class="text-end">
|
|
<span class="badge bg-warning text-dark fs-6 px-3 py-1 rounded-pill fw-bold shadow-sm">
|
|
<i class="bi bi-door-open me-1"></i> ${c.classroom_name}
|
|
</span>
|
|
<div class="fw-semibold text-dark mt-1" style="font-size: 0.85rem;">
|
|
Piso: <strong>${c.floor || 1}</strong> (${c.building_name})
|
|
</div>
|
|
<div class="small text-muted mt-1">
|
|
<i class="bi bi-clock me-1"></i> ${c.start_time} a ${c.end_time} hs
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
`).join('');
|
|
} else {
|
|
classesContainer.innerHTML = `
|
|
<div class="alert alert-secondary py-2 px-3 rounded-3 small mb-0">
|
|
<i class="bi bi-info-circle me-1"></i> No tiene clases presenciales programadas para el día de hoy.
|
|
</div>
|
|
`;
|
|
}
|
|
}
|
|
|
|
// Actualización de la tabla de ingresos recientes
|
|
async function refreshRecentLogs() {
|
|
const buildingId = document.getElementById('buildingSelect').value;
|
|
try {
|
|
const res = await fetch(`/reception/recent-logs?building_id=${buildingId || ''}`);
|
|
const data = await res.json();
|
|
const tbody = document.getElementById('recentLogsBody');
|
|
if (data.items && data.items.length > 0) {
|
|
tbody.innerHTML = data.items.map(l => `
|
|
<tr>
|
|
<td class="ps-4 fw-semibold">${l.user_name}</td>
|
|
<td><span class="badge bg-light text-dark border">${l.user_role || 'ALUMNO'}</span></td>
|
|
<td>${l.user_dni || '--'}</td>
|
|
<td>${l.building_name}</td>
|
|
<td>${formatLogTime(l)}</td>
|
|
<td class="text-center">
|
|
<span class="badge ${l.status === 'AUTORIZADO' ? 'bg-success-subtle text-success' : 'bg-danger-subtle text-danger'}">
|
|
${l.status === 'AUTORIZADO' ? 'OK' : l.status}
|
|
</span>
|
|
</td>
|
|
</tr>
|
|
`).join('');
|
|
}
|
|
} catch (e) {
|
|
console.warn('Error refrescando logs:', e);
|
|
}
|
|
}
|
|
|
|
function formatLogTime(l) {
|
|
if (l.scanned_time) return l.scanned_time;
|
|
if (!l.scanned_at) return '--';
|
|
try {
|
|
const raw = l.scanned_at;
|
|
const d = new Date(raw.endsWith('Z') || raw.includes('+') || raw.includes('-') ? raw : raw + 'Z');
|
|
return d.toLocaleTimeString('es-AR', {
|
|
hour: '2-digit',
|
|
minute: '2-digit',
|
|
hour12: false,
|
|
timeZone: 'America/Argentina/Buenos_Aires'
|
|
}) + ' hs';
|
|
} catch (e) {
|
|
return l.scanned_at.substring(11, 16) + ' hs';
|
|
}
|
|
}
|
|
|
|
// Feedback sonoro opcional vía Web Audio API
|
|
function playBeep(success) {
|
|
try {
|
|
const ctx = new (window.AudioContext || window.webkitAudioContext)();
|
|
const osc = ctx.createOscillator();
|
|
const gain = ctx.createGain();
|
|
osc.connect(gain);
|
|
gain.connect(ctx.destination);
|
|
osc.frequency.value = success ? 880 : 330;
|
|
gain.gain.value = 0.1;
|
|
osc.start();
|
|
setTimeout(() => { osc.stop(); }, 120);
|
|
} catch (e) {}
|
|
}
|
|
|
|
// Eventos globales para forzar el foco permanente en scannerInput
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
initSerialScanner();
|
|
focusScannerInput();
|
|
setInterval(focusScannerInput, 2000);
|
|
|
|
const input = document.getElementById('scannerInput');
|
|
if (input) {
|
|
input.addEventListener('focus', () => updateFocusIndicator(true));
|
|
input.addEventListener('blur', () => {
|
|
setTimeout(() => {
|
|
const active = document.activeElement;
|
|
if (active && active.id !== 'buildingSelect') {
|
|
focusScannerInput();
|
|
} else {
|
|
updateFocusIndicator(false);
|
|
}
|
|
}, 100);
|
|
});
|
|
}
|
|
});
|
|
|
|
window.addEventListener('focus', focusScannerInput);
|
|
|
|
document.addEventListener('click', (e) => {
|
|
// Si el usuario no hace clic sobre el selector de sedes o botones interactivos, regresar el cursor al input
|
|
if (!e.target.closest('select, button, a, #reader')) {
|
|
focusScannerInput();
|
|
}
|
|
});
|
|
</script>
|
|
|
|
<style>
|
|
.scanner-active-dot {
|
|
width: 8px;
|
|
height: 8px;
|
|
background-color: #22c55e;
|
|
border-radius: 50%;
|
|
display: inline-block;
|
|
animation: pulse-dot 1.5s infinite ease-in-out;
|
|
}
|
|
@keyframes pulse-dot {
|
|
0% { transform: scale(0.9); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7); }
|
|
70% { transform: scale(1.15); box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
|
|
100% { transform: scale(0.9); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
|
|
}
|
|
</style>
|
|
{% endblock %}
|