88 lines
4.7 KiB
HTML
88 lines
4.7 KiB
HTML
<!doctype html>
|
|
<html lang="es">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Administración — HBOX</title>
|
|
<script src="js/tema.js"></script>
|
|
<link rel="stylesheet" href="formularios/acta.css">
|
|
<style>
|
|
table{border-collapse:collapse;width:100%;font-size:14px;margin-top:6px}
|
|
th{text-align:left;color:var(--tinta2);font-size:11.5px;text-transform:uppercase;letter-spacing:.05em;padding:6px 8px 6px 0;border-bottom:1px solid var(--tinta2)}
|
|
td{padding:7px 8px 7px 0;border-bottom:1px solid var(--linea)}
|
|
.del{background:transparent;color:var(--falla);border:1px solid var(--falla);border-radius:8px;padding:5px 10px;font-size:13px;cursor:pointer}
|
|
.bulk{background:var(--falla);color:#fff;border:0;border-radius:9px;padding:9px 14px;font-size:13.5px;cursor:pointer;margin:4px 8px 4px 0}
|
|
.ver{color:var(--plane);text-decoration:none;font-weight:600}
|
|
.aviso{background:var(--crit-soft);border:1px solid var(--crit);padding:10px 14px;border-radius:8px;margin:10px 0}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="wrap">
|
|
<header class="top"><h1>Administración de actas</h1><p id="sub">Solo para el administrador.</p></header>
|
|
<div style="margin:2px 0 10px;display:flex;gap:16px;flex-wrap:wrap"><a class="volver" href="tableros/actas/">← Estado de actas</a><a class="volver" href="tableros/equipo/">Usuarios y equipo →</a></div>
|
|
<div id="cont"><p>Comprobando permisos…</p></div>
|
|
</div>
|
|
<script>
|
|
const cont = document.getElementById('cont');
|
|
const TIPOS = [
|
|
{ tipo:'prueba-v5', label:'Prueba V5' },
|
|
{ tipo:'prueba-v4', label:'Prueba V4' },
|
|
{ tipo:'ensamble', label:'Ensamble' },
|
|
];
|
|
function esc(s){ const d=document.createElement('div'); d.textContent=s==null?'':String(s); return d.innerHTML; }
|
|
function fmt(iso){ return iso? iso.replace('T',' ').slice(0,16):''; }
|
|
|
|
async function delOne(tipo, serie){
|
|
if(!confirm('¿Borrar el acta '+serie+'? Podrá rehacerse.')) return;
|
|
const r = await fetch('/api/acta?tipo='+encodeURIComponent(tipo)+'&serie='+encodeURIComponent(serie),{method:'DELETE'});
|
|
const j = await r.json(); if(!j.ok){ alert(j.error||'error'); return; } load();
|
|
}
|
|
async function delAll(tipo, label){
|
|
if(!confirm('¿BORRAR TODAS las actas de '+label+'? Esta acción no se puede deshacer.')) return;
|
|
if(!confirm('Confirma otra vez: se borrarán TODAS las de '+label+'.')) return;
|
|
const r = await fetch('/api/actas?tipo='+encodeURIComponent(tipo),{method:'DELETE'});
|
|
const j = await r.json(); if(!j.ok){ alert(j.error||'error'); return; }
|
|
alert('Borradas: '+j.borradas); load();
|
|
}
|
|
async function delPruebas(){
|
|
if(!confirm('¿Borrar todos los registros de PRUEBA de los tres formularios?')) return;
|
|
for(const t of TIPOS){ await fetch('/api/actas?tipo='+encodeURIComponent(t.tipo)+'&pruebas=1',{method:'DELETE'}); }
|
|
alert('Registros de prueba borrados.'); load();
|
|
}
|
|
|
|
async function load(){
|
|
let who; try{ who = await (await fetch('/api/whoami')).json(); }catch(e){}
|
|
if(!who || !who.admin){
|
|
cont.innerHTML = '<div class="aviso"><b>Acceso restringido.</b> Esta página solo está disponible para el administrador (Leo). '
|
|
+ 'Tú entraste como <b>'+esc(who&&who.user||'—')+'</b>.</div>';
|
|
return;
|
|
}
|
|
document.getElementById('sub').textContent = 'Administrador: '+esc(who.user);
|
|
let j; try{ j = await (await fetch('/api/actas')).json(); }catch(e){ cont.innerHTML='Error al cargar.'; return; }
|
|
const actas = j.actas || [];
|
|
let h = '<div class="paso"><h2>Reiniciar en bloque</h2>'
|
|
+ '<p class="sub">Borra todas las actas guardadas de un formulario, para volver a empezar el lote.</p>';
|
|
TIPOS.forEach(t=>{ h += '<button class="bulk" onclick="delAll(\''+t.tipo+'\',\''+t.label+'\')">Borrar TODAS — '+t.label+'</button>'; });
|
|
h += '<button class="bulk" style="background:var(--tinta2)" onclick="delPruebas()">Limpiar registros de PRUEBA</button></div>';
|
|
|
|
h += '<div class="paso"><h2>Actas guardadas ('+actas.length+')</h2>';
|
|
if(!actas.length){ h += '<p class="sub">No hay actas guardadas.</p>'; }
|
|
else {
|
|
h += '<div class="tblwrap"><table><tr><th>Serie</th><th>Tipo</th><th>Técnico</th><th>Resultado</th><th>Fecha</th><th></th><th></th></tr>';
|
|
actas.forEach(a=>{
|
|
h += '<tr><td><b>'+esc(a.serie)+'</b></td><td>'+esc(a.tipo)+'</td><td>'+esc(a.tecnico||'')+'</td>'
|
|
+ '<td>'+esc(a.resultado||'')+'</td><td>'+esc(fmt(a.recibido))+'</td>'
|
|
+ '<td><a class="ver" href="formularios/ver.html?tipo='+encodeURIComponent(a.tipo)+'&serie='+encodeURIComponent(a.serie)+'">Ver</a></td>'
|
|
+ '<td><button class="del" onclick="delOne(\''+a.tipo+'\',\''+esc(a.serie)+'\')">Borrar</button></td></tr>';
|
|
});
|
|
h += '</table></div>';
|
|
}
|
|
h += '</div>';
|
|
cont.innerHTML = h;
|
|
}
|
|
window.delOne=delOne; window.delAll=delAll; window.delPruebas=delPruebas;
|
|
load();
|
|
</script>
|
|
</body>
|
|
</html>
|