-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
126 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
app/Filament/Resources/ActivityResource/Widgets/ModelActivity.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\ActivityResource\Widgets; | ||
|
||
use App\Models\Activity; | ||
use Filament\Tables; | ||
use Filament\Tables\Table; | ||
use Filament\Widgets\TableWidget as BaseWidget; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\Pivot; | ||
|
||
class ModelActivity extends BaseWidget | ||
{ | ||
public ?Model $causer = null; | ||
public ?Model $subject = null; | ||
|
||
public function getHeading(): ?string | ||
{ | ||
if ($this->causer) { | ||
return __('User Activity'); | ||
} | ||
|
||
if ($this->subject) { | ||
return str(class_basename($this->subject)) | ||
->headline() | ||
->append(__(' History')); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
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); | ||
}); | ||
|
||
return $table | ||
->heading($this->getHeading()) | ||
->query($query) | ||
->columns([ | ||
Tables\Columns\Layout\Split::make([ | ||
Tables\Columns\TextColumn::make('description')->html(), | ||
Tables\Columns\Layout\Split::make([ | ||
Tables\Columns\TextColumn::make('created_at') | ||
->since() | ||
->dateTimeTooltip() | ||
->badge() | ||
->color('warning') | ||
->grow(false), | ||
]) | ||
->grow(false), | ||
]) | ||
->from('md'), | ||
Tables\Columns\Layout\Panel::make([ | ||
Tables\Columns\ViewColumn::make('properties') | ||
->view('filament.tables.columns.activity-properties'), | ||
]) | ||
->hidden(fn(Model $model) => (new $model->subject_type) instanceof Pivot) | ||
->extraAttributes(['class' => 'overflow-x-auto']) | ||
->collapsible(), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters