Actualizar buscar.html

This commit is contained in:
2026-02-24 07:48:25 +00:00
parent 00daa302a0
commit 9ef7e71738

View File

@@ -49,7 +49,7 @@
<button onclick="document.getElementById('searchInput').value=''; renderServices();" class="absolute right-4 top-1/2 -translate-y-1/2 text-slate-400 hover:text-rose-500 hidden" id="clearBtn"><i data-lucide="x-circle" class="w-5 h-5"></i></button>
</div>
<div class="flex gap-2 w-full pt-1">
<div class="flex gap-2 w-full pt-1" id="tabsContainer">
<button onclick="setTab('mine')" id="tab-mine" class="flex-1 py-2.5 rounded-xl text-xs uppercase tracking-widest border transition-all tab-active">
Mis Asignados
</button>
@@ -135,6 +135,7 @@
let systemStatuses = [];
let systemGuilds = [];
let currentTab = 'mine'; // 'mine' o 'unassigned'
let isRestricted = false; // Control de bolsa
const colorDict = {
'gray': { bg: 'bg-slate-100', text: 'text-slate-600', dot: 'bg-slate-500', border: 'border-slate-200' },
@@ -166,9 +167,18 @@
}
document.addEventListener("DOMContentLoaded", async () => {
if (!localStorage.getItem("token") || localStorage.getItem("role") !== 'operario') {
const currentRole = localStorage.getItem("role");
if (!localStorage.getItem("token") || (currentRole !== 'operario' && currentRole !== 'operario_cerrado')) {
window.location.href = "index.html"; return;
}
// Ocultamos la pestaña de bolsa si el perfil es cerrado
if (currentRole === 'operario_cerrado') {
isRestricted = true;
const unassignedTab = document.getElementById('tab-unassigned');
if(unassignedTab) unassignedTab.style.display = 'none';
}
await applyTheme();
lucide.createIcons();
await loadStatuses();
@@ -219,20 +229,25 @@
const resMine = await fetch(`${API_URL}/services/active`, { headers });
const dataMine = await resMine.json();
// 2. Cargar todos los servicios para sacar la bolsa
let myItems = [];
if (dataMine.ok) {
myItems = dataMine.services.map(s => ({...s, _scope: 'mine'}));
}
// 2. Cargar todos los servicios para sacar la bolsa (SOLO SI NO ESTÁ RESTRINGIDO)
let unassignedItems = [];
if (!isRestricted) {
const resAll = await fetch(`${API_URL}/providers/scraped`, { headers });
const dataAll = await resAll.json();
if (dataMine.ok && dataAll.ok) {
const myItems = dataMine.services.map(s => ({...s, _scope: 'mine'}));
const unassignedItems = dataAll.services.filter(s => {
if (dataAll.ok) {
unassignedItems = dataAll.services.filter(s => {
return !s.assigned_to && s.status !== 'archived';
}).map(s => ({...s, _scope: 'unassigned'}));
}
}
allServices = [...myItems, ...unassignedItems].filter(s => s.provider !== 'SYSTEM_BLOCK');
renderServices();
}
} catch (e) {
alert("Error cargando los datos");
} finally {
@@ -483,7 +498,6 @@
t.classList.remove('translate-y-0');
}, 2500);
}
</script>
</body>
</html>