@@ -153,7 +156,7 @@
function safeLoadIcons() {
try { if (typeof lucide !== 'undefined') lucide.createIcons(); }
- catch(e) { console.warn("Iconos no cargados aún"); }
+ catch(e) { console.warn("Iconos no cargados"); }
}
function toISODate(dateObj) {
@@ -177,7 +180,6 @@
if (!localStorage.getItem("token") || localStorage.getItem("role") !== 'operario') {
window.location.href = "index.html"; return;
}
-
safeLoadIcons();
try {
@@ -186,16 +188,12 @@
selectedDateStr = toISODate(today);
buildWeekCalendar();
- // Cargar datos paralelos
loadStatuses();
await loadGuilds();
refreshData();
- } catch(error) {
- alert("Error iniciando calendario: " + error.message);
- }
+ } catch(error) { alert("Error iniciando calendario"); }
});
- // Cargar gremios para saber los nombres
async function loadGuilds() {
try {
const res = await fetch(`${API_URL}/guilds`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
@@ -235,7 +233,7 @@
}
if(localServices.length > 0) updateBadges();
safeLoadIcons();
- } catch(e) { console.error(e); }
+ } catch(e) {}
}
function changeWeek(offsetWeeks) {
@@ -256,7 +254,7 @@
const res = await fetch(`${API_URL}/statuses`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
const data = await res.json();
if (data.ok) systemStatuses = data.statuses;
- } catch (e) { console.error("Error estados:", e); }
+ } catch (e) {}
}
async function refreshData() {
@@ -275,12 +273,10 @@
const dateStr = String(raw.scheduled_date || "").trim();
return dateStr !== "";
});
-
buildWeekCalendar();
renderServices();
}
} catch (e) {
- console.error(e);
} finally {
document.getElementById('loader').classList.add('hidden');
document.getElementById('dayTitle').classList.remove('hidden');
@@ -290,13 +286,11 @@
function updateBadges() {
document.querySelectorAll('[id^="badge-"]').forEach(el => el.classList.add('hidden'));
-
const counts = {};
localServices.forEach(s => {
const date = String(s.raw_data.scheduled_date || "").trim();
if(date) counts[date] = (counts[date] || 0) + 1;
});
-
for (const [date, qty] of Object.entries(counts)) {
const badge = document.getElementById(`badge-${date}`);
if (badge) badge.classList.remove('hidden');
@@ -335,7 +329,6 @@
const raw = s.raw_data || {};
const time = raw.scheduled_time || "A convenir";
- // BLOQUEOS
if (s.provider === 'SYSTEM_BLOCK') {
const desc = raw["Descripción"] || "Operario no disponible";
return `
@@ -351,13 +344,11 @@
`;
}
- // SERVICIOS NORMALES
const name = raw["Nombre Cliente"] || raw["CLIENTE"] || "Asegurado";
const addr = raw["Dirección"] || "Sin dirección";
const pop = raw["Población"] || "";
const isUrgent = s.is_urgent;
- // Extracción Compañía y Gremio
let compRaw = raw["Compañía"] || raw["COMPAÑIA"] || raw["Procedencia"] || "Particular";
let compShort = compRaw.split('-')[0].trim().substring(0, 15);
if(compRaw.includes("MULTI")) compShort = "MULTIASISTENCIA";
@@ -395,9 +386,6 @@
} catch(e) { console.error("Render error:", e); }
}
- // ==========================================
- // LÓGICA DEL MODAL Y GPS
- // ==========================================
let currentServiceId = null;
function openService(id) {
@@ -413,18 +401,16 @@
const fullAddress = `${raw["Dirección"] || ""}, ${raw["Código Postal"] || ""} ${raw["Población"] || ""}`;
document.getElementById('detAddress').innerText = fullAddress;
- // VOLCAR TODOS LOS DATOS EXTRA
const detailsContainer = document.getElementById('detExtraInfo');
let detailsHtml = '';
- // Ignoramos los campos que ya están enseñados arriba por defecto
- const skipKeys = ["Nombre Cliente", "CLIENTE", "Dirección", "DOMICILIO", "Población", "POBLACION-PROVINCIA", "scheduled_date", "scheduled_time", "status_operativo", "assigned_to", "guild_id", "Código Postal"];
+ const skipKeys = ["Nombre Cliente", "CLIENTE", "Dirección", "DOMICILIO", "Población", "POBLACION-PROVINCIA", "scheduled_date", "scheduled_time", "status_operativo", "assigned_to", "guild_id", "Código Postal", "assigned_to_name"];
for(let key in raw) {
if(skipKeys.includes(key)) continue;
let val = raw[key];
- if(typeof val === 'object') val = JSON.stringify(val); // Por si es un JSON anidado
+ if(typeof val === 'object') val = JSON.stringify(val);
if(!val || val.trim() === "") continue;
detailsHtml += `
@@ -438,12 +424,10 @@
if(detailsHtml === '') detailsHtml = '
No hay más datos proporcionados.
';
detailsContainer.innerHTML = detailsHtml;
- // Mostrar modal
const modal = document.getElementById('serviceModal');
modal.classList.remove('hidden');
setTimeout(() => modal.classList.remove('translate-y-full'), 10);
- // Iniciar GPS automático
calculateDistance(fullAddress);
}
@@ -457,14 +441,12 @@
async function calculateDistance(destAddress) {
if(!navigator.geolocation) { showGpsError("GPS no soportado"); return; }
-
navigator.geolocation.getCurrentPosition(async (position) => {
const userLat = position.coords.latitude;
const userLon = position.coords.longitude;
try {
const res = await fetch(`https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(destAddress + ', España')}`);
const data = await res.json();
-
if (data && data.length > 0) {
const destLat = parseFloat(data[0].lat);
const destLon = parseFloat(data[0].lon);