Files
usher-manage-stack/resources/views/admin/audit/index.blade.php
2025-11-20 23:21:05 +08:00

150 lines
8.8 KiB
PHP

<x-app-layout>
<x-slot name="header">
<h2 class="text-xl font-semibold leading-tight text-gray-800">
{{ __('Audit Logs') }}
</h2>
</x-slot>
<div class="py-12">
<div class="mx-auto max-w-7xl sm:px-6 lg:px-8">
<div class="bg-white shadow sm:rounded-lg">
<div class="px-4 py-5 sm:p-6 space-y-6">
<form method="GET" action="{{ route('admin.audit.index') }}" class="space-y-4" role="search" aria-label="{{ __('Filter audit logs') }}">
<div class="grid gap-4 sm:grid-cols-2">
<div>
<label for="search" class="block text-sm font-medium text-gray-700">
{{ __('Search actions or metadata') }}
</label>
<input
type="text"
id="search"
name="search"
value="{{ $search }}"
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
>
</div>
<div>
<label for="action" class="block text-sm font-medium text-gray-700">
{{ __('Action') }}
</label>
<select
id="action"
name="action"
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
>
<option value="">{{ __('All') }}</option>
@foreach ($actions as $actionOption)
<option value="{{ $actionOption }}" @selected($actionFilter === $actionOption)>{{ $actionOption }}</option>
@endforeach
</select>
</div>
<div>
<label for="user_id" class="block text-sm font-medium text-gray-700">
{{ __('User') }}
</label>
<select
id="user_id"
name="user_id"
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
>
<option value="">{{ __('All') }}</option>
@foreach ($users as $user)
<option value="{{ $user->id }}" @selected($userFilter == $user->id)>{{ $user->name }} ({{ $user->email }})</option>
@endforeach
</select>
</div>
<div class="grid sm:grid-cols-2 gap-4">
<div>
<label for="start_date" class="block text-sm font-medium text-gray-700">
{{ __('Start date') }}
</label>
<input
type="date"
id="start_date"
name="start_date"
value="{{ $startDate }}"
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
>
</div>
<div>
<label for="end_date" class="block text-sm font-medium text-gray-700">
{{ __('End date') }}
</label>
<input
type="date"
id="end_date"
name="end_date"
value="{{ $endDate }}"
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
>
</div>
</div>
</div>
<div class="flex flex-wrap gap-2">
<button type="submit" class="inline-flex items-center rounded-md border border-transparent bg-indigo-600 px-4 py-2 text-sm font-medium text-white hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2">
{{ __('Apply filters') }}
</button>
<a href="{{ route('admin.audit.export', request()->only('search','action','user_id','start_date','end_date')) }}" class="inline-flex items-center rounded-md border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2">
{{ __('Export CSV') }}
</a>
</div>
</form>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200" role="table">
<thead class="bg-gray-50">
<tr>
<th scope="col" class="px-4 py-3 text-left text-xs font-medium uppercase tracking-wider text-gray-500">
{{ __('Time') }}
</th>
<th scope="col" class="px-4 py-3 text-left text-xs font-medium uppercase tracking-wider text-gray-500">
{{ __('User') }}
</th>
<th scope="col" class="px-4 py-3 text-left text-xs font-medium uppercase tracking-wider text-gray-500">
{{ __('Action') }}
</th>
<th scope="col" class="px-4 py-3 text-left text-xs font-medium uppercase tracking-wider text-gray-500">
{{ __('Metadata') }}
</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200 bg-white">
@forelse ($logs as $log)
<tr>
<td class="whitespace-nowrap px-4 py-3 text-sm text-gray-900">
{{ $log->created_at->toDateTimeString() }}
</td>
<td class="whitespace-nowrap px-4 py-3 text-sm text-gray-900">
{{ $log->user?->name ?? __('System') }}
</td>
<td class="whitespace-nowrap px-4 py-3 text-sm text-gray-900">
{{ $log->action }}
</td>
<td class="px-4 py-3 text-sm text-gray-900">
<pre class="whitespace-pre-wrap break-all text-xs bg-gray-50 p-2 rounded">{{ json_encode($log->metadata, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) }}</pre>
</td>
</tr>
@empty
<tr>
<td colspan="4" class="px-4 py-4 text-sm text-gray-500">
{{ __('No audit logs found.') }}
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
<div>
{{ $logs->links() }}
</div>
</div>
</div>
</div>
</div>
</x-app-layout>