them log, chinh upload
This commit is contained in:
132
app/Filament/Resources/ActivityLogs/ActivityLogResource.php
Normal file
132
app/Filament/Resources/ActivityLogs/ActivityLogResource.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ActivityLogs;
|
||||
|
||||
use App\Filament\Resources\ActivityLogs\Pages\ListActivityLogs;
|
||||
use App\Models\ActivityLog;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ActivityLogResource extends Resource
|
||||
{
|
||||
protected static ?string $model = ActivityLog::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedClock;
|
||||
|
||||
protected static ?int $navigationSort = 7;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'description';
|
||||
|
||||
public static function getPluralLabel(): ?string
|
||||
{
|
||||
return __('app.resource_activity_logs');
|
||||
}
|
||||
|
||||
public static function getNavigationGroup(): ?string
|
||||
{
|
||||
return __('app.nav_management');
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('description')
|
||||
->defaultSort('created_at', 'desc')
|
||||
->columns([
|
||||
TextColumn::make('created_at')
|
||||
->label(__('app.time'))
|
||||
->dateTime('d/m/Y H:i:s')
|
||||
->sortable(),
|
||||
TextColumn::make('user.name')
|
||||
->label(__('app.user'))
|
||||
->placeholder(__('app.system')),
|
||||
TextColumn::make('action')
|
||||
->label(__('app.action'))
|
||||
->badge()
|
||||
->formatStateUsing(fn (string $state): string => match ($state) {
|
||||
'import' => __('app.action_import'),
|
||||
'export' => __('app.action_export'),
|
||||
'transfer' => __('app.action_transfer'),
|
||||
'close' => __('app.action_close'),
|
||||
'create' => __('app.action_create'),
|
||||
'update' => __('app.action_update'),
|
||||
'delete' => __('app.action_delete'),
|
||||
default => $state,
|
||||
})
|
||||
->color(fn (string $state): string => match ($state) {
|
||||
'import' => 'info',
|
||||
'export' => 'success',
|
||||
'transfer' => 'warning',
|
||||
'close' => 'success',
|
||||
'create' => 'info',
|
||||
'update' => 'gray',
|
||||
'delete' => 'danger',
|
||||
default => 'gray',
|
||||
}),
|
||||
TextColumn::make('description')
|
||||
->label(__('app.description'))
|
||||
->wrap()
|
||||
->searchable(),
|
||||
TextColumn::make('metadata')
|
||||
->label(__('app.details'))
|
||||
->formatStateUsing(function (?array $state): string {
|
||||
if (empty($state)) return '';
|
||||
$lines = [];
|
||||
foreach ($state as $key => $val) {
|
||||
if (is_scalar($val)) {
|
||||
$lines[] = "<b>{$key}</b>: {$val}";
|
||||
} elseif (is_array($val)) {
|
||||
$nested = [];
|
||||
foreach ($val as $k => $v) {
|
||||
if (is_scalar($v)) {
|
||||
$nested[] = "{$k}: {$v}";
|
||||
}
|
||||
}
|
||||
$lines[] = "<b>{$key}</b>: " . implode(', ', $nested);
|
||||
}
|
||||
}
|
||||
return implode('<br>', $lines);
|
||||
})
|
||||
->html()
|
||||
->wrap()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('action')
|
||||
->label(__('app.action'))
|
||||
->options([
|
||||
'import' => __('app.action_import'),
|
||||
'export' => __('app.action_export'),
|
||||
'transfer' => __('app.action_transfer'),
|
||||
'close' => __('app.action_close'),
|
||||
'create' => __('app.action_create'),
|
||||
'update' => __('app.action_update'),
|
||||
'delete' => __('app.action_delete'),
|
||||
]),
|
||||
SelectFilter::make('user_id')
|
||||
->label(__('app.user'))
|
||||
->relationship('user', 'name'),
|
||||
])
|
||||
->actions([])
|
||||
->bulkActions([]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListActivityLogs::route('/'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
->with('user')
|
||||
->orderBy('created_at', 'desc');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user