Skip to content

Commit 067767e

Browse files
authored
Merge pull request #71 from phpust/main
NEW FEATURES ( a lot of good stuff ) : added restore + a lot of customization for date, datetime, icon , ....
2 parents 56719bf + e0d0340 commit 067767e

20 files changed

Lines changed: 650 additions & 37 deletions

README.md

Lines changed: 194 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ return [
7171
'resources' => [
7272
'label' => 'Activity Log',
7373
'plural_label' => 'Activity Logs',
74+
'hide_restore_action' => false,
75+
'restore_action_label' => 'Restore',
76+
'hide_resource_action' => false,
77+
'resource_action_label' => 'View',
7478
'navigation_item' => true,
7579
'navigation_group' => null,
7680
'navigation_icon' => 'heroicon-o-shield-check',
@@ -80,6 +84,7 @@ return [
8084
'navigation_count_badge' => false,
8185
'resource' => \Rmsramos\Activitylog\Resources\ActivitylogResource::class,
8286
],
87+
'date_format' => 'd/m/Y',
8388
'datetime_format' => 'd/m/Y H:i:s',
8489
];
8590
```
@@ -279,6 +284,166 @@ public function panel(Panel $panel): Panel
279284
}
280285
```
281286

287+
## Translate Resource Names
288+
289+
To translate resource names in the activity log, add a `translateSubject` callback within the `ActivitylogPlugin` chain
290+
291+
```php
292+
use Rmsramos\Activitylog\ActivitylogPlugin;
293+
294+
public function panel(Panel $panel): Panel
295+
{
296+
return $panel
297+
->plugins([
298+
ActivitylogPlugin::make()
299+
->translateSubject(fn($label) => __("yourCustomLangFile.".$label)),
300+
]);
301+
}
302+
```
303+
304+
## Customize Date Parsing
305+
306+
To customize how dates are parsed, depending on user preferences or settings:
307+
308+
```php
309+
use Rmsramos\Activitylog\ActivitylogPlugin;
310+
use Morilog\Jalali\Jalalian;
311+
use Carbon\Carbon;
312+
313+
public function panel(Panel $panel): Panel
314+
{
315+
return $panel
316+
->plugins([
317+
ActivitylogPlugin::make()
318+
->dateParser(
319+
fn($date) => auth()->user()->isJalaliCalendar() ?
320+
Jalalian::fromDateTime($date) :
321+
Carbon::parse($date)
322+
)
323+
]);
324+
}
325+
```
326+
327+
## Customize Date and DateTime Formats
328+
329+
To customize the format of dates and datetime columns based on user settings:
330+
331+
```php
332+
use Rmsramos\Activitylog\ActivitylogPlugin;
333+
334+
public function panel(Panel $panel): Panel
335+
{
336+
return $panel
337+
->plugins([
338+
ActivitylogPlugin::make()
339+
->dateFormat('Y-m-d')
340+
->datetimeFormat(fn() => auth()->user()->getFilamentDateTimeFormat())
341+
]);
342+
}
343+
344+
```
345+
346+
## Customize DateTime Columns
347+
348+
To conditionally customize datetime columns in the UI, depending on the user's calendar preference:
349+
350+
```php
351+
use Rmsramos\Activitylog\ActivitylogPlugin;
352+
353+
public function panel(Panel $panel): Panel
354+
{
355+
return $panel
356+
->plugins([
357+
ActivitylogPlugin::make()
358+
->customizeDatetimeColumn(function ($column) {
359+
return $column->when(
360+
auth()->user()->isJalaliCalendar(),
361+
function ($column) {
362+
return $column->jalaliDateTime();
363+
}
364+
);
365+
})
366+
]);
367+
}
368+
```
369+
370+
## Customize Date Picker Fields
371+
372+
To customize date picker fields in forms, depending on user preferences:
373+
374+
```php
375+
use Rmsramos\Activitylog\ActivitylogPlugin;
376+
377+
public function panel(Panel $panel): Panel
378+
{
379+
return $panel
380+
->plugins([
381+
ActivitylogPlugin::make()
382+
->customizeDatePicker(function ($field) {
383+
return $field->when(
384+
auth()->user()->isJalaliCalendar(),
385+
function ($field) {
386+
return $field->jalali();
387+
}
388+
);
389+
})
390+
]);
391+
}
392+
```
393+
394+
## Manipulate View Action Using Custom Activity Resource Trait
395+
396+
Implement `getFilamentActualResourceModel` in the trait `HasCustomActivityResource` to determine the actual model related to the activity record for generating valid URLs.
397+
398+
```php
399+
use Rmsramos\Activitylog\Traits\HasCustomActivityResource;
400+
401+
trait HasCustomActivityResource
402+
{
403+
public function getFilamentActualResourceModel($record)
404+
{
405+
$record = $record->subject->translatable;
406+
$model = null;
407+
408+
switch ($record::class) {
409+
case FirstTranslatableModel::class:
410+
$model = $record->firstModel;
411+
break;
412+
413+
case SecondTranslatableModel::class:
414+
$model = $record->secondModel;
415+
break;
416+
417+
default:
418+
throw new Exception("Error Translatable subject model not found. record = ".$record::class, 1);
419+
break;
420+
}
421+
422+
return $model;
423+
}
424+
}
425+
```
426+
427+
### Hide Restore / View Action
428+
429+
To hide the restore / view action globally for a resource within the `ActivitylogPlugin`, you can use the `isRestoreActionHidden` and `isResourceActionHidden` method. these are particularly useful in scenarios where you do not want users to have the ability to restore or view entries from the activity log. you can also customize the label of view action:
430+
431+
```php
432+
use Rmsramos\Activitylog\ActivitylogPlugin;
433+
434+
public function panel(Panel $panel): Panel
435+
{
436+
return $panel
437+
->plugins([
438+
ActivitylogPlugin::make()
439+
->isRestoreActionHidden(true)
440+
->isResourceActionHidden(true)
441+
->resourceActionLabel("Sample Label")
442+
]);
443+
}
444+
```
445+
446+
282447
### Role Policy
283448

284449
To ensure ActivitylogResource access via RolePolicy you would need to add the following to your AppServiceProvider:
@@ -317,7 +482,35 @@ public function panel(Panel $panel): Panel
317482
->navigationSort(2)
318483
->authorize(
319484
fn () => auth()->user()->id === 1
320-
),
485+
)
486+
->translateSubject(fn($label) => __("yourCustomLangFile.".$label)),
487+
->dateParser(
488+
fn($date) => auth()->user()->isJalaliCalendar() ?
489+
Jalalian::fromDateTime($date) :
490+
Carbon::parse($date)
491+
)
492+
->dateFormat('Y-m-d')
493+
->datetimeFormat(fn() => auth()->user()->getFilamentDateTimeFormat())
494+
->customizeDatetimeColumn(function ($column) {
495+
return $column->when(
496+
auth()->user()->isJalaliCalendar(),
497+
function ($column) {
498+
return $column->jalaliDateTime();
499+
}
500+
);
501+
})
502+
->customizeDatePicker(function ($field) {
503+
return $field->when(
504+
auth()->user()->isJalaliCalendar(),
505+
function ($field) {
506+
return $field->jalali();
507+
}
508+
);
509+
})
510+
->isRestoreActionHidden(true)
511+
->isResourceActionHidden(true)
512+
->resourceActionLabel("Sample Label")
513+
,
321514
]);
322515
}
323516
```

config/filament-activitylog.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
'resources' => [
55
'label' => 'Activity Log',
66
'plural_label' => 'Activity Logs',
7+
'hide_restore_action' => false,
8+
'restore_action_label' => 'Restore',
9+
'hide_resource_action' => false,
10+
'resource_action_label' => 'View',
711
'navigation_item' => true,
812
'navigation_group' => null,
913
'navigation_icon' => 'heroicon-o-shield-check',
@@ -13,5 +17,6 @@
1317
'navigation_count_badge' => false,
1418
'resource' => \Rmsramos\Activitylog\Resources\ActivitylogResource::class,
1519
],
16-
'datetime_format' => 'd/m/Y H:i:s',
20+
'date_format' => 'd/m/Y',
21+
'datetime_format' => 'd/m/Y H:i:s',
1722
];

resources/lang/en/action.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,13 @@
66
'description' => 'Track all user activities',
77
'tooltip' => 'User Activities',
88
],
9+
'event' => [
10+
'created' => 'created',
11+
'deleted' => 'deleted',
12+
'updated' => 'updated',
13+
'restored' => 'restored',
14+
],
15+
'view' => 'View',
16+
'edit' => 'Edit',
17+
'restore' => 'Restore',
918
];

resources/lang/en/forms.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
return [
4+
'changes' => 'Changes',
45
'fields' => [
56
'log_name' => [
67
'label' => 'Type',

resources/lang/en/infolists.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
return [
4+
'components' => [
5+
"created_by_at" => "The <strong>:subject</strong> was <strong>:event</strong> by <strong>:causer</strong>. <br><small> Updated at: <strong>:update_at</strong></small>",
6+
"updater_updated" => ":causer :event the following: <br>:changes",
7+
"from_oldvalue_to_newvalue" => "- :key from <strong>:old_value</strong> to <strong>:new_value</strong>",
8+
"to_newvalue" => "- :key <strong>:new_value</strong>",
9+
"unknown" => "Unknown"
10+
],
11+
];
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
return [
4+
'no_properties_to_restore' => 'No properties to restore.'
5+
'activity_restored' => 'Activity restored.'
6+
'activity_restored_successfully' => 'Activity restored successfully.'
7+
'failed_to_restore_activity' => 'Failed to restore activity : :error.'
8+
];

resources/lang/en/tables.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
'created_at' => [
2626
'label' => 'Logged at',
2727
'created_from' => 'Created from ',
28+
'created_from_indicator' => 'Created from : :created_from',
2829
'created_until' => 'Created until ',
30+
'created_until_indicator' => 'Created until : :created_from',
2931
],
3032
'event' => [
3133
'label' => 'Event',

resources/lang/fa/action.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@
22

33
return [
44
'modal' => [
5-
'heading' => 'گزارش فعالیت کاربر',
5+
'heading' => 'سیاهه‌فعالیت‌کاربر',
66
'description' => 'ردیابی تمام فعالیت های کاربر',
77
'tooltip' => 'فعالیت های کاربر',
88
],
9+
'event' => [
10+
'created' => 'ایجاد شد',
11+
'deleted' => 'حذف شد',
12+
'updated' => 'بروزرسانی شد',
13+
'restored' => 'بازیابی شد',
14+
],
15+
'view' => 'نمایش',
16+
'edit' => 'ویرایش',
17+
'restore' => 'بازیابی'
918
];

resources/lang/fa/forms.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
return [
4+
'changes' => 'تغییرات',
45
'fields' => [
56
'log_name' => [
67
'label' => 'نوع',
@@ -9,7 +10,7 @@
910
'label' => 'رویداد',
1011
],
1112
'subject_type' => [
12-
'label' => 'مفعول',
13+
'label' => 'موضوع مورد سیاهه',
1314
],
1415
'causer' => [
1516
'label' => 'کاربر',

resources/lang/fa/infolists.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
return [
4+
'components' => [
5+
"created_by_at" => "<strong>:subject</strong> توسط <strong>:causer</strong> در تاریخ <strong>:update_at</strong> <strong>:event</strong>.",
6+
"updater_updated" => "ویژگی های زیر توسط <strong>:causer</strong> :event :<br> :changes ",
7+
"from_oldvalue_to_newvalue" => "مقدار ویژگی :key از <strong>:old_value</strong> به <strong>:new_value</strong> تغییر کرد.",
8+
"to_newvalue" => "ویژگی :key به <strong>:new_value</strong> مقدار دهی شد.",
9+
"unknown" => "ناشناس"
10+
],
11+
];

0 commit comments

Comments
 (0)