44
55namespace Moox \Tag \Resources ;
66
7- use Filament \Schemas \Schema ;
8- use Filament \Schemas \Components \Grid ;
9- use Filament \Schemas \Components \Section ;
10- use Filament \Schemas \Components \Tabs ;
11- use Filament \Schemas \Components \Actions ;
12- use Filament \Actions \Action ;
13- use Filament \Actions \ViewAction ;
14- use Filament \Actions \EditAction ;
157use Filament \Actions \DeleteBulkAction ;
8+ use Filament \Actions \EditAction ;
169use Filament \Actions \RestoreBulkAction ;
17- use Filament \Schemas \Components \Tabs \Tab ;
18- use Filament \Schemas \Components \Utilities \Set ;
10+ use Filament \Actions \ViewAction ;
1911use Filament \Forms \Components \ColorPicker ;
2012use Filament \Forms \Components \DateTimePicker ;
2113use Filament \Forms \Components \MarkdownEditor ;
2214use Filament \Forms \Components \TextInput ;
23- use Filament \Resources \Resource ;
15+ use Filament \Schemas \Components \Grid ;
16+ use Filament \Schemas \Components \Section ;
17+ use Filament \Schemas \Components \Tabs ;
18+ use Filament \Schemas \Components \Tabs \Tab ;
19+ use Filament \Schemas \Components \Utilities \Set ;
20+ use Filament \Schemas \Schema ;
2421use Filament \Tables \Columns \ColorColumn ;
2522use Filament \Tables \Columns \TextColumn ;
2623use Filament \Tables \Table ;
2724use Illuminate \Database \Eloquent \Builder ;
2825use Illuminate \Database \Eloquent \SoftDeletes ;
2926use Illuminate \Support \Str ;
3027use Illuminate \Validation \Rules \Unique ;
28+ use Moox \Core \Entities \Items \Draft \BaseDraftResource ;
3129use Moox \Core \Traits \Tabs \HasResourceTabs ;
3230use Moox \Localization \Filament \Tables \Columns \TranslationColumn ;
3331use Moox \Localization \Models \Localization ;
4038use Moox \Tag \Resources \TagResource \Pages \ViewTag ;
4139use Override ;
4240
43- class TagResource extends Resource
41+ class TagResource extends BaseDraftResource
4442{
4543 use HasResourceTabs;
4644
@@ -54,7 +52,7 @@ public static function getEloquentQuery(): Builder
5452 return parent ::getEloquentQuery ()->withoutGlobalScopes ();
5553 }
5654
57- protected static string | \BackedEnum | null $ navigationIcon = 'gmdi-label ' ;
55+ protected static string | \BackedEnum | null $ navigationIcon = 'gmdi-label ' ;
5856
5957 protected static ?string $ authorModel = null ;
6058
@@ -63,100 +61,48 @@ public static function form(Schema $schema): Schema
6361 {
6462 static ::initUserModel ();
6563
66- return $ schema ->components ([
67- Grid::make (2 )
68- ->schema ([
69- Grid::make ()
70- ->schema ([
71- Section::make ()
72- ->schema ([
73- MediaPicker::make ('featured_image_url ' )
74- ->label (__ ('core::core.featured_image_url ' ))
75- ->multiple (),
76- Tabs::make ('Translations ' )
77- ->tabs (self ::generateTranslationTabs ()),
78- ]),
79- ])
80- ->columnSpan (['lg ' => 2 ]),
81- Grid::make ()
82- ->schema ([
83- Section::make ()
84- ->schema ([
85- Actions::make ([
86- Action::make ('restore ' )
87- ->label (__ ('core::core.restore ' ))
88- ->color ('success ' )
89- ->button ()
90- ->extraAttributes (['class ' => 'w-full ' ])
91- ->action (fn ($ record ) => $ record ->restore ())
64+ return $ schema
65+ ->schema ([
66+ Grid::make ()
67+ ->schema ([
68+ Section::make ()
69+ ->schema ([
70+ MediaPicker::make ('featured_image_url ' )
71+ ->label (__ ('core::core.featured_image_url ' )),
72+ Tabs::make ('Translations ' )
73+ ->tabs (self ::generateTranslationTabs ()),
74+ ])
75+ ->columnSpan (2 ),
76+ Grid::make ()
77+ ->schema ([
78+ Section::make ()
79+ ->schema ([
80+ static ::getFormActions (),
81+ ]),
82+ Section::make ('' )
83+ ->schema ([
84+ ColorPicker::make ('color ' ),
85+ TextInput::make ('weight ' ),
86+ TextInput::make ('count ' )
87+ ->disabled ()
88+ ->visible (fn ($ livewire , $ record ): bool => ($ record && $ livewire instanceof EditTag) || ($ record && $ livewire instanceof ViewTag)),
89+ DateTimePicker::make ('created_at ' )
90+ ->disabled ()
91+ ->visible (fn ($ livewire , $ record ): bool => ($ record && $ livewire instanceof EditTag) || ($ record && $ livewire instanceof ViewTag)),
92+ DateTimePicker::make ('updated_at ' )
93+ ->disabled ()
94+ ->visible (fn ($ livewire , $ record ): bool => ($ record && $ livewire instanceof EditTag) || ($ record && $ livewire instanceof ViewTag)),
95+ DateTimePicker::make ('deleted_at ' )
96+ ->disabled ()
9297 ->visible (fn ($ livewire , $ record ): bool => $ record && $ record ->trashed () && $ livewire instanceof ViewTag),
93- Action::make ('save ' )
94- ->label (__ ('core::core.save ' ))
95- ->color ('primary ' )
96- ->button ()
97- ->extraAttributes (['class ' => 'w-full ' ])
98- ->action (function ($ livewire ): void {
99- $ livewire instanceof CreateTag ? $ livewire ->create () : $ livewire ->save ();
100- })
101- ->visible (fn ($ livewire ): bool => $ livewire instanceof CreateTag || $ livewire instanceof EditTag),
102- Action::make ('saveAndCreateAnother ' )
103- ->label (__ ('core::core.save_and_create_another ' ))
104- ->color ('secondary ' )
105- ->button ()
106- ->extraAttributes (['class ' => 'w-full ' ])
107- ->action (function ($ livewire ): void {
108- $ livewire ->saveAndCreateAnother ();
109- })
110- ->visible (fn ($ livewire ): bool => $ livewire instanceof CreateTag),
111- Action::make ('cancel ' )
112- ->label (__ ('core::core.cancel ' ))
113- ->color ('secondary ' )
114- ->outlined ()
115- ->extraAttributes (['class ' => 'w-full ' ])
116- ->url (fn (): string => static ::getUrl ('index ' ))
117- ->visible (fn ($ livewire ): bool => $ livewire instanceof CreateTag),
118- Action::make ('edit ' )
119- ->label (__ ('core::core.edit ' ))
120- ->color ('primary ' )
121- ->button ()
122- ->extraAttributes (['class ' => 'w-full ' ])
123- ->url (fn ($ record ): string => static ::getUrl ('edit ' , ['record ' => $ record , 'lang ' => request ()->get ('lang ' )]))
124- ->visible (fn ($ livewire , $ record ): bool => $ livewire instanceof ViewTag && ! $ record ->trashed ()),
125- Action::make ('restore ' )
126- ->label (__ ('core::core.restore ' ))
127- ->color ('success ' )
128- ->button ()
129- ->extraAttributes (['class ' => 'w-full ' ])
130- ->action (fn ($ record ) => $ record ->restore ())
131- ->visible (fn ($ livewire , $ record ): bool => $ record && $ record ->trashed () && $ livewire instanceof EditTag),
132- Action::make ('delete ' )
133- ->label (__ ('core::core.delete ' ))
134- ->color ('danger ' )
135- ->link ()
136- ->extraAttributes (['class ' => 'w-full ' ])
137- ->action (fn ($ record ) => $ record ->delete ())
138- ->visible (fn ($ livewire , $ record ): bool => $ record && ! $ record ->trashed () && $ livewire instanceof EditTag),
13998 ]),
140- ColorPicker::make ('color ' ),
141- TextInput::make ('weight ' ),
142- TextInput::make ('count ' )
143- ->disabled ()
144- ->visible (fn ($ livewire , $ record ): bool => ($ record && $ livewire instanceof EditTag) || ($ record && $ livewire instanceof ViewTag)),
145- DateTimePicker::make ('created_at ' )
146- ->disabled ()
147- ->visible (fn ($ livewire , $ record ): bool => ($ record && $ livewire instanceof EditTag) || ($ record && $ livewire instanceof ViewTag)),
148- DateTimePicker::make ('updated_at ' )
149- ->disabled ()
150- ->visible (fn ($ livewire , $ record ): bool => ($ record && $ livewire instanceof EditTag) || ($ record && $ livewire instanceof ViewTag)),
151- DateTimePicker::make ('deleted_at ' )
152- ->disabled ()
153- ->visible (fn ($ livewire , $ record ): bool => $ record && $ record ->trashed () && $ livewire instanceof ViewTag),
154- ]),
155- ])
156- ->columnSpan (['lg ' => 1 ]),
157- ])
158- ->columns (['lg ' => 3 ]),
159- ]);
99+ ])
100+ ->columns (1 )
101+ ->columnSpan (1 ),
102+ ])
103+ ->columns (3 )
104+ ->columnSpanFull (),
105+ ]);
160106 }
161107
162108 #[Override]
0 commit comments