Actualizar buscar.html
This commit is contained in:
43
buscar.html
43
buscar.html
@@ -134,8 +134,8 @@
|
||||
let allServices = [];
|
||||
let systemStatuses = [];
|
||||
let systemGuilds = [];
|
||||
let currentTab = 'mine'; // 'mine' o 'unassigned'
|
||||
let isRestricted = false; // Control de bolsa
|
||||
let currentTab = 'mine';
|
||||
let isRestricted = false; // Bandera de seguridad
|
||||
|
||||
const colorDict = {
|
||||
'gray': { bg: 'bg-slate-100', text: 'text-slate-600', dot: 'bg-slate-500', border: 'border-slate-200' },
|
||||
@@ -159,7 +159,7 @@
|
||||
localStorage.setItem('app_theme', JSON.stringify(theme));
|
||||
}
|
||||
if(theme) {
|
||||
document.documentElement.style.setProperty('--primary', '#8b5cf6'); // Purpura para buscar.html
|
||||
document.documentElement.style.setProperty('--primary', '#8b5cf6');
|
||||
document.documentElement.style.setProperty('--secondary', theme.secondary);
|
||||
document.documentElement.style.setProperty('--app-bg', theme.bg);
|
||||
}
|
||||
@@ -167,25 +167,38 @@
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", async () => {
|
||||
const currentRole = localStorage.getItem("role");
|
||||
if (!localStorage.getItem("token") || (currentRole !== 'operario' && currentRole !== 'operario_cerrado')) {
|
||||
if (!localStorage.getItem("token") || localStorage.getItem("role") !== 'operario') {
|
||||
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();
|
||||
|
||||
// PRIMERO VERIFICAMOS EL ROL REAL EN EL SERVIDOR
|
||||
await checkUserRole();
|
||||
|
||||
await loadStatuses();
|
||||
await loadGuilds();
|
||||
loadAllData();
|
||||
});
|
||||
|
||||
async function checkUserRole() {
|
||||
try {
|
||||
const res = await fetch(`${API_URL}/auth/me`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
||||
const data = await res.json();
|
||||
if (data.ok && data.user) {
|
||||
// SI ES OPERARIO CERRADO, ACTIVAMOS MODO RESTRINGIDO
|
||||
if (data.user.role === 'operario_cerrado') {
|
||||
isRestricted = true;
|
||||
// Ocultamos la pestaña de la bolsa inmediatamente
|
||||
const tabBolsa = document.getElementById('tab-unassigned');
|
||||
if(tabBolsa) tabBolsa.style.display = 'none';
|
||||
// Forzamos la pestaña 'mine'
|
||||
setTab('mine');
|
||||
}
|
||||
}
|
||||
} catch(e) { console.error("Error verificando rol"); }
|
||||
}
|
||||
|
||||
function setTab(tabName) {
|
||||
currentTab = tabName;
|
||||
const btnMine = document.getElementById('tab-mine');
|
||||
@@ -225,7 +238,7 @@
|
||||
try {
|
||||
const headers = { "Authorization": `Bearer ${localStorage.getItem("token")}` };
|
||||
|
||||
// 1. Cargar mis servicios asignados
|
||||
// 1. Cargar mis servicios asignados (SIEMPRE)
|
||||
const resMine = await fetch(`${API_URL}/services/active`, { headers });
|
||||
const dataMine = await resMine.json();
|
||||
|
||||
@@ -234,8 +247,8 @@
|
||||
myItems = dataMine.services.map(s => ({...s, _scope: 'mine'}));
|
||||
}
|
||||
|
||||
// 2. Cargar todos los servicios para sacar la bolsa (SOLO SI NO ESTÁ RESTRINGIDO)
|
||||
let unassignedItems = [];
|
||||
// 2. Cargar bolsa libre SOLO SI NO ESTÁ RESTRINGIDO
|
||||
if (!isRestricted) {
|
||||
const resAll = await fetch(`${API_URL}/providers/scraped`, { headers });
|
||||
const dataAll = await resAll.json();
|
||||
|
||||
Reference in New Issue
Block a user