Skip to content

Commit

Permalink
Merge pull request #30 from rmsramos/develop
Browse files Browse the repository at this point in the history
Fix and documentation
  • Loading branch information
rmsramos authored Jun 19, 2024
2 parents 94fe6e6 + 4c83df5 commit e47046b
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 37 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ This package provides a Filament resource that shows you all of the activity log
- Filament v3
- Spatie/Laravel-activitylog v4

## Languages Supported

ActivityLog Plugin is translated for :

- 🇧🇷 Brazilian Portuguese
- 🇺🇸 English
- 🇪🇸 Spanish
- 🇫🇷 French

## Installation

You can install the package via composer:
Expand Down Expand Up @@ -121,7 +130,10 @@ public function panel(Panel $panel): Panel

## Customising the ActivitylogResource

You can swap out the `ActivitylogResource` used by updating the `->resource()` value. Use this to create your own `CustomResource` class and extend the original at `\Rmsramos\Activitylog\Resources\ActivitylogResource::class`. This will allow you to customise everything such as the views, table, form and permissions. If you wish to change the resource on List and View page be sure to replace the `getPages` method on the new resource and create your own version of the `ListPage` and `ViewPage` classes to reference the custom `CustomResource`.
You can swap out the `ActivitylogResource` used by updating the `->resource()` value. Use this to create your own `CustomResource` class and extend the original at `\Rmsramos\Activitylog\Resources\ActivitylogResource::class`. This will allow you to customise everything such as the views, table, form and permissions.

