108 lines
4.6 KiB
HTML
108 lines
4.6 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="es">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Buzón Inteligente - Integra Repara</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
|
<style>
|
|
body { background-color: #f1f5f9; font-family: 'Inter', sans-serif; }
|
|
.service-card { border: none; border-radius: 12px; background: white; border-left: 6px solid #22c55e; margin-bottom: 1rem; }
|
|
.badge-provider { font-weight: 800; font-size: 0.7rem; padding: 4px 10px; border-radius: 20px; text-transform: uppercase; }
|
|
.homeserve { background: #fee2e2; color: #991b1b; }
|
|
.multiasistencia { background: #dbeafe; color: #1e40af; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="container py-5">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h2 class="fw-bold"><i class="fas fa-inbox text-primary me-2"></i>Buzón con Mapeo Activo</h2>
|
|
<button onclick="init()" class="btn btn-outline-primary rounded-pill"><i class="fas fa-sync-alt"></i></button>
|
|
</div>
|
|
|
|
<div id="inboxContainer"></div>
|
|
</div>
|
|
|
|
<script src="./js/layout.js"></script>
|
|
<script>
|
|
let userMappings = {};
|
|
|
|
async function init() {
|
|
const container = document.getElementById('inboxContainer');
|
|
container.innerHTML = '<div class="text-center py-5"><div class="spinner-border text-primary"></div><p>Aplicando tus reglas de mapeo...</p></div>';
|
|
|
|
try {
|
|
// 1. Cargamos los servicios detectados
|
|
const svcRes = await fetch(`${API_URL}/providers/scraped`, {
|
|
headers: { 'Authorization': `Bearer ${localStorage.getItem('token')}` }
|
|
});
|
|
const svcData = await svcRes.json();
|
|
|
|
// 2. Cargamos tus reglas de mapeo (el diccionario que hiciste)
|
|
const mapRes = await fetch(`${API_URL}/discovery/mappings`, {
|
|
headers: { 'Authorization': `Bearer ${localStorage.getItem('token')}` }
|
|
});
|
|
const mapData = await mapRes.json();
|
|
|
|
// Organizamos los mapeos por proveedor para acceso rápido
|
|
userMappings = mapData.reduce((acc, curr) => {
|
|
if (!acc[curr.provider]) acc[curr.provider] = {};
|
|
acc[curr.provider][curr.target_key] = curr.original_key;
|
|
return acc;
|
|
}, {});
|
|
|
|
renderInbox(svcData.services);
|
|
} catch (e) {
|
|
container.innerHTML = '<div class="alert alert-danger">Error al cargar datos o mapeos.</div>';
|
|
}
|
|
}
|
|
|
|
function renderInbox(services) {
|
|
const container = document.getElementById('inboxContainer');
|
|
if (!services || services.length === 0) {
|
|
container.innerHTML = '<p class="text-center">No hay servicios nuevos.</p>';
|
|
return;
|
|
}
|
|
|
|
container.innerHTML = '';
|
|
services.forEach(svc => {
|
|
const raw = svc.raw_data || {};
|
|
const provider = svc.provider;
|
|
const myMap = userMappings[provider] || {};
|
|
|
|
// APLICAMOS TU MAPEO: "Busca lo que yo te dije que es el nombre"
|
|
const name = raw[myMap['clientName']] || raw.clientName_fixed || "Sin nombre";
|
|
const addr = raw[myMap['address']] || raw.address_fixed || "Sin dirección";
|
|
const phone = raw[myMap['phone']] || raw.phone_fixed || "Sin teléfono";
|
|
|
|
const card = document.createElement('div');
|
|
card.className = 'service-card shadow-sm p-4 d-flex justify-content-between align-items-center';
|
|
card.innerHTML = `
|
|
<div>
|
|
<span class="badge-provider ${provider}">${provider}</span>
|
|
<h5 class="fw-bold mt-2 mb-1">${name}</h5>
|
|
<div class="small text-secondary">
|
|
<i class="fas fa-map-marker-alt"></i> ${addr} |
|
|
<i class="fas fa-phone"></i> ${phone}
|
|
</div>
|
|
</div>
|
|
<button onclick="importSvc(${svc.id})" class="btn btn-success fw-bold rounded-pill">IMPORTAR</button>
|
|
`;
|
|
container.appendChild(card);
|
|
});
|
|
}
|
|
|
|
async function importSvc(id) {
|
|
const res = await fetch(`${API_URL}/providers/import/${id}`, {
|
|
method: 'POST',
|
|
headers: { 'Authorization': `Bearer ${localStorage.getItem('token')}` }
|
|
});
|
|
const data = await res.json();
|
|
if(data.ok) { alert("¡Importado correctamente!"); init(); }
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', init);
|
|
</script>
|
|
</body>
|
|
</html> |