2
2
3
3
namespace AlexJustesen \FilamentSpatieLaravelActivitylog \Resources ;
4
4
5
- use AlexJustesen \FilamentSpatieLaravelActivitylog \Contracts \IsActivitySubject ;
6
- use AlexJustesen \FilamentSpatieLaravelActivitylog \RelationManagers \ActivitiesRelationManager ;
7
- use AlexJustesen \FilamentSpatieLaravelActivitylog \ResourceFinder ;
8
5
use AlexJustesen \FilamentSpatieLaravelActivitylog \Resources \ActivityResource \Pages ;
6
+ use Carbon \Carbon ;
9
7
use Filament \Forms ;
10
8
use Filament \Resources \Form ;
11
9
use Filament \Resources \Resource ;
12
10
use Filament \Resources \Table ;
13
11
use Filament \Tables ;
14
12
use Illuminate \Database \Eloquent \Builder ;
15
- use Illuminate \Support \HtmlString ;
16
- use Livewire \Component ;
17
13
use Spatie \Activitylog \Models \Activity ;
18
14
19
15
class ActivityResource extends Resource
@@ -40,39 +36,39 @@ public static function form(Form $form): Form
40
36
->label (__ ('filament-spatie-activitylog::activity.causer_type ' ))
41
37
->columnSpan ([
42
38
'default ' => 2 ,
43
- 'sm ' => 1
39
+ 'sm ' => 1 ,
44
40
]),
45
41
Forms \Components \TextInput::make ('causer_id ' )
46
42
->label (__ ('filament-spatie-activitylog::activity.causer_id ' ))
47
43
->columnSpan ([
48
44
'default ' => 2 ,
49
- 'sm ' => 1
45
+ 'sm ' => 1 ,
50
46
]),
51
47
Forms \Components \TextInput::make ('subject_type ' )
52
48
->label (__ ('filament-spatie-activitylog::activity.subject_type ' ))
53
49
->columnSpan ([
54
50
'default ' => 2 ,
55
- 'sm ' => 1
51
+ 'sm ' => 1 ,
56
52
]),
57
53
Forms \Components \TextInput::make ('subject_id ' )
58
54
->label (__ ('filament-spatie-activitylog::activity.subject_id ' ))
59
55
->columnSpan ([
60
56
'default ' => 2 ,
61
- 'sm ' => 1
57
+ 'sm ' => 1 ,
62
58
]),
63
59
Forms \Components \TextInput::make ('description ' )
64
60
->label (__ ('filament-spatie-activitylog::activity.description ' ))->columnSpan (2 ),
65
61
Forms \Components \KeyValue::make ('properties.attributes ' )
66
62
->label (__ ('filament-spatie-activitylog::activity.attributes ' ))
67
63
->columnSpan ([
68
64
'default ' => 2 ,
69
- 'sm ' => 1
65
+ 'sm ' => 1 ,
70
66
]),
71
67
Forms \Components \KeyValue::make ('properties.old ' )
72
68
->label (__ ('filament-spatie-activitylog::activity.old ' ))
73
69
->columnSpan ([
74
70
'default ' => 2 ,
75
- 'sm ' => 1
71
+ 'sm ' => 1 ,
76
72
]),
77
73
]);
78
74
}
@@ -84,55 +80,60 @@ public static function table(Table $table): Table
84
80
Tables \Columns \TextColumn::make ('id ' )
85
81
->label ('ID ' )
86
82
->sortable (),
83
+ Tables \Columns \TextColumn::make ('subject_type ' )
84
+ ->label (__ ('filament-spatie-activitylog::activity.subject ' ))
85
+ ->searchable (),
87
86
Tables \Columns \TextColumn::make ('description ' )
88
87
->label (__ ('filament-spatie-activitylog::activity.description ' ))
89
88
->searchable (),
90
- Tables \Columns \TextColumn::make ('subject.name ' )
91
- ->label (__ ('filament-spatie-activitylog::activity.subject ' ))
92
- ->hidden (function (Component $ livewire ) {
93
- return method_exists ($ livewire , 'hideSubjectColumn ' )
94
- ? call_user_func ([$ livewire , 'hideSubjectColumn ' ])
95
- : $ livewire instanceof ActivitiesRelationManager;
96
- })
97
- ->getStateUsing (function (Activity $ record ) {
98
- if (! $ record ->subject || ! $ record ->subject instanceof IsActivitySubject) {
99
- return new HtmlString ('— ' );
100
- }
101
-
102
- /** @var \AlexJustesen\FilamentSpatieLaravelActivitylog\Contracts\IsActivitySubject */
103
- $ subject = $ record ->subject ;
104
-
105
- return $ subject ->getActivitySubjectDescription ($ record );
89
+ Tables \Columns \TextColumn::make ('log_name ' )
90
+ ->label (__ ('filament-spatie-activitylog::activity.log ' )),
91
+ Tables \Columns \TextColumn::make ('created_at ' )
92
+ ->label (__ ('filament-spatie-activitylog::activity.logged_at ' ))
93
+ ->dateTime (),
94
+ ])
95
+ ->filters ([
96
+ Tables \Filters \SelectFilter::make ('event ' )
97
+ ->multiple ()
98
+ ->options ([
99
+ 'created ' => 'Created ' ,
100
+ 'updated ' => 'Updated ' ,
101
+ 'deleted ' => 'Deleted ' ,
102
+ ]),
103
+ Tables \Filters \Filter::make ('created_at ' )
104
+ ->form ([
105
+ Forms \Components \DatePicker::make ('logged_from ' )
106
+ ->label ('Logged from ' ),
107
+ Forms \Components \DatePicker::make ('logged_until ' )
108
+ ->label ('Logged until ' ),
109
+ ])
110
+ ->query (function (Builder $ query , array $ data ): Builder {
111
+ return $ query
112
+ ->when (
113
+ $ data ['logged_from ' ],
114
+ fn (Builder $ query , $ date ): Builder => $ query ->whereDate ('created_at ' , '>= ' , $ date ),
115
+ )
116
+ ->when (
117
+ $ data ['logged_until ' ],
118
+ fn (Builder $ query , $ date ): Builder => $ query ->whereDate ('created_at ' , '<= ' , $ date ),
119
+ );
106
120
})
107
- ->url (function (Activity $ record ) {
108
- if (! $ record ->subject || ! $ record ->subject instanceof IsActivitySubject) {
109
- return ;
110
- }
121
+ ->indicateUsing (function (array $ data ): array {
122
+ $ indicators = [];
111
123
112
- /** @var class-string<\Filament\Resources\Resource> */
113
- $ resource = ResourceFinder::find ($ record ->subject ::class);
114
-
115
- if (! $ resource ) {
116
- return ;
124
+ if ($ data ['from ' ] ?? null ) {
125
+ $ indicators ['from ' ] = 'Created from ' . Carbon::parse ($ data ['from ' ])->toFormattedDateString ();
117
126
}
118
127
119
- if (! $ resource :: hasPage ( ' edit ' ) ) {
120
- return ;
128
+ if ($ data [ ' until ' ] ?? null ) {
129
+ $ indicators [ ' until ' ] = ' Created until ' . Carbon:: parse ( $ data [ ' until ' ])-> toFormattedDateString () ;
121
130
}
122
131
123
- return $ resource ::getUrl ('edit ' , ['record ' => $ record ->subject ]) ?? null ;
124
- }, shouldOpenInNewTab: true ),
125
- Tables \Columns \TextColumn::make ('created_at ' )
126
- ->label (__ ('filament-spatie-activitylog::activity.logged_at ' ))
127
- ->dateTime ()
128
- ->sortable (),
129
- ])
130
- ->filters ([
131
- Tables \Filters \Filter::make ('has_subject ' ) ->label (__ ('filament-spatie-activitylog::activity.has_subject ' ))
132
- ->query (fn (Builder $ query ) => $ query ->has ('subject ' )),
132
+ return $ indicators ;
133
+ }),
133
134
])
134
135
->bulkActions ([])
135
- ->defaultSort ('created_at ' , 'DESC ' );
136
+ ->defaultSort ('id ' , 'DESC ' );
136
137
}
137
138
138
139
protected static function getNavigationGroup (): ?string
0 commit comments