filteredLogs not re rendering upon applying filters
Browse files
script.js
CHANGED
|
@@ -426,54 +426,18 @@ const urlFilter = document.querySelector('input[placeholder="URL Contains"]').va
|
|
| 426 |
const errorFilter = document.querySelector('input[placeholder="Error Contains"]').value;
|
| 427 |
const now = new Date();
|
| 428 |
const timeAgo = new Date(now.getTime() - (hours * 60 * 60 * 1000));
|
| 429 |
-
|
| 430 |
const filteredLogs = sampleLogs.filter(log => {
|
| 431 |
const logDate = new Date(log.time);
|
| 432 |
-
|
| 433 |
-
|
|
|
|
| 434 |
(methodFilter === 'All' || log.method === methodFilter) &&
|
| 435 |
timeMatch &&
|
| 436 |
(urlFilter === '' || log.url.toLowerCase().includes(urlFilter.toLowerCase())) &&
|
| 437 |
(errorFilter === '' || log.errorMessage.toLowerCase().includes(errorFilter.toLowerCase()));
|
| 438 |
});
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
logsTable.innerHTML = '';
|
| 442 |
-
|
| 443 |
-
// Render filtered logs
|
| 444 |
-
filteredLogs.forEach(log => {
|
| 445 |
-
const row = document.createElement('tr');
|
| 446 |
-
row.className = 'hover:bg-gray-50';
|
| 447 |
-
row.innerHTML = `
|
| 448 |
-
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${log.id}</td>
|
| 449 |
-
<td class="px-6 py-4 whitespace-nowrap">
|
| 450 |
-
<span class="status-badge ${getStatusClass(log.status)}">${log.status}</span>
|
| 451 |
-
</td>
|
| 452 |
-
<td class="px-6 py-4 whitespace-nowrap">
|
| 453 |
-
<span class="status-badge ${getMethodClass(log.method)}">${log.method}</span>
|
| 454 |
-
</td>
|
| 455 |
-
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${log.time}</td>
|
| 456 |
-
<td class="px-6 py-4 text-sm text-gray-500 max-w-xs truncate">${log.url}</td>
|
| 457 |
-
<td class="px-6 py-4 text-sm text-gray-500 truncate max-w-xs">${log.errorMessage}</td>
|
| 458 |
-
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
| 459 |
-
<button class="view-btn p-1 rounded hover:bg-gray-200" data-id="${log.id}">
|
| 460 |
-
<i data-feather="eye" class="w-4 h-4 text-primary-500"></i>
|
| 461 |
-
</button>
|
| 462 |
-
</td>
|
| 463 |
-
`;
|
| 464 |
-
logsTable.appendChild(row);
|
| 465 |
-
});
|
| 466 |
-
|
| 467 |
-
// Add event listeners to new view buttons
|
| 468 |
-
document.querySelectorAll('.view-btn').forEach(btn => {
|
| 469 |
-
btn.addEventListener('click', (e) => {
|
| 470 |
-
const id = parseInt(e.currentTarget.getAttribute('data-id'));
|
| 471 |
-
currentLog = sampleLogs.find(log => log.id === id);
|
| 472 |
-
showErrorDetails(currentLog);
|
| 473 |
-
});
|
| 474 |
-
});
|
| 475 |
-
|
| 476 |
-
feather.replace();
|
| 477 |
});
|
| 478 |
});
|
| 479 |
// Global event delegation for modal buttons
|
|
|
|
| 426 |
const errorFilter = document.querySelector('input[placeholder="Error Contains"]').value;
|
| 427 |
const now = new Date();
|
| 428 |
const timeAgo = new Date(now.getTime() - (hours * 60 * 60 * 1000));
|
|
|
|
| 429 |
const filteredLogs = sampleLogs.filter(log => {
|
| 430 |
const logDate = new Date(log.time);
|
| 431 |
+
const timeMatch = hours === 'all' || logDate >= timeAgo;
|
| 432 |
+
|
| 433 |
+
return (statusFilter === 'All' || log.status.toString() === statusFilter) &&
|
| 434 |
(methodFilter === 'All' || log.method === methodFilter) &&
|
| 435 |
timeMatch &&
|
| 436 |
(urlFilter === '' || log.url.toLowerCase().includes(urlFilter.toLowerCase())) &&
|
| 437 |
(errorFilter === '' || log.errorMessage.toLowerCase().includes(errorFilter.toLowerCase()));
|
| 438 |
});
|
| 439 |
+
renderLogsTableWithFilter(filteredLogs);
|
| 440 |
+
feather.replace();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 441 |
});
|
| 442 |
});
|
| 443 |
// Global event delegation for modal buttons
|