> [!NOTE]
> If you wish to change the resource on List and View page be sure to replace the `getPages` method on the new resource and create your own version of the `ListPage` and `ViewPage` classes to reference the custom `CustomResource`.
```php
use Rmsramos\Activitylog\ActivitylogPlugin;
Expand Down
4 changes: 2 additions & 2 deletions resources/lang/fr/action.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

return [
'modal' => [
'heading' => 'Journal d\'activité des utilisateurs',
'heading' => 'Journal d\'activité des utilisateurs',
'description' => 'Suivre toutes les activités des utilisateurs',
'tooltip' => 'Activités des utilisateurs',
'tooltip' => 'Activités des utilisateurs',
],
];
3 changes: 2 additions & 1 deletion resources/lang/fr/forms.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php return [
<?php
return [
'fields' => [
'log_name' => [
'label' => 'Type',
Expand Down
7 changes: 4 additions & 3 deletions resources/lang/fr/tables.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php return [
<?php
return [
'columns' => [
'log_name' => [
'label' => 'Type',
Expand All @@ -21,8 +22,8 @@
],
'filters' => [
'created_at' => [
'label' => 'Enregistré à',
'created_from' => 'Créé à partir de ',
'label' => 'Enregistré à',
'created_from' => 'Créé à partir de ',
'created_until' => 'Créé jusqu\'à ',
],
'event' => [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<div class="my-2 text-sm tracking-tight">
@foreach($getState() as $key => $value)
<span class="font-medium inline-block p-1 mr-1 rounded-md whitespace-normal text-gray-700 dark:text-gray-200 bg-gray-500/10">
<span class="inline-block p-1 mr-1 font-medium text-gray-700 whitespace-normal rounded-md dark:text-gray-200 bg-gray-500/10">
{{ $key }}
</span>

@unless(is_array($value))
{{ $value }}
@else
<span class="divide-x whitespace-normal divide-solid divide-gray-200 dark:divide-gray-700">
@if(is_array($value))
<span class="whitespace-normal divide-x divide-gray-200 divide-solid dark:divide-gray-700">
@foreach ($value as $nestedKey => $nestedValue)
{{$nestedKey}}: {{$nestedValue}}
<span class="inline-block mr-1">
{{ $nestedKey }}: {{ is_array($nestedValue) ? json_encode($nestedValue) : $nestedValue }}
</span>
@endforeach
</span>
@endunless
@else
<span class="whitespace-normal">{{ $value }}</span>
@endif
@endforeach
</div>
39 changes: 23 additions & 16 deletions src/Actions/ActivityLogTimelineAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ class ActivityLogTimelineAction extends Action
private ?array $timelineIconColors = null;

private ?int $limit = 10;

protected Closure $modifyQueryUsing;

protected Closure|Builder $query;

protected ?Closure $activitiesUsing;

protected ?Closure $modifyTitleUsing;

protected ?Closure $shouldModifyTitleUsing;

public static function getDefaultName(): ?string
Expand All @@ -42,13 +47,13 @@ protected function setUp(): void

$this->configureInfolist();
$this->configureModal();
$this->activitiesUsing = null;
$this->modifyTitleUsing = null;
$this->shouldModifyTitleUsing = fn() => true;
$this->modifyQueryUsing = fn($builder) => $builder;
$this->modalHeading= __('activitylog::action.modal.heading');
$this->modalDescription = __('activitylog::action.modal.description');
$this->query = function(?Model $record) {
$this->activitiesUsing = null;
$this->modifyTitleUsing = null;
$this->shouldModifyTitleUsing = fn () => true;
$this->modifyQueryUsing = fn ($builder) => $builder;
$this->modalHeading = __('activitylog::action.modal.heading');
$this->modalDescription = __('activitylog::action.modal.description');
$this->query = function (?Model $record) {
return Activity::query()
->where(function (Builder $query) use ($record) {
$query->where(function (Builder $q) use ($record) {
Expand Down Expand Up @@ -99,8 +104,8 @@ private function getSchema(): array
return $this->getTimelineIconColors()[$state] ?? 'primary';
}),
TimeLineTitleEntry::make('activityData')
->configureTitleUsing($this->modifyTitleUsing)
->shouldConfigureTitleUsing($this->shouldModifyTitleUsing),
->configureTitleUsing($this->modifyTitleUsing)
->shouldConfigureTitleUsing($this->shouldModifyTitleUsing),
TimeLinePropertieEntry::make('activityData'),
TextEntry::make('log_name')
->hiddenLabel()
Expand Down Expand Up @@ -164,6 +169,7 @@ public function getLimit(): ?int
public function query(Closure|Builder|null $query): static
{
$this->query = $query;

return $this;
}

Expand All @@ -175,32 +181,35 @@ public function getQuery(): ?Builder
public function modifyQueryUsing(Closure $closure): static
{
$this->modifyQueryUsing = $closure;

return $this;
}

public function getModifyQueryUsing(Builder $builder): Builder
{
$this->evaluate($this->modifyQueryUsing, ['builder' => $builder]);
return $builder;

return $builder;
}

public function modifyTitleUsing(Closure $closure): static
{
$this->modifyTitleUsing = $closure;

return $this;
}

public function shouldModifyTitleUsing(Closure $closure): static
{
$this->shouldModifyTitleUsing = $closure;

return $this;
}



public function activitiesUsing(Closure $closure): static
{
$this->activitiesUsing = $closure;

return $this;
}

Expand All @@ -209,16 +218,16 @@ public function getActivitiesUsing(): ?Collection
return $this->evaluate($this->activitiesUsing);
}


protected function getActivities(?Model $record, ?array $relations = null): Collection
{
if($activities = $this->getActivitiesUsing()) {
if ($activities = $this->getActivitiesUsing()) {
return $activities;
} else {
$builder = $this->getQuery()
->latest()
->limit($this->getLimit());
$this->getModifyQueryUsing($builder);

return $builder
->get();
}
Expand All @@ -235,8 +244,6 @@ protected function getActivityLogRecord(?Model $record, ?array $relations = null
});
}



protected function formatActivityData($activity): array
{
return [
Expand Down
2 changes: 2 additions & 0 deletions src/Infolists/Components/TimeLinePropertieEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ private function compareOldAndNewValues(array $oldValues, array $newValues): arr

if (isset($oldValues[$key]) && $oldValues[$key] != $newValue) {
$changes[] = "- {$key} from <strong>" . htmlspecialchars($oldValue) . '</strong> to <strong>' . htmlspecialchars($newValue) . '</strong>';
} else {
$changes[] = "- {$key} <strong>'" . htmlspecialchars($newValue) . '</strong>';
}
}

Expand Down
13 changes: 6 additions & 7 deletions src/Infolists/Components/TimeLineTitleEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class TimeLineTitleEntry extends Entry
use HasModifyState;

protected ?Closure $configureTitleUsing = null;

protected ?Closure $shouldConfigureTitleUsing = null;

protected function setUp(): void
Expand All @@ -29,22 +30,20 @@ protected function setUp(): void

protected string $view = 'activitylog::filament.infolists.components.time-line-title-entry';



public function configureTitleUsing(?Closure $configureTitleUsing): TimeLineTitleEntry
{
$this->configureTitleUsing = $configureTitleUsing;

return $this;
}

public function shouldConfigureTitleUsing(?Closure $condition): TimeLineTitleEntry
{
$this->shouldConfigureTitleUsing = $condition;

return $this;
}



private function configureTitleEntry()
{
$this
Expand All @@ -54,13 +53,13 @@ private function configureTitleEntry()

private function modifiedTitle($state): string|HtmlString
{
if(null !== $this->configureTitleUsing && null !== $this->shouldConfigureTitleUsing && $this->evaluate($this->shouldConfigureTitleUsing)) {
if ($this->configureTitleUsing !== null && $this->shouldConfigureTitleUsing !== null && $this->evaluate($this->shouldConfigureTitleUsing)) {
return $this->evaluate($this->configureTitleUsing);
} else {
if ($state['description'] == $state['event']) {
$className = Str::lower(Str::snake(class_basename($state['subject']), ' '));
$className = Str::lower(Str::snake(class_basename($state['subject']), ' '));
$causerName = $this->getCauserName($state['causer']);
$update_at = Carbon::parse($state['update'])->translatedFormat(config('filament-activitylog.datetime_format'));
$update_at = Carbon::parse($state['update'])->translatedFormat(config('filament-activitylog.datetime_format'));

return new HtmlString(
sprintf(
Expand Down

0 comments on commit e47046b

Please sign in to comment.