diff --git a/dashboard/dashboard.js b/dashboard/dashboard.js index 53be5d8..1caa1d3 100644 --- a/dashboard/dashboard.js +++ b/dashboard/dashboard.js @@ -41,37 +41,31 @@ class VehicleDashboard { async loadStats() { try { - const [brandsRes, vehiclesRes, partsRes, categoriesRes] = await Promise.all([ + const [statsRes, brandsRes, categoriesRes] = await Promise.all([ + fetch('/api/catalog/stats'), fetch('/api/brands'), - fetch('/api/vehicles'), - fetch('/api/parts'), fetch('/api/categories') ]); - if (brandsRes.ok && vehiclesRes.ok) { - const brands = await brandsRes.json(); - const vehiclesData = await vehiclesRes.json(); - const vehicles = vehiclesData.data || vehiclesData; - - // Contar modelos únicos - const uniqueModels = new Set(vehicles.map(v => `${v.brand}-${v.model}`)); - - this.stats.brands = brands.length; - this.stats.models = uniqueModels.size; - this.stats.vehicles = vehiclesData.pagination ? vehiclesData.pagination.total : vehicles.length; + if (statsRes.ok) { + const s = await statsRes.json(); + this.stats.brands = s.brands; + this.stats.models = s.models; + this.stats.vehicles = s.vehicles; + this.stats.parts = s.parts; + const fmt = n => n > 1000 ? Math.floor(n/1000) + 'K+' : n; const brandsEl = document.getElementById('totalBrands'); const modelsEl = document.getElementById('totalModels'); - if (brandsEl) brandsEl.textContent = this.stats.brands; - if (modelsEl) modelsEl.textContent = this.stats.models > 1000 ? Math.floor(this.stats.models/1000) + 'K+' : this.stats.models; + const partsEl = document.getElementById('totalParts'); + if (brandsEl) brandsEl.textContent = fmt(this.stats.brands); + if (modelsEl) modelsEl.textContent = fmt(this.stats.models); + if (partsEl) partsEl.textContent = fmt(this.stats.parts); } - if (partsRes.ok) { - const partsData = await partsRes.json(); - // Handle paginated response - this.stats.parts = partsData.pagination ? partsData.pagination.total : (partsData.data ? partsData.data.length : partsData.length || 0); - const partsEl = document.getElementById('totalParts'); - if (partsEl) partsEl.textContent = this.stats.parts; + if (brandsRes.ok) { + // Still needed for brand list rendering + await brandsRes.json(); } if (categoriesRes.ok) { @@ -1144,6 +1138,11 @@ class VehicleDashboard {

${part.name_es || part.name || 'Sin nombre'}

+ ${part.image_url ? ` +
+ ${part.oem_part_number || ''} +
+ ` : ''}
Número OEM ${part.oem_part_number || 'N/A'} diff --git a/dashboard/demo.html b/dashboard/demo.html new file mode 100644 index 0000000..c6e7296 --- /dev/null +++ b/dashboard/demo.html @@ -0,0 +1,1221 @@ + + + + + + NEXUS AUTOPARTS — Catálogo OEM + + + + +
+ + + DEMO +
+ +
+ +

+

+
+
+ + + + + + +