Actualizar agenda.html
This commit is contained in:
120
agenda.html
120
agenda.html
@@ -122,35 +122,7 @@
|
||||
<div id="pastBlocksList" class="space-y-3 mt-4 opacity-80 grayscale-[20%]">
|
||||
<p class="text-sm text-slate-400 font-medium">Cargando...</p>
|
||||
</div>
|
||||
<div class="bg-white p-5 rounded-2xl border border-slate-200 shadow-sm flex flex-col md:flex-row items-center justify-between mt-8 gap-4">
|
||||
<div class="flex items-center gap-3 w-full md:w-auto">
|
||||
<div class="bg-blue-50 p-2.5 rounded-xl text-blue-600 shrink-0">
|
||||
<i data-lucide="calendar-search" class="w-5 h-5"></i>
|
||||
</div>
|
||||
<div>
|
||||
<h3 class="text-sm font-black text-slate-800 uppercase tracking-widest leading-none">Filtrar por Mes</h3>
|
||||
<p class="text-[10px] text-slate-500 font-medium mt-1">Busca bloqueos pasados o futuros</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-3 w-full md:w-auto">
|
||||
<input type="month" id="blockMonthFilter" onchange="loadActiveBlocks()" class="w-full md:w-auto bg-slate-50 border border-slate-200 text-sm font-bold text-slate-700 p-3 rounded-xl outline-none focus:ring-2 focus:ring-blue-500 cursor-pointer transition-all">
|
||||
<button onclick="document.getElementById('blockMonthFilter').value=''; loadActiveBlocks();" class="text-xs font-bold text-slate-400 hover:text-red-500 transition-colors shrink-0">Ver Todos</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h3 class="font-black text-slate-800 text-lg flex items-center gap-2 mt-8">
|
||||
<i data-lucide="shield" class="w-5 h-5 text-rose-500"></i> Bloqueos Activos a Futuro
|
||||
</h3>
|
||||
<div id="blocksList" class="space-y-3 mt-4">
|
||||
<p class="text-sm text-slate-400 font-medium">Cargando...</p>
|
||||
</div>
|
||||
|
||||
<h3 class="font-black text-slate-800 text-lg flex items-center gap-2 mt-12 opacity-60 border-t border-slate-200 pt-6">
|
||||
<i data-lucide="history" class="w-5 h-5 text-slate-400"></i> Historial Pasado
|
||||
</h3>
|
||||
<div id="pastBlocksList" class="space-y-3 mt-4 opacity-80 grayscale-[20%]">
|
||||
<p class="text-sm text-slate-400 font-medium">Cargando...</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@@ -398,79 +370,45 @@
|
||||
} catch(e) { alert("Error de conexión"); }
|
||||
}
|
||||
|
||||
async function loadActiveBlocks() {
|
||||
const activeContainer = document.getElementById('blocksList');
|
||||
const pastContainer = document.getElementById('pastBlocksList');
|
||||
|
||||
// Leemos el valor del filtro de mes (Ej: "2026-02")
|
||||
const monthFilter = document.getElementById('blockMonthFilter').value;
|
||||
|
||||
async function loadActiveBlocks() {
|
||||
const container = document.getElementById('blocksList');
|
||||
try {
|
||||
const res = await fetch(`${API_URL}/agenda/blocks`, {
|
||||
headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` }
|
||||
});
|
||||
const data = await res.json();
|
||||
|
||||
if (!data.ok) throw new Error("Error fetching blocks");
|
||||
|
||||
let allBlocks = data.blocks;
|
||||
|
||||
// 🧠 APLICAMOS EL FILTRO POR MES SI HAY ALGUNO SELECCIONADO
|
||||
if (monthFilter) {
|
||||
// Nos quedamos solo con los bloqueos cuya fecha empiece por "YYYY-MM"
|
||||
allBlocks = allBlocks.filter(b => b.date.startsWith(monthFilter));
|
||||
if (!data.ok || data.blocks.length === 0) {
|
||||
container.innerHTML = `<p class="text-sm text-slate-400 italic">No hay bloqueos activos a futuro.</p>`;
|
||||
return;
|
||||
}
|
||||
|
||||
// Sacamos la fecha de hoy (YYYY-MM-DD) para comparar
|
||||
const todayStr = new Date().toISOString().split('T')[0];
|
||||
container.innerHTML = data.blocks.map(b => {
|
||||
// Etiqueta visual si es de un gremio concreto o total
|
||||
const badge = b.guild_name
|
||||
? `<span class="bg-indigo-100 text-indigo-700 px-2 py-0.5 rounded text-[9px] uppercase tracking-widest font-black">Solo ${b.guild_name}</span>`
|
||||
: `<span class="bg-rose-100 text-rose-700 px-2 py-0.5 rounded text-[9px] uppercase tracking-widest font-black">Bloqueo Total</span>`;
|
||||
|
||||
const activeBlocks = allBlocks.filter(b => b.date >= todayStr).reverse();
|
||||
const pastBlocks = allBlocks.filter(b => b.date < todayStr);
|
||||
|
||||
// Pintar Activos
|
||||
if (activeBlocks.length === 0) {
|
||||
activeContainer.innerHTML = `<p class="text-sm text-slate-400 italic bg-white p-4 rounded-xl border border-slate-200 text-center shadow-sm">No hay bloqueos activos en este periodo.</p>`;
|
||||
} else {
|
||||
activeContainer.innerHTML = activeBlocks.map(b => buildBlockHtml(b, false)).join('');
|
||||
}
|
||||
|
||||
// Pintar Caducados
|
||||
if (pastBlocks.length === 0) {
|
||||
pastContainer.innerHTML = `<p class="text-sm text-slate-400 italic bg-transparent p-4 text-center">No hay bloqueos antiguos en este periodo.</p>`;
|
||||
} else {
|
||||
pastContainer.innerHTML = pastBlocks.map(b => buildBlockHtml(b, true)).join('');
|
||||
}
|
||||
|
||||
lucide.createIcons();
|
||||
} catch(e) {
|
||||
activeContainer.innerHTML = "Error cargando";
|
||||
pastContainer.innerHTML = "Error cargando";
|
||||
}
|
||||
}
|
||||
|
||||
// Helper visual para pintar la tarjeta según sea activa o caducada
|
||||
function buildBlockHtml(b, isPast) {
|
||||
const badge = b.guild_name
|
||||
? `<span class="bg-indigo-100 text-indigo-700 px-2 py-0.5 rounded text-[9px] uppercase tracking-widest font-black">Solo ${b.guild_name}</span>`
|
||||
: `<span class="bg-rose-100 text-rose-700 px-2 py-0.5 rounded text-[9px] uppercase tracking-widest font-black">Bloqueo Total</span>`;
|
||||
|
||||
return `
|
||||
<div class="bg-white p-4 rounded-xl border ${isPast ? 'border-slate-100 shadow-none' : 'border-slate-200 shadow-sm'} flex justify-between items-center transition-all hover:border-red-200">
|
||||
<div>
|
||||
<div class="flex items-center gap-2">
|
||||
<p class="font-black ${isPast ? 'text-slate-500' : 'text-slate-800'} flex items-center gap-1.5">
|
||||
<i data-lucide="hard-hat" class="w-4 h-4 ${isPast ? 'text-slate-300' : 'text-slate-400'}"></i> ${b.worker_name}
|
||||
</p>
|
||||
${badge}
|
||||
return `
|
||||
<div class="bg-white p-4 rounded-xl border border-slate-200 flex justify-between items-center shadow-sm">
|
||||
<div>
|
||||
<div class="flex items-center gap-2">
|
||||
<p class="font-black text-slate-800 flex items-center gap-1.5">
|
||||
<i data-lucide="hard-hat" class="w-4 h-4 text-slate-400"></i> ${b.worker_name}
|
||||
</p>
|
||||
${badge}
|
||||
</div>
|
||||
<p class="text-xs text-slate-600 font-bold mt-1.5">${b.date} | ${b.time} (${b.duration} min)</p>
|
||||
<p class="text-[10px] text-slate-500 uppercase mt-0.5">${b.reason}</p>
|
||||
</div>
|
||||
<button onclick="deleteBlock(${b.id})" class="text-slate-300 hover:text-red-500 p-2 transition-colors">
|
||||
<i data-lucide="trash-2" class="w-5 h-5"></i>
|
||||
</button>
|
||||
</div>
|
||||
<p class="text-xs ${isPast ? 'text-slate-400' : 'text-slate-600'} font-bold mt-1.5">${b.date} | ${b.time} (${b.duration} min)</p>
|
||||
<p class="text-[10px] text-slate-400 uppercase mt-0.5">${b.reason || 'Sin motivo especificado'}</p>
|
||||
</div>
|
||||
<button onclick="deleteBlock(${b.id})" class="text-slate-300 hover:text-red-500 bg-slate-50 hover:bg-red-50 p-2.5 rounded-lg transition-colors">
|
||||
<i data-lucide="trash-2" class="w-4 h-4"></i>
|
||||
</button>
|
||||
</div>
|
||||
`;
|
||||
`;
|
||||
}).join('');
|
||||
lucide.createIcons();
|
||||
} catch(e) { container.innerHTML = "Error"; }
|
||||
}
|
||||
|
||||
async function deleteBlock(id) {
|
||||
|
||||
Reference in New Issue
Block a user