Actualizar trazabilidad.html
This commit is contained in:
@@ -12,7 +12,6 @@
|
|||||||
.no-scrollbar::-webkit-scrollbar { display: none; }
|
.no-scrollbar::-webkit-scrollbar { display: none; }
|
||||||
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
|
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
|
||||||
|
|
||||||
/* Línea continua del timeline */
|
|
||||||
.timeline-line::before {
|
.timeline-line::before {
|
||||||
content: ''; position: absolute; top: 0; bottom: 0; left: 23px; width: 2px; background: #e2e8f0; z-index: 0;
|
content: ''; position: absolute; top: 0; bottom: 0; left: 23px; width: 2px; background: #e2e8f0; z-index: 0;
|
||||||
}
|
}
|
||||||
@@ -107,8 +106,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="relative timeline-line ml-2 md:ml-4 pb-20" id="timelineContainer">
|
<div class="relative timeline-line ml-2 md:ml-4 pb-20" id="timelineContainer"></div>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</main>
|
</main>
|
||||||
@@ -121,8 +119,7 @@
|
|||||||
<script src="js/layout.js"></script>
|
<script src="js/layout.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const API_URL = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'
|
// API_URL ya viene declarada en layout.js, NO la declares de nuevo aquí.
|
||||||
|
|
||||||
|
|
||||||
let allServices = [];
|
let allServices = [];
|
||||||
let currentServiceId = null;
|
let currentServiceId = null;
|
||||||
@@ -131,7 +128,6 @@
|
|||||||
if (!localStorage.getItem("token")) window.location.href = "index.html";
|
if (!localStorage.getItem("token")) window.location.href = "index.html";
|
||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
|
|
||||||
// Ponemos el mes actual por defecto
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const currentMonthStr = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}`;
|
const currentMonthStr = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}`;
|
||||||
document.getElementById('monthBox').value = currentMonthStr;
|
document.getElementById('monthBox').value = currentMonthStr;
|
||||||
@@ -139,7 +135,6 @@
|
|||||||
loadAllServices();
|
loadAllServices();
|
||||||
});
|
});
|
||||||
|
|
||||||
// 1. CARGAMOS TODOS LOS SERVICIOS AL ENTRAR
|
|
||||||
async function loadAllServices() {
|
async function loadAllServices() {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_URL}/providers/scraped`, {
|
const res = await fetch(`${API_URL}/providers/scraped`, {
|
||||||
@@ -149,9 +144,8 @@
|
|||||||
|
|
||||||
if (data.ok && data.services) {
|
if (data.ok && data.services) {
|
||||||
allServices = data.services;
|
allServices = data.services;
|
||||||
renderServices(); // Pintamos la lista
|
renderServices();
|
||||||
|
|
||||||
// Si nos pasaron un ID por la URL, lo seleccionamos automáticamente
|
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
const paramId = urlParams.get('id');
|
const paramId = urlParams.get('id');
|
||||||
if (paramId) {
|
if (paramId) {
|
||||||
@@ -169,11 +163,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. PINTAR LA LISTA LATERAL CON FILTROS
|
|
||||||
function renderServices() {
|
function renderServices() {
|
||||||
const list = document.getElementById('servicesList');
|
const list = document.getElementById('servicesList');
|
||||||
const search = document.getElementById('searchBox').value.toLowerCase();
|
const search = document.getElementById('searchBox').value.toLowerCase();
|
||||||
const month = document.getElementById('monthBox').value; // Formato YYYY-MM
|
const month = document.getElementById('monthBox').value;
|
||||||
|
|
||||||
const filtered = allServices.filter(s => {
|
const filtered = allServices.filter(s => {
|
||||||
const raw = s.raw_data || {};
|
const raw = s.raw_data || {};
|
||||||
@@ -187,7 +180,6 @@
|
|||||||
matchesMonth = svcDate === month;
|
matchesMonth = svcDate === month;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Omitir bloqueos de agenda
|
|
||||||
return matchesSearch && matchesMonth && s.provider !== 'SYSTEM_BLOCK';
|
return matchesSearch && matchesMonth && s.provider !== 'SYSTEM_BLOCK';
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -229,14 +221,10 @@
|
|||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. AL HACER CLIC EN UN SERVICIO, CARGAMOS SU TIMELINE
|
|
||||||
function selectService(id, ref, statusText) {
|
function selectService(id, ref, statusText) {
|
||||||
currentServiceId = id;
|
currentServiceId = id;
|
||||||
|
|
||||||
// Actualizamos la lista para pintar de azul el seleccionado
|
|
||||||
renderServices();
|
renderServices();
|
||||||
|
|
||||||
// Actualizar URL sin recargar para que si refresca se quede donde estaba
|
|
||||||
const newUrl = new URL(window.location);
|
const newUrl = new URL(window.location);
|
||||||
newUrl.searchParams.set('id', id);
|
newUrl.searchParams.set('id', id);
|
||||||
window.history.pushState({}, '', newUrl);
|
window.history.pushState({}, '', newUrl);
|
||||||
@@ -294,7 +282,6 @@
|
|||||||
const fecha = esHoy ? "Hoy" : dateObj.toLocaleDateString('es-ES', { day: '2-digit', month: 'short', year: 'numeric' });
|
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' });
|
const hora = dateObj.toLocaleTimeString('es-ES', { hour: '2-digit', minute: '2-digit' });
|
||||||
|
|
||||||
// Lógica de colores del timeline
|
|
||||||
let icon = "activity";
|
let icon = "activity";
|
||||||
let colorClass = "bg-slate-100 text-slate-600 border-slate-200";
|
let colorClass = "bg-slate-100 text-slate-600 border-slate-200";
|
||||||
let dotClass = "bg-slate-300 ring-slate-100";
|
let dotClass = "bg-slate-300 ring-slate-100";
|
||||||
@@ -344,7 +331,6 @@
|
|||||||
`;
|
`;
|
||||||
});
|
});
|
||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
|
|
||||||
} catch (error) {
|
} catch (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>";
|
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>";
|
||||||
}
|
}
|
||||||
@@ -352,37 +338,29 @@
|
|||||||
|
|
||||||
async function addManualNote(btn) {
|
async function addManualNote(btn) {
|
||||||
if (!currentServiceId) return showToast("⚠️ Selecciona un expediente primero.");
|
if (!currentServiceId) return showToast("⚠️ Selecciona un expediente primero.");
|
||||||
|
|
||||||
const input = document.getElementById('manualNoteInput');
|
const input = document.getElementById('manualNoteInput');
|
||||||
const text = input.value.trim();
|
const text = input.value.trim();
|
||||||
|
|
||||||
if (!text) {
|
if (!text) {
|
||||||
showToast("⚠️ Escribe un apunte antes de guardar.");
|
showToast("⚠️ Escribe un apunte antes de guardar.");
|
||||||
input.focus();
|
input.focus();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const originalHtml = btn.innerHTML;
|
const originalHtml = btn.innerHTML;
|
||||||
btn.innerHTML = '<i data-lucide="loader-2" class="w-4 h-4 animate-spin"></i> Guardando...';
|
btn.innerHTML = '<i data-lucide="loader-2" class="w-4 h-4 animate-spin"></i> Guardando...';
|
||||||
btn.disabled = true;
|
btn.disabled = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_URL}/services/${currentServiceId}/log`, {
|
const res = await fetch(`${API_URL}/services/${currentServiceId}/log`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
|
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
|
||||||
body: JSON.stringify({ action: "Nota Manual", details: text })
|
body: JSON.stringify({ action: "Nota Manual", details: text })
|
||||||
});
|
});
|
||||||
|
|
||||||
if(res.ok) {
|
if(res.ok) {
|
||||||
input.value = "";
|
input.value = "";
|
||||||
showToast("✅ Apunte guardado correctamente");
|
showToast("✅ Apunte guardado correctamente");
|
||||||
loadLogsForService(currentServiceId);
|
loadLogsForService(currentServiceId);
|
||||||
} else {
|
} else { throw new Error("Error del servidor"); }
|
||||||
throw new Error("Error del servidor");
|
} catch (e) { showToast("❌ Error al guardar la nota."); }
|
||||||
}
|
finally {
|
||||||
} catch (e) {
|
|
||||||
showToast("❌ Error al guardar la nota.");
|
|
||||||
} finally {
|
|
||||||
btn.innerHTML = originalHtml;
|
btn.innerHTML = originalHtml;
|
||||||
btn.disabled = false;
|
btn.disabled = false;
|
||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
|
|||||||
Reference in New Issue
Block a user