base commit
This commit is contained in:
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