feat(benefits-reception): add institutional benefits, QR digital card & reception access control (SDD-012 v3.8.39)
This commit is contained in:
@@ -0,0 +1,390 @@
|
||||
{% 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:</label>
|
||||
<select class="form-select form-select-sm rounded-pill px-3" id="buildingSelect">
|
||||
<option value="">Todas las Sedes</option>
|
||||
{% for b in buildings %}
|
||||
<option value="{{ b.id }}" {% if loop.first %}selected{% endif %}>{{ b.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row g-4">
|
||||
<!-- Columna Izquierda: Escáner y Entrada Rápida -->
|
||||
<div class="col-12 col-lg-5">
|
||||
<div class="card border-0 shadow-sm rounded-4 p-4 mb-4">
|
||||
<h5 class="fw-bold mb-3 d-flex align-items-center justify-content-between">
|
||||
<span><i class="bi bi-camera me-2 text-primary"></i>Lector de Cámara</span>
|
||||
<button type="button" class="btn btn-sm btn-outline-primary rounded-pill px-3" id="toggleCamBtn" onclick="toggleCamera()">
|
||||
<i class="bi bi-play-circle me-1"></i> Iniciar Cámara
|
||||
</button>
|
||||
</h5>
|
||||
|
||||
<!-- Visor de Cámara -->
|
||||
<div id="reader" class="rounded-4 overflow-hidden bg-dark position-relative d-flex align-items-center justify-content-center text-white"
|
||||
style="width: 100%; min-height: 280px;">
|
||||
<div id="cameraPlaceholder" class="text-center p-4">
|
||||
<i class="bi bi-camera-video display-4 text-secondary mb-2 d-block"></i>
|
||||
<span class="small text-muted">Cámara en espera. Presiona "Iniciar Cámara" o utiliza un lector óptico USB.</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Entrada Manual o Pistola Óptica USB -->
|
||||
<div class="mt-4 pt-3 border-top">
|
||||
<label class="form-label small fw-bold text-uppercase text-muted">
|
||||
<i class="bi bi-upc-scan me-1 text-primary"></i> Pistola Óptica USB o Entrada Manual por DNI
|
||||
</label>
|
||||
<form id="manualScanForm" onsubmit="handleManualScan(event)">
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control rounded-start-pill ps-3" 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" type="submit">
|
||||
Validar
|
||||
</button>
|
||||
</div>
|
||||
<span class="small text-muted d-block mt-1">El lector óptico envía la lectura directamente a este campo con retorno de carro automático.</span>
|
||||
</form>
|
||||
</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 código QR a la cámara</h4>
|
||||
<p class="small text-muted max-w-md mx-auto">
|
||||
Al detectar la credencial 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_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>
|
||||
|
||||
<!-- html5-qrcode Library via CDN -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/html5-qrcode@2.3.8/html5-qrcode.min.js"></script>
|
||||
|
||||
<script>
|
||||
let html5QrCode = null;
|
||||
let isCameraRunning = false;
|
||||
let isScanningLocked = false;
|
||||
|
||||
// Inicializar o alternar cámara
|
||||
function toggleCamera() {
|
||||
const btn = document.getElementById('toggleCamBtn');
|
||||
const placeholder = document.getElementById('cameraPlaceholder');
|
||||
|
||||
if (isCameraRunning) {
|
||||
if (html5QrCode) {
|
||||
html5QrCode.stop().then(() => {
|
||||
isCameraRunning = false;
|
||||
btn.innerHTML = '<i class="bi bi-play-circle me-1"></i> Iniciar Cámara';
|
||||
btn.classList.replace('btn-danger', 'btn-outline-primary');
|
||||
placeholder.classList.remove('d-none');
|
||||
});
|
||||
}
|
||||
} else {
|
||||
html5QrCode = new Html5Qrcode("reader");
|
||||
placeholder.classList.add('d-none');
|
||||
|
||||
html5QrCode.start(
|
||||
{ facingMode: "environment" },
|
||||
{
|
||||
fps: 10,
|
||||
qrbox: { width: 250, height: 250 }
|
||||
},
|
||||
(decodedText) => {
|
||||
if (!isScanningLocked) {
|
||||
isScanningLocked = true;
|
||||
playBeep(true);
|
||||
verifyToken(decodedText);
|
||||
setTimeout(() => { isScanningLocked = false; }, 2500);
|
||||
}
|
||||
},
|
||||
(errorMessage) => {
|
||||
// Errores normales de lectura frame a frame, se omiten
|
||||
}
|
||||
).then(() => {
|
||||
isCameraRunning = true;
|
||||
btn.innerHTML = '<i class="bi bi-stop-circle me-1"></i> Detener Cámara';
|
||||
btn.classList.replace('btn-outline-primary', 'btn-danger');
|
||||
}).catch(err => {
|
||||
console.error("Error al iniciar cámara:", err);
|
||||
placeholder.classList.remove('d-none');
|
||||
alert("No se pudo acceder a la cámara. Asegúrate de otorgar los permisos en el navegador.");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Entrada manual o con pistola de código de barras
|
||||
function handleManualScan(e) {
|
||||
e.preventDefault();
|
||||
const input = document.getElementById('scannerInput');
|
||||
const val = input.value.trim();
|
||||
if (!val) return;
|
||||
verifyToken(val);
|
||||
input.value = '';
|
||||
}
|
||||
|
||||
// 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: []
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 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>${l.scanned_at ? l.scanned_at.replace('T', ' ').substring(11, 16) + ' hs' : '--'}</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);
|
||||
}
|
||||
}
|
||||
|
||||
// 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) {}
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user