base commit
This commit is contained in:
89
app/Filament/Resources/ActivityLogs/ActivityLogResource.php
Normal file
89
app/Filament/Resources/ActivityLogs/ActivityLogResource.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\ActivityLogs;
|
||||
|
||||
use App\Filament\Resources\ActivityLogs\Pages\ListActivityLogs;
|
||||
use App\Filament\Resources\ActivityLogs\Pages\ViewActivityLog;
|
||||
use App\Filament\Resources\ActivityLogs\Schemas\ActivityLogInfolist;
|
||||
use App\Filament\Resources\ActivityLogs\Tables\ActivityLogsTable;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use Spatie\Activitylog\Models\Activity;
|
||||
use UnitEnum;
|
||||
|
||||
class ActivityLogResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Activity::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedClipboardDocumentList;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'System';
|
||||
|
||||
protected static ?int $navigationSort = 3;
|
||||
|
||||
protected static ?string $navigationLabel = 'Audit Log';
|
||||
|
||||
protected static ?string $modelLabel = 'Activity Log';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Activity Logs';
|
||||
|
||||
protected static ?string $slug = 'activity-logs';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema;
|
||||
}
|
||||
|
||||
public static function infolist(Schema $schema): Schema
|
||||
{
|
||||
return ActivityLogInfolist::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return ActivityLogsTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListActivityLogs::route('/'),
|
||||
'view' => ViewActivityLog::route('/{record}'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function canCreate(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function canEdit($record): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function canDelete($record): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function canForceDelete($record): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function canRestore($record): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\ActivityLogs\Pages;
|
||||
|
||||
use App\Filament\Resources\ActivityLogs\ActivityLogResource;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListActivityLogs extends ListRecords
|
||||
{
|
||||
protected static string $resource = ActivityLogResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\ActivityLogs\Pages;
|
||||
|
||||
use App\Filament\Resources\ActivityLogs\ActivityLogResource;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewActivityLog extends ViewRecord
|
||||
{
|
||||
protected static string $resource = ActivityLogResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\ActivityLogs\Schemas;
|
||||
|
||||
use Filament\Infolists\Components\KeyValueEntry;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class ActivityLogInfolist
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Section::make('Activity Details')
|
||||
->schema([
|
||||
TextEntry::make('created_at')
|
||||
->label('Date')
|
||||
->dateTime(),
|
||||
TextEntry::make('description'),
|
||||
TextEntry::make('event')
|
||||
->badge(),
|
||||
TextEntry::make('log_name')
|
||||
->label('Log Name'),
|
||||
TextEntry::make('subject_type')
|
||||
->label('Subject Type')
|
||||
->formatStateUsing(fn (?string $state): string => $state ? class_basename($state) : '—'),
|
||||
TextEntry::make('subject_id')
|
||||
->label('Subject ID'),
|
||||
TextEntry::make('causer.name')
|
||||
->label('Causer'),
|
||||
KeyValueEntry::make('properties.attributes')
|
||||
->label('Changes')
|
||||
->visible(fn ($record): bool => filled($record->properties['attributes'] ?? null)),
|
||||
KeyValueEntry::make('properties.old')
|
||||
->label('Previous Values')
|
||||
->visible(fn ($record): bool => filled($record->properties['old'] ?? null)),
|
||||
])
|
||||
->columns(2),
|
||||
]);
|
||||
}
|
||||
}
|
||||
100
app/Filament/Resources/ActivityLogs/Tables/ActivityLogsTable.php
Normal file
100
app/Filament/Resources/ActivityLogs/Tables/ActivityLogsTable.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\ActivityLogs\Tables;
|
||||
|
||||
use App\Models\Bonus;
|
||||
use App\Models\Department;
|
||||
use App\Models\DisciplinaryReport;
|
||||
use App\Models\Employee;
|
||||
use App\Models\User;
|
||||
use App\Models\Vacation;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ActivityLogsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('created_at')
|
||||
->label('Date')
|
||||
->dateTime()
|
||||
->sortable(),
|
||||
TextColumn::make('description')
|
||||
->searchable()
|
||||
->limit(50),
|
||||
TextColumn::make('event')
|
||||
->badge()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('subject_type')
|
||||
->label('Subject Type')
|
||||
->formatStateUsing(fn (?string $state): string => $state ? class_basename($state) : '—')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('subject_id')
|
||||
->label('Subject ID')
|
||||
->sortable(),
|
||||
TextColumn::make('causer.name')
|
||||
->label('Causer')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('log_name')
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->defaultSort('created_at', 'desc')
|
||||
->filters([
|
||||
SelectFilter::make('subject_type')
|
||||
->label('Subject Type')
|
||||
->options([
|
||||
Employee::class => 'Employee',
|
||||
Vacation::class => 'Vacation',
|
||||
Bonus::class => 'Bonus',
|
||||
DisciplinaryReport::class => 'Disciplinary Report',
|
||||
Department::class => 'Department',
|
||||
User::class => 'User',
|
||||
]),
|
||||
SelectFilter::make('event')
|
||||
->options(fn (): array => \Spatie\Activitylog\Models\Activity::query()
|
||||
->whereNotNull('event')
|
||||
->distinct()
|
||||
->pluck('event', 'event')
|
||||
->all()),
|
||||
SelectFilter::make('causer')
|
||||
->label('Causer')
|
||||
->relationship('causer', 'name')
|
||||
->searchable()
|
||||
->preload(),
|
||||
Filter::make('created_at')
|
||||
->schema([
|
||||
DatePicker::make('from')
|
||||
->label('From'),
|
||||
DatePicker::make('until')
|
||||
->label('Until'),
|
||||
])
|
||||
->query(function (Builder $query, array $data): Builder {
|
||||
return $query
|
||||
->when(
|
||||
$data['from'] ?? null,
|
||||
fn (Builder $query, string $date): Builder => $query->whereDate('created_at', '>=', $date),
|
||||
)
|
||||
->when(
|
||||
$data['until'] ?? null,
|
||||
fn (Builder $query, string $date): Builder => $query->whereDate('created_at', '<=', $date),
|
||||
);
|
||||
}),
|
||||
])
|
||||
->recordActions([
|
||||
ViewAction::make(),
|
||||
])
|
||||
->toolbarActions([]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user