280 lines
16 KiB
HTML
280 lines
16 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="es">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Trazabilidad - IntegraRepara</title>
|
|
<script src="https://cdn.tailwindcss.com"></script>
|
|
<script src="https://unpkg.com/lucide@latest"></script>
|
|
<style>
|
|
.fade-in { animation: fadeIn 0.4s ease-out forwards; }
|
|
@keyframes fadeIn {
|
|
from { opacity: 0; transform: translateY(15px); }
|
|
to { opacity: 1; transform: translateY(0); }
|
|
}
|
|
.no-scrollbar::-webkit-scrollbar { display: none; }
|
|
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
|
|
|
|
/* Línea continua del timeline */
|
|
.timeline-line::before {
|
|
content: '';
|
|
position: absolute;
|
|
top: 0;
|
|
bottom: 0;
|
|
left: 23px; /* Ajuste fino para centrar la línea con los puntos */
|
|
width: 2px;
|
|
background: #e2e8f0; /* slate-200 */
|
|
z-index: 0;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body class="bg-slate-50 text-slate-800 font-sans h-screen flex flex-col overflow-hidden">
|
|
|
|
<header class="bg-white border-b border-slate-200 px-6 py-4 flex items-center justify-between shadow-sm z-20 shrink-0">
|
|
<div class="flex items-center gap-4">
|
|
<button onclick="window.history.back()" class="p-2.5 bg-slate-100 text-slate-500 hover:bg-blue-100 hover:text-blue-600 rounded-xl transition-all shadow-sm active:scale-95">
|
|
<i data-lucide="arrow-left" class="w-5 h-5"></i>
|
|
</button>
|
|
<div>
|
|
<p class="text-[10px] font-black text-slate-400 uppercase tracking-widest">Auditoría y Trazabilidad</p>
|
|
<h1 class="text-xl font-black text-slate-800 leading-none mt-1 flex items-center gap-2">
|
|
Expediente <span id="svcRef" class="text-blue-600 px-2 py-0.5 bg-blue-50 rounded-lg">...</span>
|
|
</h1>
|
|
</div>
|
|
</div>
|
|
<div class="bg-slate-800 text-white px-4 py-2 rounded-xl shadow-md flex items-center gap-2">
|
|
<i data-lucide="activity" class="w-4 h-4 text-emerald-400"></i>
|
|
<span class="text-xs font-black uppercase tracking-widest" id="logCount">0 Registros</span>
|
|
</div>
|
|
</header>
|
|
|
|
<main class="flex-1 overflow-y-auto no-scrollbar p-6 md:p-10 relative">
|
|
<div class="max-w-3xl mx-auto">
|
|
|
|
<div class="bg-white p-5 rounded-3xl shadow-sm border border-slate-200 mb-10 sticky top-0 z-10">
|
|
<div class="flex gap-4 items-start">
|
|
<div class="w-12 h-12 bg-amber-50 rounded-full flex items-center justify-center text-amber-500 shrink-0 shadow-inner border border-amber-100">
|
|
<i data-lucide="pen-tool" class="w-6 h-6"></i>
|
|
</div>
|
|
<div class="flex-1">
|
|
<textarea id="manualNoteInput" rows="2" placeholder="Escribe un apunte interno, observación o nota para este expediente..." class="w-full bg-slate-50 border border-slate-200 px-4 py-3 rounded-2xl text-sm font-medium outline-none focus:bg-white focus:border-amber-400 focus:ring-4 focus:ring-amber-50 transition-all resize-none"></textarea>
|
|
<div class="flex justify-end mt-3">
|
|
<button onclick="addManualNote(this)" class="bg-amber-500 hover:bg-amber-600 text-white text-xs font-black uppercase tracking-widest px-6 py-2.5 rounded-xl shadow-md transition-all flex items-center gap-2 active:scale-95">
|
|
Guardar Apunte <i data-lucide="send" class="w-4 h-4"></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="relative timeline-line ml-2 md:ml-4 pb-20" id="timelineContainer">
|
|
<div class="text-center text-slate-400 py-20 flex flex-col items-center relative z-10">
|
|
<i data-lucide="loader-2" class="w-10 h-10 animate-spin mb-4 text-blue-500"></i>
|
|
<p class="text-sm font-black uppercase tracking-widest text-slate-500">Recopilando historial...</p>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</main>
|
|
|
|
<div id="toast" class="fixed bottom-8 right-8 bg-slate-900 text-white px-6 py-3 rounded-2xl shadow-2xl hidden z-[200] font-bold text-sm flex items-center gap-2 transition-all"></div>
|
|
|
|
<script>
|
|
// Configuración de la API (Usa la misma variable que el resto de tu app si tienes layout.js)
|
|
const API_URL = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'
|
|
? 'http://localhost:3000'
|
|
: 'https://integrarepara-api.integrarepara.es';
|
|
|
|
let serviceId = null;
|
|
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
lucide.createIcons();
|
|
|
|
// Extraer el ID de la URL (Ejemplo: trazabilidad.html?id=15)
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
serviceId = urlParams.get('id');
|
|
const urlRef = urlParams.get('ref'); // Opcional, si le pasas la referencia en la URL
|
|
|
|
if (!serviceId) {
|
|
document.getElementById('timelineContainer').innerHTML = `
|
|
<div class="bg-red-50 border border-red-200 text-red-600 p-8 rounded-3xl text-center relative z-10">
|
|
<i data-lucide="alert-triangle" class="w-12 h-12 mx-auto mb-4 text-red-400"></i>
|
|
<h2 class="text-lg font-black uppercase tracking-widest mb-2">Error de Identificación</h2>
|
|
<p class="text-sm font-medium">No se ha indicado ningún ID de expediente válido en la URL.</p>
|
|
<button onclick="window.history.back()" class="mt-6 bg-red-600 text-white px-6 py-2 rounded-xl font-bold hover:bg-red-700">Volver Atrás</button>
|
|
</div>
|
|
`;
|
|
lucide.createIcons();
|
|
return;
|
|
}
|
|
|
|
document.getElementById('svcRef').innerText = urlRef ? urlRef : `#${serviceId}`;
|
|
loadLogs();
|
|
});
|
|
|
|
async function loadLogs() {
|
|
try {
|
|
const res = await fetch(`${API_URL}/services/${serviceId}/logs`, {
|
|
headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` }
|
|
});
|
|
|
|
const data = await res.json();
|
|
const container = document.getElementById('timelineContainer');
|
|
|
|
if (!data.ok) throw new Error("Error cargando logs");
|
|
|
|
document.getElementById('logCount').innerText = `${data.logs.length} Registros`;
|
|
|
|
if (data.logs.length === 0) {
|
|
container.innerHTML = `
|
|
<div class="relative pl-14 pt-2 z-10">
|
|
<div class="absolute left-[17px] top-4 w-3 h-3 bg-slate-300 rounded-full ring-4 ring-white"></div>
|
|
<div class="bg-slate-100 border border-slate-200 p-6 rounded-2xl text-center">
|
|
<p class="text-sm font-bold text-slate-500 italic">No hay actividad registrada aún para este expediente.</p>
|
|
</div>
|
|
</div>
|
|
`;
|
|
return;
|
|
}
|
|
|
|
container.innerHTML = ""; // Limpiamos
|
|
|
|
data.logs.forEach((log, index) => {
|
|
const dateObj = new Date(log.created_at);
|
|
|
|
// Formateo de fecha molón: "Hoy a las 10:00" o "12 Mar 2025"
|
|
const hoy = new Date();
|
|
const esHoy = dateObj.getDate() === hoy.getDate() && dateObj.getMonth() === hoy.getMonth() && dateObj.getFullYear() === hoy.getFullYear();
|
|
|
|
const fecha = esHoy ? "Hoy" : dateObj.toLocaleDateString('es-ES', { day: '2-digit', month: 'short', year: 'numeric' });
|
|
const hora = dateObj.toLocaleTimeString('es-ES', { hour: '2-digit', minute: '2-digit' });
|
|
|
|
// LÓGICA INTELIGENTE DE COLORES E ICONOS
|
|
let icon = "activity";
|
|
let colorClass = "bg-slate-100 text-slate-600 border-slate-200";
|
|
let dotClass = "bg-slate-400 ring-slate-100";
|
|
let iconColor = "text-slate-500";
|
|
|
|
const actionLower = log.action.toLowerCase();
|
|
const detailsLower = (log.details || "").toLowerCase();
|
|
const fullText = actionLower + " " + detailsLower;
|
|
|
|
if (fullText.includes('estado') || fullText.includes('actualización')) {
|
|
icon = "arrow-right-left"; colorClass = "bg-blue-50 text-blue-700 border-blue-200"; dotClass = "bg-blue-500 ring-blue-100"; iconColor = "text-blue-500";
|
|
}
|
|
else if (fullText.includes('llamada') || fullText.includes('contacto') || fullText.includes('teléfono')) {
|
|
icon = "phone-call"; colorClass = "bg-teal-50 text-teal-700 border-teal-200"; dotClass = "bg-teal-500 ring-teal-100"; iconColor = "text-teal-500";
|
|
}
|
|
else if (fullText.includes('whatsapp') || fullText.includes('sms')) {
|
|
icon = "message-circle"; colorClass = "bg-emerald-50 text-emerald-700 border-emerald-200"; dotClass = "bg-emerald-500 ring-emerald-100"; iconColor = "text-emerald-500";
|
|
}
|
|
else if (fullText.includes('camino') || fullText.includes('ruta')) {
|
|
icon = "car"; colorClass = "bg-purple-50 text-purple-700 border-purple-200"; dotClass = "bg-purple-500 ring-purple-100"; iconColor = "text-purple-500";
|
|
}
|
|
else if (fullText.includes('nota') || fullText.includes('apunte') || fullText.includes('manual')) {
|
|
icon = "sticky-note"; colorClass = "bg-amber-50 text-amber-800 border-amber-200"; dotClass = "bg-amber-400 ring-amber-100"; iconColor = "text-amber-500";
|
|
}
|
|
else if (fullText.includes('asign') || fullText.includes('bolsa')) {
|
|
icon = "user-check"; colorClass = "bg-indigo-50 text-indigo-700 border-indigo-200"; dotClass = "bg-indigo-500 ring-indigo-100"; iconColor = "text-indigo-500";
|
|
}
|
|
else if (fullText.includes('archivado') || fullText.includes('cierre')) {
|
|
icon = "archive"; colorClass = "bg-slate-200 text-slate-700 border-slate-300"; dotClass = "bg-slate-600 ring-slate-200"; iconColor = "text-slate-600";
|
|
}
|
|
else if (fullText.includes('creado') || fullText.includes('presupuesto')) {
|
|
icon = "sparkles"; colorClass = "bg-yellow-50 text-yellow-700 border-yellow-200"; dotClass = "bg-yellow-500 ring-yellow-100"; iconColor = "text-yellow-500";
|
|
}
|
|
|
|
// El punto más reciente parpadea suavemente
|
|
const pingAnimation = index === 0 ? `<div class="absolute inset-0 rounded-full ${dotClass.split(' ')[0]} animate-ping opacity-50"></div>` : '';
|
|
|
|
container.innerHTML += `
|
|
<div class="relative pl-14 sm:pl-16 pt-2 pb-4 fade-in z-10" style="animation-delay: ${index * 0.05}s">
|
|
|
|
<div class="absolute left-[15px] top-6 w-4 h-4 rounded-full border-2 border-white ring-4 ${dotClass} z-20 flex items-center justify-center">
|
|
${pingAnimation}
|
|
</div>
|
|
|
|
<div class="bg-white border border-slate-200 p-5 rounded-3xl shadow-sm hover:shadow-md transition-all group">
|
|
<div class="flex flex-wrap justify-between items-start gap-4 mb-3">
|
|
<span class="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-xl text-[10px] font-black uppercase tracking-widest border ${colorClass}">
|
|
<i data-lucide="${icon}" class="w-3.5 h-3.5 ${iconColor}"></i> ${log.action}
|
|
</span>
|
|
|
|
<div class="text-right">
|
|
<p class="text-sm font-black text-slate-800">${hora}</p>
|
|
<p class="text-[10px] font-bold text-slate-400 uppercase tracking-widest">${fecha}</p>
|
|
</div>
|
|
</div>
|
|
|
|
<p class="text-sm text-slate-700 font-medium leading-relaxed bg-slate-50 p-3 rounded-xl border border-slate-100">${log.details}</p>
|
|
|
|
<div class="mt-3 flex items-center gap-2">
|
|
<div class="w-6 h-6 rounded-full bg-slate-800 text-white flex items-center justify-center text-[10px] font-black shrink-0 shadow-sm">
|
|
${log.user_name.charAt(0).toUpperCase()}
|
|
</div>
|
|
<p class="text-[10px] font-bold text-slate-400 uppercase tracking-widest">
|
|
Registrado por: <span class="text-slate-700">${log.user_name}</span>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
`;
|
|
});
|
|
|
|
lucide.createIcons();
|
|
|
|
} catch (error) {
|
|
console.error(error);
|
|
document.getElementById('timelineContainer').innerHTML = "<p class='text-red-500 pl-14 pt-4 font-bold relative z-10'>No se pudo conectar con el servidor.</p>";
|
|
}
|
|
}
|
|
|
|
async function addManualNote(btn) {
|
|
const input = document.getElementById('manualNoteInput');
|
|
const text = input.value.trim();
|
|
|
|
if (!text) {
|
|
showToast("⚠️ Escribe un apunte antes de guardar.");
|
|
input.focus();
|
|
return;
|
|
}
|
|
|
|
const originalHtml = btn.innerHTML;
|
|
btn.innerHTML = '<i data-lucide="loader-2" class="w-4 h-4 animate-spin"></i> Guardando...';
|
|
btn.disabled = true;
|
|
|
|
try {
|
|
const res = await fetch(`${API_URL}/services/${serviceId}/log`, {
|
|
method: 'POST',
|
|
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
|
|
body: JSON.stringify({
|
|
action: "Nota Manual",
|
|
details: text
|
|
})
|
|
});
|
|
|
|
if(res.ok) {
|
|
input.value = "";
|
|
showToast("✅ Apunte guardado correctamente");
|
|
loadLogs();
|
|
} else {
|
|
throw new Error("Error del servidor");
|
|
}
|
|
} catch (e) {
|
|
showToast("❌ Error al guardar la nota.");
|
|
} finally {
|
|
btn.innerHTML = originalHtml;
|
|
btn.disabled = false;
|
|
lucide.createIcons();
|
|
}
|
|
}
|
|
|
|
function showToast(msg) {
|
|
const t = document.getElementById('toast');
|
|
t.innerHTML = msg;
|
|
t.classList.remove('hidden');
|
|
setTimeout(() => t.classList.add('hidden'), 3000);
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |