22
33namespace Visualbuilder \FilamentUserConsent \Resources ;
44
5- use Filament \Schemas \Components \Livewire ;
6- use Closure ;
5+ use BackedEnum ;
6+ use Filament \Actions \Action ;
7+ use Filament \Actions \BulkActionGroup ;
78use Filament \Forms ;
8- use Filament \Schemas \Components \Group ;
99use Filament \Forms \Components \Repeater ;
10+ use Filament \Pages \Enums \SubNavigationPosition ;
11+ use Filament \Resources \Resource ;
12+ use Filament \Schemas \Components \Group ;
13+ use Filament \Schemas \Components \Livewire ;
1014use Filament \Schemas \Components \Section ;
11- use Filament \Schemas \Schema ;
1215use Filament \Schemas \Components \Utilities \Get ;
1316use Filament \Schemas \Components \Utilities \Set ;
14- use Filament \Pages \Enums \SubNavigationPosition ;
15- use Filament \Resources \Resource ;
17+ use Filament \Schemas \Schema ;
1618use Filament \Tables ;
1719use Filament \Tables \Table ;
1820use Illuminate \Support \Str ;
1921use Visualbuilder \FilamentTinyEditor \TinyEditor ;
22+ use Visualbuilder \FilamentUserConsent \Livewire \ConsentOptionPreview ;
2023use Visualbuilder \FilamentUserConsent \Models \ConsentOption ;
2124use Visualbuilder \FilamentUserConsent \Resources \ConsentOptionResource \Pages \CreateConsentOption ;
2225use Visualbuilder \FilamentUserConsent \Resources \ConsentOptionResource \Pages \EditConsentOption ;
2326use Visualbuilder \FilamentUserConsent \Resources \ConsentOptionResource \Pages \ListConsentOptions ;
2427use Visualbuilder \FilamentUserConsent \Resources \ConsentOptionResource \RelationManagers \ConsentOptionQuestionsRelationManager ;
25- use Visualbuilder \FilamentUserConsent \Livewire \ConsentOptionPreview ;
26- use BackedEnum ;
2728
2829class ConsentOptionResource extends Resource
2930{
@@ -66,6 +67,55 @@ public static function shouldRegisterNavigation(): bool
6667 return config ('filament-user-consent.navigation.consent_options.register ' );
6768 }
6869
70+ public static function table (Table $ table ): Table
71+ {
72+ return $ table
73+ ->columns ([
74+ Tables \Columns \TextColumn::make ('title ' )
75+ ->searchable (),
76+ Tables \Columns \TextColumn::make ('version ' )
77+ ->sortable (),
78+ Tables \Columns \IconColumn::make ('is_mandatory ' )
79+ ->boolean ()
80+ ->sortable (),
81+ Tables \Columns \IconColumn::make ('is_survey ' )
82+ ->boolean ()
83+ ->sortable (),
84+ Tables \Columns \IconColumn::make ('is_current ' )
85+ ->boolean ()
86+ ->sortable (),
87+ Tables \Columns \IconColumn::make ('enabled ' )
88+ ->boolean ()
89+ ->sortable (),
90+ Tables \Columns \IconColumn::make ('force_user_update ' )
91+ ->boolean ()
92+ ->sortable (),
93+ Tables \Columns \TextColumn::make ('usersAcceptedTotal ' )
94+ ->label ('Accepted Users ' ),
95+ Tables \Columns \TextColumn::make ('usersDeclinedTotal ' )
96+ ->label ('Declined Users ' ),
97+ Tables \Columns \TextColumn::make ('published_at ' )
98+ ->sortable (),
99+ ])
100+ ->filters ([
101+ //
102+ ])
103+ ->defaultSort ('created_at ' , 'desc ' )
104+ ->recordActions ([
105+ Action::make ('Preview ' )
106+ ->icon ('heroicon-m-viewfinder-circle ' )
107+ ->modalHeading ("" )
108+ ->modalSubmitAction (false )
109+ ->modalCancelAction (false )
110+ ->form ([
111+ Livewire::make (ConsentOptionPreview::class),
112+ ])
113+ ])
114+ ->headerActions ([
115+ BulkActionGroup::make ([]),
116+ ]);
117+ }
118+
69119 public static function form (Schema $ schema ): Schema
70120 {
71121 return $ schema
@@ -75,7 +125,7 @@ public static function form(Schema $schema): Schema
75125 Forms \Components \TextInput::make ('title ' )
76126 ->live ()
77127 ->afterStateUpdated (
78- fn (Set $ set , ?string $ state ) => $ set ('key ' , Str::slug ($ state ))
128+ fn (Set $ set , ?string $ state ) => $ set ('key ' , Str::slug ($ state ))
79129 )
80130 ->required (),
81131 Forms \Components \TextInput::make ('key ' )
@@ -85,42 +135,42 @@ public static function form(Schema $schema): Schema
85135 ->required (),
86136 Forms \Components \TextInput::make ('sort_order ' )
87137 ->numeric ()
88- ->hintIcon ('heroicon-o-information-circle ' ,'To set the order in which they are shown when multiple consents are used. ' )
138+ ->hintIcon ('heroicon-o-information-circle ' , 'To set the order in which they are shown when multiple consents are used. ' )
89139 ->hintColor ('info ' )
90140 ->required (),
91141
92142 Forms \Components \Toggle::make ('enabled ' )
93143 ->label ('Enable this consent ' )
94- ->hintIcon ('heroicon-o-information-circle ' ,'Disabled consents will not be shown to users ' )
144+ ->hintIcon ('heroicon-o-information-circle ' , 'Disabled consents will not be shown to users ' )
95145 ->hintColor ('info ' ),
96146
97147 Forms \Components \Toggle::make ('is_current ' )
98148 ->label ('Is current consent ' )
99- ->hintIcon ('heroicon-o-information-circle ' ,'If enabled all other consents with the same key will be disabled ' )
149+ ->hintIcon ('heroicon-o-information-circle ' , 'If enabled all other consents with the same key will be disabled ' )
100150 ->hintColor ('info ' ),
101151
102152 Forms \Components \Toggle::make ('is_survey ' )
103153 ->label ('Has survey questions? ' )
104- ->hintIcon ('heroicon-o-information-circle ' ,'Enable additional survey questions ' )
154+ ->hintIcon ('heroicon-o-information-circle ' , 'Enable additional survey questions ' )
105155 ->hintColor ('info ' ),
106156
107157 Forms \Components \Toggle::make ('is_mandatory ' )
108- ->hintIcon ('heroicon-o-information-circle ' ,'User must accept this consent to proceed ' )
158+ ->hintIcon ('heroicon-o-information-circle ' , 'User must accept this consent to proceed ' )
109159 ->hintColor ('info ' ),
110160
111161 Forms \Components \Toggle::make ('force_user_update ' )
112162 ->label ('Require all users to re-confirm after this update ' )
113- ->hintIcon ('heroicon-o-information-circle ' ,'Caution, will ask all users when logging in to reconfirm this consent. ' )
163+ ->hintIcon ('heroicon-o-information-circle ' , 'Caution, will ask all users when logging in to reconfirm this consent. ' )
114164 ->hintColor ('info ' ),
115165
116166 Forms \Components \Toggle::make ('increment_version ' )
117167 ->label ('Save as a new version? ' )
118- ->hintIcon ('heroicon-o-information-circle ' ,'Enable to keep previous consent history ' )
168+ ->hintIcon ('heroicon-o-information-circle ' , 'Enable to keep previous consent history ' )
119169 ->hintColor ('info ' ),
120170
121171 Forms \Components \DateTimePicker::make ('published_at ' )
122172 ->label ('Enable From Date ' )
123- ->hintIcon ('heroicon-o-information-circle ' ,'Enable from this date ' )
173+ ->hintIcon ('heroicon-o-information-circle ' , 'Enable from this date ' )
124174 ->hintColor ('info ' )
125175 ->default (now ()->subDay ())
126176 ->native (false )
@@ -145,87 +195,38 @@ public static function form(Schema $schema): Schema
145195 Section::make ('Additional Info ' )->components ([
146196
147197 Repeater::make ('fields ' )->label ('' )
148- ->schema ([
149- Forms \Components \TextInput::make ('name ' )
150- ->regex ('/^[a-z_]+$/ ' )
151- ->required (),
152- Forms \Components \Select::make ('component ' )
153- ->options (config ('filament-user-consent.components ' ))
154- ->searchable ()
155- ->live ()
156- ->required (),
157- Forms \Components \TextInput::make ('label ' )
158- ->visible (fn (Get $ get ) => $ get ('component ' ) !== 'placeholder ' ),
159- Forms \Components \Toggle::make ('required ' )
160- ->inline (false )
161- ->required (fn (Get $ get ) => $ get ('component ' ) !== 'placeholder ' )
162- ->visible (fn (Get $ get ) => $ get ('component ' ) !== 'placeholder ' ),
163- Forms \Components \RichEditor::make ('content ' )
164- ->required (fn (Get $ get ) => $ get ('component ' ) === 'placeholder ' )
165- ->visible (fn (Get $ get ) => $ get ('component ' ) === 'placeholder ' )
166- ->columnSpanFull (),
167- Forms \Components \KeyValue::make ('options ' )
168- ->addActionLabel ('Add Option ' )
169- ->keyLabel ('Value ' )
170- ->valueLabel ('Label ' )
171- ->columnSpanFull ()
172- ->required (fn (Get $ get ) => in_array ($ get ('component ' ), ['select ' , 'radio ' , 'likert ' ]))
173- ->visible (fn (Get $ get ) => in_array ($ get ('component ' ), ['select ' , 'radio ' , 'likert ' ])),
174- ])
175- ->defaultItems (1 )
176- ->columns (2 )
177- ->addActionLabel ('Add Field ' )
178- ->collapsed ()
179- ])->visible (fn (Get $ get ) => (bool )$ get ('additional_info ' ))
180- ]);
181- }
182-
183- public static function table (Table $ table ): Table
184- {
185- return $ table
186- ->columns ([
187- Tables \Columns \TextColumn::make ('title ' )
188- ->searchable (),
189- Tables \Columns \TextColumn::make ('version ' )
190- ->sortable (),
191- Tables \Columns \IconColumn::make ('is_mandatory ' )
192- ->boolean ()
193- ->sortable (),
194- Tables \Columns \IconColumn::make ('is_survey ' )
195- ->boolean ()
196- ->sortable (),
197- Tables \Columns \IconColumn::make ('is_current ' )
198- ->boolean ()
199- ->sortable (),
200- Tables \Columns \IconColumn::make ('enabled ' )
201- ->boolean ()
202- ->sortable (),
203- Tables \Columns \IconColumn::make ('force_user_update ' )
204- ->boolean ()
205- ->sortable (),
206- Tables \Columns \TextColumn::make ('usersAcceptedTotal ' )
207- ->label ('Accepted Users ' ),
208- Tables \Columns \TextColumn::make ('usersDeclinedTotal ' )
209- ->label ('Declined Users ' ),
210- Tables \Columns \TextColumn::make ('published_at ' )
211- ->sortable (),
212- ])
213- ->filters ([
214- //
215- ])
216- ->defaultSort ('created_at ' , 'desc ' )
217- ->actions ([
218- Tables \Actions \Action::make ('Preview ' )
219- ->icon ('heroicon-m-viewfinder-circle ' )
220- ->modalHeading ("" )
221- ->modalSubmitAction (false )
222- ->modalCancelAction (false )
223- ->form ([
224- Livewire::make (ConsentOptionPreview::class),
225- ])
226- ])
227- ->bulkActions ([
228- Tables \Actions \BulkActionGroup::make ([]),
198+ ->schema ([
199+ Forms \Components \TextInput::make ('name ' )
200+ ->regex ('/^[a-z_]+$/ ' )
201+ ->required (),
202+ Forms \Components \Select::make ('component ' )
203+ ->options (config ('filament-user-consent.components ' ))
204+ ->searchable ()
205+ ->live ()
206+ ->required (),
207+ Forms \Components \TextInput::make ('label ' )
208+ ->visible (fn (Get $ get ) => $ get ('component ' ) !== 'placeholder ' ),
209+ Forms \Components \Toggle::make ('required ' )
210+ ->inline (false )
211+ ->required (fn (Get $ get ) => $ get ('component ' ) !== 'placeholder ' )
212+ ->visible (fn (Get $ get ) => $ get ('component ' ) !== 'placeholder ' ),
213+ Forms \Components \RichEditor::make ('content ' )
214+ ->required (fn (Get $ get ) => $ get ('component ' ) === 'placeholder ' )
215+ ->visible (fn (Get $ get ) => $ get ('component ' ) === 'placeholder ' )
216+ ->columnSpanFull (),
217+ Forms \Components \KeyValue::make ('options ' )
218+ ->addActionLabel ('Add Option ' )
219+ ->keyLabel ('Value ' )
220+ ->valueLabel ('Label ' )
221+ ->columnSpanFull ()
222+ ->required (fn (Get $ get ) => in_array ($ get ('component ' ), ['select ' , 'radio ' , 'likert ' ]))
223+ ->visible (fn (Get $ get ) => in_array ($ get ('component ' ), ['select ' , 'radio ' , 'likert ' ])),
224+ ])
225+ ->defaultItems (1 )
226+ ->columns (2 )
227+ ->addActionLabel ('Add Field ' )
228+ ->collapsed ()
229+ ])->visible (fn (Get $ get ) => (bool ) $ get ('additional_info ' ))
229230 ]);
230231 }
231232
@@ -239,9 +240,9 @@ public static function getRelations(): array
239240 public static function getPages (): array
240241 {
241242 return [
242- 'index ' => ListConsentOptions::route ('/ ' ),
243+ 'index ' => ListConsentOptions::route ('/ ' ),
243244 'create ' => CreateConsentOption::route ('/create ' ),
244- 'edit ' => EditConsentOption::route ('/{record}/edit ' ),
245+ 'edit ' => EditConsentOption::route ('/{record}/edit ' ),
245246 ];
246247 }
247248}
0 commit comments