From 5c815bc2f5971c8f7d55ed2bb2bf5a74d25d077c Mon Sep 17 00:00:00 2001 From: consultoria-as Date: Tue, 26 May 2026 09:32:27 +0000 Subject: [PATCH] feat(ui): ML status cards with sparklines, Kanban order view in marketplace_external --- pos/static/js/marketplace_external.js | 71 +++++++++++++++++++++++++ pos/templates/marketplace_external.html | 6 ++- 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/pos/static/js/marketplace_external.js b/pos/static/js/marketplace_external.js index 9774f8a..4f09022 100644 --- a/pos/static/js/marketplace_external.js +++ b/pos/static/js/marketplace_external.js @@ -380,6 +380,77 @@ })(); } + // ML Status Cards (sparkline simulation) + window.loadMeliStats = async function() { + var container = document.getElementById('meliStatsBar'); + if (!container) return; + try { + var res = await fetch(API + '/listings?page=1&per_page=200', { headers: headers() }); + if (!res.ok) throw new Error('Failed'); + var data = await res.json(); + var items = data.items || []; + var active = items.filter(function(l) { return l.external_status === 'active'; }).length; + var paused = items.filter(function(l) { return l.external_status === 'paused'; }).length; + var closed = items.filter(function(l) { return l.external_status === 'closed'; }).length; + var total = items.length; + + var html = '
' + + '
Activas
' + active + '
' + + '
Pausadas
' + paused + '
' + + '
Cerradas
' + closed + '
' + + '
Total
' + total + '
'; + // Sparkline simulation + html += '
Tendencia
'; + html += '
'; + container.innerHTML = html; + if (typeof renderSparkline === 'function') { + renderSparkline('#meliSparkline', [active, paused, closed, total % 50, active - 2, paused + 1, closed, active], { prefix: '' }); + } + } catch(e) { + container.innerHTML = ''; + } + }; + + // Kanban Order View + var _orderViewMode = 'table'; + window.toggleOrderView = function() { + _orderViewMode = _orderViewMode === 'table' ? 'kanban' : 'table'; + document.getElementById('ordersTableView').style.display = _orderViewMode === 'table' ? '' : 'none'; + document.getElementById('ordersKanbanView').style.display = _orderViewMode === 'kanban' ? '' : 'none'; + document.getElementById('btnKanbanView').textContent = _orderViewMode === 'table' ? '📋 Kanban' : '📄 Tabla'; + if (_orderViewMode === 'kanban') renderKanbanOrders(); + }; + + function renderKanbanOrders() { + var container = document.getElementById('ordersKanbanView'); + if (!container) return; + var columns = [ + { key: 'pending', label: 'Pendientes', badge: 'badge--pending' }, + { key: 'confirmed', label: 'Confirmadas', badge: 'badge--ok' }, + { key: 'packed', label: 'Empacadas', badge: 'badge--transit' }, + { key: 'shipped', label: 'Enviadas', badge: 'badge--transit' }, + { key: 'delivered', label: 'Entregadas', badge: 'badge--complete' }, + { key: 'cancelled', label: 'Canceladas', badge: 'badge--cancelled' }, + ]; + var html = '
'; + columns.forEach(function(col) { + var items = ordersData.filter(function(o) { return o.status === col.key; }); + html += '
'; + html += '
' + col.label + '' + items.length + '
'; + html += '
'; + items.slice(0, 20).forEach(function(o) { + html += '
' + + '
' + escapeHtml(o.buyer_name || o.buyer_nickname || '—') + '
' + + '
$' + (o.total_amount || 0).toFixed(2) + ' · ' + escapeHtml(o.external_order_id || '') + '
' + + '
'; + }); + if (items.length > 20) html += '
+' + (items.length - 20) + ' más
'; + html += '
'; + }); + html += '
'; + container.innerHTML = html; + } + // Register Cmd+K items if (typeof registerCmdKItem === 'function') { registerCmdKItem({ group: 'MercadoLibre', label: 'Configuración ML', href: '/pos/marketplace-external', icon: '⚙️' }); diff --git a/pos/templates/marketplace_external.html b/pos/templates/marketplace_external.html index 64b2c4e..6bada57 100644 --- a/pos/templates/marketplace_external.html +++ b/pos/templates/marketplace_external.html @@ -254,8 +254,10 @@
+ +
@@ -277,9 +279,11 @@
+ -
+ +