up
This commit is contained in:
+83
-77
@@ -1404,19 +1404,11 @@ class SimpleWhatsAppManager {
|
||||
|
||||
this.log(`Enviando mensaje a ${recipient}: ${JSON.stringify(messageData)}`);
|
||||
|
||||
// Preguntar al usuario si quiere envío real o simulado
|
||||
const sendReal = confirm('¿Enviar mensaje REAL por WhatsApp?\n\nSí = Envío real\nNo = Envío simulado (debug)');
|
||||
|
||||
// Enviar mensaje
|
||||
const response = sendReal
|
||||
? await this.apiCallReal('send_message.php', {
|
||||
method: 'POST',
|
||||
body: messageData
|
||||
})
|
||||
: await this.apiCall('send_message.php', {
|
||||
method: 'POST',
|
||||
body: messageData
|
||||
});
|
||||
// Enviar mensaje por WhatsApp
|
||||
const response = await this.apiCallReal('send_message.php', {
|
||||
method: 'POST',
|
||||
body: messageData
|
||||
});
|
||||
|
||||
if (response && response.success) {
|
||||
this.showSuccess(`Mensaje enviado correctamente a ${recipient}`);
|
||||
@@ -1474,28 +1466,50 @@ class SimpleWhatsAppManager {
|
||||
if (!log) return null;
|
||||
|
||||
const tr = document.createElement('tr');
|
||||
tr.setAttribute('data-level', (log.level || 'INFO').toUpperCase());
|
||||
tr.setAttribute('data-message', (log.message || log.mensaje || '').toLowerCase());
|
||||
tr.setAttribute('data-source', (log.source || log.origen || '').toLowerCase());
|
||||
|
||||
// Fecha y hora
|
||||
const tdDateTime = document.createElement('td');
|
||||
tdDateTime.textContent = log.datetime || log.created_at || 'N/A';
|
||||
const dateStr = log.datetime || log.created_at || 'N/A';
|
||||
tdDateTime.innerHTML = `<small class="text-muted">${dateStr}</small>`;
|
||||
tr.appendChild(tdDateTime);
|
||||
|
||||
// Nivel
|
||||
const tdLevel = document.createElement('td');
|
||||
const level = (log.level || log.tipo || 'INFO').toUpperCase();
|
||||
const levelIcon = {
|
||||
'ERROR': '❌',
|
||||
'WARNING': '⚠️',
|
||||
'INFO': 'ℹ️',
|
||||
'DEBUG': '🔧',
|
||||
'SUCCESS': '✅'
|
||||
}[level] || 'ℹ️';
|
||||
const levelBadge = document.createElement('span');
|
||||
levelBadge.className = `badge bg-${this.getLevelBadgeClass(log.level || log.tipo)}`;
|
||||
levelBadge.textContent = (log.level || log.tipo || 'INFO').toUpperCase();
|
||||
levelBadge.className = `badge bg-${this.getLevelBadgeClass(level)}`;
|
||||
levelBadge.textContent = `${levelIcon} ${level}`;
|
||||
tdLevel.appendChild(levelBadge);
|
||||
tr.appendChild(tdLevel);
|
||||
|
||||
// Mensaje
|
||||
const tdMessage = document.createElement('td');
|
||||
tdMessage.textContent = this.truncateText(log.message || log.mensaje || '', 100);
|
||||
const message = log.message || log.mensaje || '';
|
||||
tdMessage.innerHTML = `<span class="log-message">${this.escapeHtml(this.truncateText(message, 120))}</span>`;
|
||||
if (log.data) {
|
||||
const dataBtn = document.createElement('button');
|
||||
dataBtn.className = 'btn btn-xs btn-link text-muted ms-2';
|
||||
dataBtn.innerHTML = '<i class="fas fa-database"></i>';
|
||||
dataBtn.title = 'Ver datos adicionales';
|
||||
dataBtn.onclick = () => this.showLogDetails(log);
|
||||
tdMessage.appendChild(dataBtn);
|
||||
}
|
||||
tr.appendChild(tdMessage);
|
||||
|
||||
// Origen
|
||||
const tdSource = document.createElement('td');
|
||||
tdSource.textContent = log.source || log.origen || 'Sistema';
|
||||
const source = log.source || log.origen || 'Sistema';
|
||||
tdSource.innerHTML = `<small><code>${this.escapeHtml(source)}</code></small>`;
|
||||
tr.appendChild(tdSource);
|
||||
|
||||
// Acciones
|
||||
@@ -1503,6 +1517,7 @@ class SimpleWhatsAppManager {
|
||||
const viewButton = document.createElement('button');
|
||||
viewButton.className = 'btn btn-sm btn-outline-info';
|
||||
viewButton.innerHTML = '<i class="fas fa-eye"></i>';
|
||||
viewButton.title = 'Ver detalles completos';
|
||||
viewButton.onclick = () => this.showLogDetails(log);
|
||||
tdActions.appendChild(viewButton);
|
||||
tr.appendChild(tdActions);
|
||||
@@ -1510,6 +1525,12 @@ class SimpleWhatsAppManager {
|
||||
return tr;
|
||||
}
|
||||
|
||||
escapeHtml(text) {
|
||||
const div = document.createElement('div');
|
||||
div.textContent = text;
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
getLevelBadgeClass(level) {
|
||||
const levelClasses = {
|
||||
'ERROR': 'danger',
|
||||
@@ -4084,37 +4105,11 @@ window.exportUsers = function() {
|
||||
if (window.whatsappManager) {
|
||||
window.whatsappManager.showInfo('Preparando exportación de usuarios...');
|
||||
|
||||
// Realizar llamada a API de exportación
|
||||
window.whatsappManager.apiCall('export_users.php')
|
||||
.then(response => {
|
||||
if (response && response.success) {
|
||||
// Si la API devuelve datos para descargar
|
||||
if (response.download_url) {
|
||||
window.open(response.download_url, '_blank');
|
||||
} else if (response.data) {
|
||||
// Crear descarga directa de datos JSON
|
||||
const dataStr = JSON.stringify(response.data, null, 2);
|
||||
const dataBlob = new Blob([dataStr], { type: 'application/json' });
|
||||
const url = URL.createObjectURL(dataBlob);
|
||||
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = `usuarios_export_${new Date().toISOString().split('T')[0]}.json`;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
window.whatsappManager.showSuccess('Usuarios exportados correctamente');
|
||||
} else {
|
||||
window.whatsappManager.showError(`Error exportando usuarios: ${response?.error || 'Error desconocido'}`);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error exportando usuarios:', error);
|
||||
window.whatsappManager.showError('Error exportando usuarios: ' + error.message);
|
||||
});
|
||||
// La API devuelve un archivo CSV directamente, así que abrimos en nueva ventana
|
||||
const url = window.whatsappManager.apiBaseUrl + 'export_users.php';
|
||||
window.open(url, '_blank');
|
||||
|
||||
window.whatsappManager.showSuccess('Descarga de usuarios iniciada');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4122,30 +4117,47 @@ window.exportUsers = function() {
|
||||
window.refreshLogs = function() {
|
||||
console.log('Refrescando logs...');
|
||||
|
||||
const logsContainer = document.getElementById('logs-container');
|
||||
if (logsContainer) {
|
||||
logsContainer.innerHTML = '<div class="text-center"><i class="fas fa-spinner fa-spin"></i> Cargando logs...</div>';
|
||||
|
||||
// Simular carga de logs (aquí se debería hacer una llamada a la API real)
|
||||
setTimeout(() => {
|
||||
logsContainer.innerHTML = `
|
||||
<div class="log-entry mb-2">
|
||||
<small class="text-muted">[${new Date().toLocaleString()}]</small>
|
||||
<span class="text-info">INFO:</span> Logs actualizados correctamente
|
||||
</div>
|
||||
<div class="log-entry mb-2">
|
||||
<small class="text-muted">[${new Date().toLocaleString()}]</small>
|
||||
<span class="text-success">SUCCESS:</span> Sistema funcionando normalmente
|
||||
</div>
|
||||
`;
|
||||
|
||||
if (window.whatsappManager) {
|
||||
window.whatsappManager.showSuccess('Logs actualizados');
|
||||
}
|
||||
}, 1000);
|
||||
if (window.whatsappManager) {
|
||||
window.whatsappManager.showInfo('Actualizando logs...');
|
||||
window.whatsappManager.loadLogs();
|
||||
} else {
|
||||
alert('Error: Sistema no inicializado');
|
||||
}
|
||||
};
|
||||
|
||||
// Función para filtrar logs
|
||||
window.filterLogs = function() {
|
||||
const searchTerm = (document.getElementById('log-search')?.value || '').toLowerCase();
|
||||
const levelFilter = document.getElementById('log-level-filter')?.value || 'all';
|
||||
const tbody = document.getElementById('logs-table');
|
||||
|
||||
if (!tbody) return;
|
||||
|
||||
const rows = tbody.querySelectorAll('tr');
|
||||
let visibleCount = 0;
|
||||
|
||||
rows.forEach(row => {
|
||||
const level = row.getAttribute('data-level');
|
||||
const message = row.getAttribute('data-message');
|
||||
const source = row.getAttribute('data-source');
|
||||
|
||||
const matchesSearch = !searchTerm ||
|
||||
(message && message.includes(searchTerm)) ||
|
||||
(source && source.includes(searchTerm));
|
||||
|
||||
const matchesLevel = levelFilter === 'all' || level === levelFilter;
|
||||
|
||||
if (matchesSearch && matchesLevel) {
|
||||
row.style.display = '';
|
||||
visibleCount++;
|
||||
} else {
|
||||
row.style.display = 'none';
|
||||
}
|
||||
});
|
||||
|
||||
console.log(`Mostrando ${visibleCount} de ${rows.length} logs`);
|
||||
};
|
||||
|
||||
// Función para limpiar logs
|
||||
window.clearLogs = async function() {
|
||||
console.log('Limpiando logs...');
|
||||
@@ -4163,15 +4175,9 @@ window.clearLogs = async function() {
|
||||
|
||||
if (response && response.success) {
|
||||
window.whatsappManager.showSuccess(
|
||||
`Logs limpiados correctamente. ${response.deleted_count} registros eliminados.`
|
||||
`Logs limpiados correctamente. ${response.deleted_count || 0} registros eliminados.`
|
||||
);
|
||||
|
||||
// Limpiar visualmente el contenedor
|
||||
const logsContainer = document.getElementById('logs-container');
|
||||
if (logsContainer) {
|
||||
logsContainer.innerHTML = '<tr><td colspan="5" class="text-center text-muted"><i class="fas fa-trash"></i> No hay logs disponibles</td></tr>';
|
||||
}
|
||||
|
||||
// Recargar logs
|
||||
window.whatsappManager.loadLogs();
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user