Skip to content

Commit

Permalink
ref: ModelActivity widget
Browse files Browse the repository at this point in the history
  • Loading branch information
fzldn committed Sep 20, 2024
1 parent d63729e commit e3415d3
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
3 changes: 2 additions & 1 deletion app/Filament/Resources/ActivityResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public static function table(Table $table): Table

return __('To: :date', ['date' => $data['to']]);
}),
], layout: Tables\Enums\FiltersLayout::AboveContent);
], layout: Tables\Enums\FiltersLayout::AboveContent)
->paginationPageOptions([10, 25, 50, 100]);
}

public static function getPages(): array
Expand Down
30 changes: 15 additions & 15 deletions app/Filament/Resources/ActivityResource/Widgets/ModelActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

class ModelActivity extends BaseWidget
{
public ?Model $record = null;
public ?Model $causer = null;
public ?Model $subject = null;

public static function canView(): bool
{
Expand All @@ -26,24 +26,23 @@ public function getHeading(): ?string
return __('User Activity');
}

if ($this->subject) {
return str(class_basename($this->subject))
->headline()
->append(__(' History'));
}

return null;
return str(class_basename($this->record))
->headline()
->append(__(' History'));
}

public function table(Table $table): Table
{
$query = Activity::query()
->when($this->causer, function ($q, $causer) {
$q->causedBy($causer);
})
->when($this->subject, function ($q, $subject) {
$q->forSubject($subject);
});
->when(
$this->causer,
function ($q, $causer) {
$q->causedBy($causer);
},
function ($q) {
$q->forSubject($this->record);
}
);

return $table
->heading($this->getHeading())
Expand All @@ -69,6 +68,7 @@ public function table(Table $table): Table
->hidden(fn(Model $model) => (new $model->subject_type) instanceof Pivot)
->extraAttributes(['class' => 'overflow-x-auto'])
->collapsible(),
]);
])
->paginationPageOptions([10, 25, 50, 100]);
}
}
2 changes: 1 addition & 1 deletion app/Filament/Resources/RoleResource/Pages/EditRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function getHeaderActions(): array
protected function getFooterWidgets(): array
{
return [
ActivityResource\Widgets\ModelActivity::make(['subject' => $this->record]),
ActivityResource\Widgets\ModelActivity::make(),
];
}
}
2 changes: 1 addition & 1 deletion app/Filament/Resources/RoleResource/Pages/ViewRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function getHeaderActions(): array
protected function getFooterWidgets(): array
{
return [
ActivityResource\Widgets\ModelActivity::make(['subject' => $this->record]),
ActivityResource\Widgets\ModelActivity::make(),
];
}
}
2 changes: 1 addition & 1 deletion app/Filament/Resources/UserResource/Pages/EditUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected function getFooterWidgets(): array
{
return [
ActivityResource\Widgets\ModelActivity::make(['causer' => $this->record]),
ActivityResource\Widgets\ModelActivity::make(['subject' => $this->record]),
ActivityResource\Widgets\ModelActivity::make(),
];
}
}
2 changes: 1 addition & 1 deletion app/Filament/Resources/UserResource/Pages/ViewUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function getFooterWidgets(): array
{
return [
ActivityResource\Widgets\ModelActivity::make(['causer' => $this->record]),
ActivityResource\Widgets\ModelActivity::make(['subject' => $this->record]),
ActivityResource\Widgets\ModelActivity::make(),
];
}
}

0 comments on commit e3415d3

Please sign in to comment.