Add "all" option in Time range filter , renderLogsTable() not re rendered on applying filter.
Browse files- index.html +2 -1
- script.js +43 -41
index.html
CHANGED
|
@@ -62,13 +62,14 @@
|
|
| 62 |
<div>
|
| 63 |
<label class="block text-sm font-medium text-gray-700 mb-1">Time Range</label>
|
| 64 |
<select id="timeRangeSelect" class="w-full rounded-md border-gray-300 shadow-sm focus:border-primary-500 focus:ring-primary-500 text-sm mb-2">
|
|
|
|
| 65 |
<option value="1">Last hour</option>
|
| 66 |
<option value="24" selected>Last 24 hours</option>
|
| 67 |
<option value="168">Last week</option>
|
| 68 |
<option value="720">Last month</option>
|
| 69 |
<option value="custom">Custom hours</option>
|
| 70 |
</select>
|
| 71 |
-
|
| 72 |
class="w-full rounded-md border-gray-300 shadow-sm focus:border-primary-500 focus:ring-primary-500 text-sm hidden">
|
| 73 |
</div>
|
| 74 |
<div>
|
|
|
|
| 62 |
<div>
|
| 63 |
<label class="block text-sm font-medium text-gray-700 mb-1">Time Range</label>
|
| 64 |
<select id="timeRangeSelect" class="w-full rounded-md border-gray-300 shadow-sm focus:border-primary-500 focus:ring-primary-500 text-sm mb-2">
|
| 65 |
+
<option value="all">All time</option>
|
| 66 |
<option value="1">Last hour</option>
|
| 67 |
<option value="24" selected>Last 24 hours</option>
|
| 68 |
<option value="168">Last week</option>
|
| 69 |
<option value="720">Last month</option>
|
| 70 |
<option value="custom">Custom hours</option>
|
| 71 |
</select>
|
| 72 |
+
<input id="customHoursInput" type="number" min="1" placeholder="Enter hours"
|
| 73 |
class="w-full rounded-md border-gray-300 shadow-sm focus:border-primary-500 focus:ring-primary-500 text-sm hidden">
|
| 74 |
</div>
|
| 75 |
<div>
|
script.js
CHANGED
|
@@ -66,9 +66,47 @@ let submitTicket;
|
|
| 66 |
// Current selected log
|
| 67 |
let currentLog = null;
|
| 68 |
// Function to render logs table with optional filter
|
| 69 |
-
function
|
| 70 |
logsTable.innerHTML = '';
|
| 71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
const filteredLogs = filter
|
| 73 |
? sampleLogs.filter(log =>
|
| 74 |
log.url.toLowerCase().includes(filter.toLowerCase()) ||
|
|
@@ -347,54 +385,18 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 347 |
const errorFilter = document.querySelector('input[placeholder="Error Contains"]').value;
|
| 348 |
const now = new Date();
|
| 349 |
const timeAgo = new Date(now.getTime() - (hours * 60 * 60 * 1000));
|
| 350 |
-
|
| 351 |
const filteredLogs = sampleLogs.filter(log => {
|
| 352 |
const logDate = new Date(log.time);
|
| 353 |
-
|
|
|
|
| 354 |
(statusFilter === 'All' || log.status.toString() === statusFilter) &&
|
| 355 |
(methodFilter === 'All' || log.method === methodFilter) &&
|
| 356 |
(urlFilter === '' || log.url.toLowerCase().includes(urlFilter.toLowerCase())) &&
|
| 357 |
(errorFilter === '' || log.errorMessage.toLowerCase().includes(errorFilter.toLowerCase()));
|
| 358 |
});
|
| 359 |
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
// Render filtered logs
|
| 364 |
-
filteredLogs.forEach(log => {
|
| 365 |
-
const row = document.createElement('tr');
|
| 366 |
-
row.className = 'hover:bg-gray-50';
|
| 367 |
-
row.innerHTML = `
|
| 368 |
-
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${log.id}</td>
|
| 369 |
-
<td class="px-6 py-4 whitespace-nowrap">
|
| 370 |
-
<span class="status-badge ${getStatusClass(log.status)}">${log.status}</span>
|
| 371 |
-
</td>
|
| 372 |
-
<td class="px-6 py-4 whitespace-nowrap">
|
| 373 |
-
<span class="status-badge ${getMethodClass(log.method)}">${log.method}</span>
|
| 374 |
-
</td>
|
| 375 |
-
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${log.time}</td>
|
| 376 |
-
<td class="px-6 py-4 text-sm text-gray-500 max-w-xs truncate">${log.url}</td>
|
| 377 |
-
<td class="px-6 py-4 text-sm text-gray-500 truncate max-w-xs">${log.errorMessage}</td>
|
| 378 |
-
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
| 379 |
-
<button class="view-btn p-1 rounded hover:bg-gray-200" data-id="${log.id}">
|
| 380 |
-
<i data-feather="eye" class="w-4 h-4 text-primary-500"></i>
|
| 381 |
-
</button>
|
| 382 |
-
</td>
|
| 383 |
-
`;
|
| 384 |
-
logsTable.appendChild(row);
|
| 385 |
-
});
|
| 386 |
-
|
| 387 |
-
// Add event listeners to new view buttons
|
| 388 |
-
document.querySelectorAll('.view-btn').forEach(btn => {
|
| 389 |
-
btn.addEventListener('click', (e) => {
|
| 390 |
-
const id = parseInt(e.currentTarget.getAttribute('data-id'));
|
| 391 |
-
currentLog = sampleLogs.find(log => log.id === id);
|
| 392 |
-
showErrorDetails(currentLog);
|
| 393 |
-
});
|
| 394 |
-
});
|
| 395 |
-
|
| 396 |
-
feather.replace();
|
| 397 |
-
});
|
| 398 |
// Setup event listeners for modal
|
| 399 |
errorModal.addEventListener('click', (e) => {
|
| 400 |
if (e.target === errorModal) {
|
|
|
|
| 66 |
// Current selected log
|
| 67 |
let currentLog = null;
|
| 68 |
// Function to render logs table with optional filter
|
| 69 |
+
function renderLogsTableWithFilter(filteredLogs) {
|
| 70 |
logsTable.innerHTML = '';
|
| 71 |
|
| 72 |
+
filteredLogs.forEach(log => {
|
| 73 |
+
const row = document.createElement('tr');
|
| 74 |
+
row.className = 'hover:bg-gray-50';
|
| 75 |
+
row.innerHTML = `
|
| 76 |
+
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${log.id}</td>
|
| 77 |
+
<td class="px-6 py-4 whitespace-nowrap">
|
| 78 |
+
<span class="status-badge ${getStatusClass(log.status)}">${log.status}</span>
|
| 79 |
+
</td>
|
| 80 |
+
<td class="px-6 py-4 whitespace-nowrap">
|
| 81 |
+
<span class="status-badge ${getMethodClass(log.method)}">${log.method}</span>
|
| 82 |
+
</td>
|
| 83 |
+
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${log.time}</td>
|
| 84 |
+
<td class="px-6 py-4 text-sm text-gray-500 max-w-xs truncate">${log.url}</td>
|
| 85 |
+
<td class="px-6 py-4 text-sm text-gray-500 truncate max-w-xs">${log.errorMessage}</td>
|
| 86 |
+
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
| 87 |
+
<button class="view-btn p-1 rounded hover:bg-gray-200" data-id="${log.id}">
|
| 88 |
+
<i data-feather="eye" class="w-4 h-4 text-primary-500"></i>
|
| 89 |
+
</button>
|
| 90 |
+
</td>
|
| 91 |
+
`;
|
| 92 |
+
logsTable.appendChild(row);
|
| 93 |
+
});
|
| 94 |
+
|
| 95 |
+
// Add event listeners to new view buttons
|
| 96 |
+
document.querySelectorAll('.view-btn').forEach(btn => {
|
| 97 |
+
btn.addEventListener('click', (e) => {
|
| 98 |
+
const id = parseInt(e.currentTarget.getAttribute('data-id'));
|
| 99 |
+
currentLog = sampleLogs.find(log => log.id === id);
|
| 100 |
+
showErrorDetails(currentLog);
|
| 101 |
+
});
|
| 102 |
+
});
|
| 103 |
+
|
| 104 |
+
feather.replace();
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
function renderLogsTable(filter = '') {
|
| 108 |
+
logsTable.innerHTML = '';
|
| 109 |
+
|
| 110 |
const filteredLogs = filter
|
| 111 |
? sampleLogs.filter(log =>
|
| 112 |
log.url.toLowerCase().includes(filter.toLowerCase()) ||
|
|
|
|
| 385 |
const errorFilter = document.querySelector('input[placeholder="Error Contains"]').value;
|
| 386 |
const now = new Date();
|
| 387 |
const timeAgo = new Date(now.getTime() - (hours * 60 * 60 * 1000));
|
|
|
|
| 388 |
const filteredLogs = sampleLogs.filter(log => {
|
| 389 |
const logDate = new Date(log.time);
|
| 390 |
+
const timeMatch = hours === 'all' || logDate >= timeAgo;
|
| 391 |
+
return timeMatch &&
|
| 392 |
(statusFilter === 'All' || log.status.toString() === statusFilter) &&
|
| 393 |
(methodFilter === 'All' || log.method === methodFilter) &&
|
| 394 |
(urlFilter === '' || log.url.toLowerCase().includes(urlFilter.toLowerCase())) &&
|
| 395 |
(errorFilter === '' || log.errorMessage.toLowerCase().includes(errorFilter.toLowerCase()));
|
| 396 |
});
|
| 397 |
|
| 398 |
+
renderLogsTableWithFilter(filteredLogs);
|
| 399 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 400 |
// Setup event listeners for modal
|
| 401 |
errorModal.addEventListener('click', (e) => {
|
| 402 |
if (e.target === errorModal) {
|