filteredLogs not rendering
Browse files
script.js
CHANGED
|
@@ -339,56 +339,70 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 339 |
const timeFilter = document.querySelector('select:nth-of-type(3)').value;
|
| 340 |
const urlFilter = document.querySelector('input[placeholder="URL Contains"]').value;
|
| 341 |
const errorFilter = document.querySelector('input[placeholder="Error Contains"]').value;
|
| 342 |
-
|
|
|
|
|
|
|
| 343 |
const filteredLogs = sampleLogs.filter(log => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
return (statusFilter === 'All' || log.status.toString() === statusFilter) &&
|
| 345 |
(methodFilter === 'All' || log.method === methodFilter) &&
|
| 346 |
-
|
| 347 |
(urlFilter === '' || log.url.toLowerCase().includes(urlFilter.toLowerCase())) &&
|
| 348 |
(errorFilter === '' || log.errorMessage.toLowerCase().includes(errorFilter.toLowerCase()));
|
| 349 |
});
|
| 350 |
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
<
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
<
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
`;
|
| 378 |
-
logsTable.appendChild(row);
|
| 379 |
-
});
|
| 380 |
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
|
|
|
| 387 |
});
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
}
|
| 392 |
// Global event delegation for modal buttons
|
| 393 |
document.addEventListener('click', (e) => {
|
| 394 |
if (e.target.closest('#closeModal, #closeModalBtn')) {
|
|
|
|
| 339 |
const timeFilter = document.querySelector('select:nth-of-type(3)').value;
|
| 340 |
const urlFilter = document.querySelector('input[placeholder="URL Contains"]').value;
|
| 341 |
const errorFilter = document.querySelector('input[placeholder="Error Contains"]').value;
|
| 342 |
+
const now = new Date();
|
| 343 |
+
const twentyFourHoursAgo = new Date(now.getTime() - (24 * 60 * 60 * 1000));
|
| 344 |
+
|
| 345 |
const filteredLogs = sampleLogs.filter(log => {
|
| 346 |
+
const logDate = new Date(log.time);
|
| 347 |
+
|
| 348 |
+
// Time filter logic
|
| 349 |
+
let timeMatch = true;
|
| 350 |
+
if (timeFilter === 'Last 24 hours') {
|
| 351 |
+
timeMatch = logDate >= twentyFourHoursAgo;
|
| 352 |
+
} else if (timeFilter === 'Last week') {
|
| 353 |
+
const oneWeekAgo = new Date(now.getTime() - (7 * 24 * 60 * 60 * 1000));
|
| 354 |
+
timeMatch = logDate >= oneWeekAgo;
|
| 355 |
+
} else if (timeFilter === 'Last month') {
|
| 356 |
+
const oneMonthAgo = new Date(now.getTime() - (30 * 24 * 60 * 60 * 1000));
|
| 357 |
+
timeMatch = logDate >= oneMonthAgo;
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
return (statusFilter === 'All' || log.status.toString() === statusFilter) &&
|
| 361 |
(methodFilter === 'All' || log.method === methodFilter) &&
|
| 362 |
+
timeMatch &&
|
| 363 |
(urlFilter === '' || log.url.toLowerCase().includes(urlFilter.toLowerCase())) &&
|
| 364 |
(errorFilter === '' || log.errorMessage.toLowerCase().includes(errorFilter.toLowerCase()));
|
| 365 |
});
|
| 366 |
|
| 367 |
+
// Clear current logs
|
| 368 |
+
logsTable.innerHTML = '';
|
| 369 |
+
|
| 370 |
+
// Render filtered logs
|
| 371 |
+
filteredLogs.forEach(log => {
|
| 372 |
+
const row = document.createElement('tr');
|
| 373 |
+
row.className = 'hover:bg-gray-50';
|
| 374 |
+
row.innerHTML = `
|
| 375 |
+
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${log.id}</td>
|
| 376 |
+
<td class="px-6 py-4 whitespace-nowrap">
|
| 377 |
+
<span class="status-badge ${getStatusClass(log.status)}">${log.status}</span>
|
| 378 |
+
</td>
|
| 379 |
+
<td class="px-6 py-4 whitespace-nowrap">
|
| 380 |
+
<span class="status-badge ${getMethodClass(log.method)}">${log.method}</span>
|
| 381 |
+
</td>
|
| 382 |
+
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${log.time}</td>
|
| 383 |
+
<td class="px-6 py-4 text-sm text-gray-500 max-w-xs truncate">${log.url}</td>
|
| 384 |
+
<td class="px-6 py-4 text-sm text-gray-500 truncate max-w-xs">${log.errorMessage}</td>
|
| 385 |
+
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
| 386 |
+
<button class="view-btn p-1 rounded hover:bg-gray-200" data-id="${log.id}">
|
| 387 |
+
<i data-feather="eye" class="w-4 h-4 text-primary-500"></i>
|
| 388 |
+
</button>
|
| 389 |
+
</td>
|
| 390 |
+
`;
|
| 391 |
+
logsTable.appendChild(row);
|
| 392 |
+
});
|
|
|
|
|
|
|
|
|
|
| 393 |
|
| 394 |
+
// Add event listeners to new view buttons
|
| 395 |
+
document.querySelectorAll('.view-btn').forEach(btn => {
|
| 396 |
+
btn.addEventListener('click', (e) => {
|
| 397 |
+
const id = parseInt(e.currentTarget.getAttribute('data-id'));
|
| 398 |
+
currentLog = sampleLogs.find(log => log.id === id);
|
| 399 |
+
showErrorDetails(currentLog);
|
| 400 |
+
});
|
| 401 |
});
|
| 402 |
+
|
| 403 |
+
feather.replace();
|
| 404 |
+
});
|
| 405 |
+
});
|
| 406 |
// Global event delegation for modal buttons
|
| 407 |
document.addEventListener('click', (e) => {
|
| 408 |
if (e.target.closest('#closeModal, #closeModalBtn')) {
|