feat: enhance firewall log timestamp display with formatted and relative time
This commit is contained in:
@@ -850,7 +850,54 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
@foreach($this->paginatedLogs as $log)
|
@foreach($this->paginatedLogs as $log)
|
||||||
<tr class="border-b border-neutral/10 hover:bg-background-secondary/30 transition-colors">
|
<tr class="border-b border-neutral/10 hover:bg-background-secondary/30 transition-colors">
|
||||||
<td class="py-3 px-4 text-xs text-base/70">{{ $log['timestamp_display'] ?? $log['timestamp'] ?? '-' }}</td>
|
<td class="py-3 px-4 text-xs text-base/70">
|
||||||
|
@if(isset($log['timestamp_iso']) && $log['timestamp_iso'] !== '-')
|
||||||
|
<div x-data="{
|
||||||
|
timestamp: '{{ $log['timestamp_iso'] }}',
|
||||||
|
formatTime() {
|
||||||
|
try {
|
||||||
|
const date = new Date(this.timestamp);
|
||||||
|
if (isNaN(date.getTime())) return '{{ $log['timestamp'] }}';
|
||||||
|
return date.toLocaleString('en-US', {
|
||||||
|
month: 'short',
|
||||||
|
day: '2-digit',
|
||||||
|
year: 'numeric',
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
second: '2-digit',
|
||||||
|
hour12: false
|
||||||
|
});
|
||||||
|
} catch(e) {
|
||||||
|
return '{{ $log['timestamp'] }}';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getRelativeTime() {
|
||||||
|
try {
|
||||||
|
const date = new Date(this.timestamp);
|
||||||
|
if (isNaN(date.getTime())) return '';
|
||||||
|
const now = new Date();
|
||||||
|
const diffMs = now - date;
|
||||||
|
const diffSec = Math.floor(diffMs / 1000);
|
||||||
|
const diffMin = Math.floor(diffSec / 60);
|
||||||
|
const diffHour = Math.floor(diffMin / 60);
|
||||||
|
const diffDay = Math.floor(diffHour / 24);
|
||||||
|
|
||||||
|
if (diffSec < 60) return diffSec + ' seconds ago';
|
||||||
|
if (diffMin < 60) return diffMin + ' minute' + (diffMin !== 1 ? 's' : '') + ' ago';
|
||||||
|
if (diffHour < 24) return diffHour + ' hour' + (diffHour !== 1 ? 's' : '') + ' ago';
|
||||||
|
return diffDay + ' day' + (diffDay !== 1 ? 's' : '') + ' ago';
|
||||||
|
} catch(e) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
class="cursor-help"
|
||||||
|
:title="getRelativeTime()"
|
||||||
|
x-text="formatTime()"></div>
|
||||||
|
@else
|
||||||
|
{{ $log['timestamp_display'] ?? $log['timestamp'] ?? '-' }}
|
||||||
|
@endif
|
||||||
|
</td>
|
||||||
<td class="py-3 px-4 text-sm">
|
<td class="py-3 px-4 text-sm">
|
||||||
<span class="px-2 py-1 rounded text-xs font-medium {{ $log['level_badge_class'] ?? '' }}">
|
<span class="px-2 py-1 rounded text-xs font-medium {{ $log['level_badge_class'] ?? '' }}">
|
||||||
{{ $log['action'] ?? '-' }}
|
{{ $log['action'] ?? '-' }}
|
||||||
|
|||||||
Reference in New Issue
Block a user