33namespace Moox\Item\Moox\Entities\Items\Item;
44
55use Camya\Filament\Forms\Components\TitleWithSlugInput;
6+ use Filament\Forms\Components\ColorPicker;
7+ use Filament\Forms\Components\DateTimePicker;
8+ use Filament\Forms\Components\FileUpload;
69use Filament\Forms\Components\Grid;
10+ use Filament\Forms\Components\KeyValue;
11+ use Filament\Forms\Components\MarkdownEditor;
12+ use Filament\Forms\Components\Placeholder;
13+ use Filament\Forms\Components\RichEditor;
714use Filament\Forms\Components\Section;
815use Filament\Forms\Components\Select;
9- use Filament\Forms\Components\Textarea;
1016use Filament\Forms\Components\TextInput;
17+ use Filament\Forms\Components\Toggle;
1118use Filament\Forms\Form;
19+ use Filament\Tables\Columns\ColorColumn;
20+ use Filament\Tables\Columns\IconColumn;
1221use Filament\Tables\Columns\TextColumn;
1322use Filament\Tables\Filters\Filter;
1423use Filament\Tables\Filters\SelectFilter;
24+ use Filament\Tables\Filters\TernaryFilter;
1525use Filament\Tables\Table;
1626use Illuminate\Database\Eloquent\Builder;
1727use Moox\Core\Entities\Items\Item\BaseItemResource;
2030
2131class ItemResource extends BaseItemResource
2232{
23- // use HasResourceTaxonomy;
33+ use HasResourceTaxonomy;
2434
2535 protected static ?string $model = Item::class;
2636
@@ -69,15 +79,18 @@ public static function form(Form $form): Form
6979 fieldTitle: 'title',
7080 fieldSlug: 'slug',
7181 ),
72- Textarea::make('content')
73- ->label('Content')->required(),
74- ]),
75- Section::make('Address')
76- ->schema([
77- TextInput::make('street'),
78- TextInput::make('city'),
79- TextInput::make('postal_code'),
80- TextInput::make('country'),
82+ Toggle::make('is_active')
83+ ->label('Active'),
84+ RichEditor::make('description')
85+ ->label('Description'),
86+ MarkdownEditor::make('content')
87+ ->label('Content'),
88+ KeyValue::make('data')
89+ ->label('Data (JSON)'),
90+ FileUpload::make('image')
91+ ->label('Image')
92+ ->directory('items')
93+ ->image(),
8194 ]),
8295 ])
8396 ->columnSpan(['lg' => 2]),
@@ -89,22 +102,48 @@ public static function form(Form $form): Form
89102 ]),
90103 Section::make('')
91104 ->schema([
105+ Select::make('type')
106+ ->label('Type')
107+ ->options(['Post' => 'Post', 'Page' => 'Page']),
108+
92109 Select::make('status')
93110 ->label('Status')
94111 ->placeholder(__('core::core.status'))
95- ->options(['Probably' => 'Probably', 'Never' => 'Never', 'Done' => 'Done', 'Maybe' => 'Maybe'])
96- ->required(),
112+ ->options(['Probably' => 'Probably', 'Never' => 'Never', 'Done' => 'Done', 'Maybe' => 'Maybe']),
97113 ]),
114+ Section::make('')
115+ ->schema(static::getTaxonomyFields()),
98116 Section::make('')
99117 ->schema([
100- Select::make('type')
101- ->label('Type')
102- ->placeholder(__('core::core.type'))
103- ->options(['Post' => 'Post', 'Page' => 'Page'])
104- ->required(),
118+ Select::make('author_id')
119+ ->label('Author')
120+ ->relationship('author', 'name'),
121+ DateTimePicker::make('due_at')
122+ ->label('Due'),
123+ ColorPicker::make('color')
124+ ->label('Color'),
105125 ]),
106- // Section::make('')
107- // ->schema(static::getTaxonomyFields()),
126+ Section::make('')
127+ ->schema([
128+ Placeholder::make('id')
129+ ->label('ID')
130+ ->content(fn ($record): string => $record->id ?? '-'),
131+ Placeholder::make('uuid')
132+ ->label('UUID')
133+ ->content(fn ($record): string => $record->uuid ?? '-'),
134+ Placeholder::make('ulid')
135+ ->label('ULID')
136+ ->content(fn ($record): string => $record->ulid ?? '-'),
137+ Placeholder::make('created_at')
138+ ->label('Created')
139+ ->content(fn ($record): string => $record->created_at ?
140+ $record->created_at.' ('.$record->created_at->diffForHumans().')' : ''),
141+ Placeholder::make('updated_at')
142+ ->label('Last Updated')
143+ ->content(fn ($record): string => $record->updated_at ?
144+ $record->updated_at.' ('.$record->updated_at->diffForHumans().')' : ''),
145+ ])
146+ ->hidden(fn ($record) => $record === null),
108147 ])
109148 ->columnSpan(['lg' => 1]),
110149 ])
@@ -119,19 +158,51 @@ public static function table(Table $table): Table
119158 TextColumn::make('title')
120159 ->searchable()
121160 ->sortable(),
161+ IconColumn::make('is_active')
162+ ->boolean()
163+ ->label('Active')
164+ ->sortable(),
122165 TextColumn::make('slug')
123166 ->searchable()
124167 ->sortable(),
168+ TextColumn::make('description')
169+ ->limit(50)
170+ ->toggleable(isToggledHiddenByDefault: true),
125171 TextColumn::make('content')
126- ->limit(50),
172+ ->limit(50)
173+ ->toggleable(isToggledHiddenByDefault: true),
174+ TextColumn::make('author.name')
175+ ->label('Author')
176+ ->sortable()
177+ ->toggleable(),
178+ TextColumn::make('type')
179+ ->sortable()
180+ ->searchable(),
181+ TextColumn::make('published_at')
182+ ->dateTime()
183+ ->sortable()
184+ ->toggleable(),
185+ ColorColumn::make('color')
186+ ->toggleable(),
187+ TextColumn::make('uuid')
188+ ->toggleable(isToggledHiddenByDefault: true),
189+ TextColumn::make('ulid')
190+ ->toggleable(isToggledHiddenByDefault: true),
191+ TextColumn::make('section')
192+ ->sortable()
193+ ->toggleable(),
127194 // ...static::getTaxonomyColumns(),
128- TextColumn::make('status')->sortable()->searchable()->toggleable(),
129- TextColumn::make('type')->sortable()->searchable()->toggleable(),
195+ TextColumn::make('status')
196+ ->sortable()
197+ ->searchable()
198+ ->toggleable(),
130199 ])
131200 ->defaultSort('title', 'desc')
132201 ->actions([...static::getTableActions()])
133202 ->bulkActions([...static::getBulkActions()])
134203 ->filters([
204+ TernaryFilter::make('is_active')
205+ ->label('Active'),
135206 Filter::make('title')
136207 ->form([
137208 TextInput::make('title')
@@ -151,25 +222,6 @@ public static function table(Table $table): Table
151222
152223 return 'Title: '.$data['title'];
153224 }),
154- Filter::make('slug')
155- ->form([
156- TextInput::make('slug')
157- ->label(__('core::core.slug'))
158- ->placeholder(__('core::core.filter').' Title'),
159- ])
160- ->query(function (Builder $query, array $data): Builder {
161- return $query->when(
162- $data['slug'],
163- fn (Builder $query, $value): Builder => $query->where('slug', 'like', "%{$value}%"),
164- );
165- })
166- ->indicateUsing(function (array $data): ?string {
167- if (! $data['slug']) {
168- return null;
169- }
170-
171- return __('core::core.slug').': '.$data['slug'];
172- }),
173225 SelectFilter::make('status')
174226 ->label('Status')
175227 ->placeholder(__('core::core.filter').' Status')
@@ -178,6 +230,10 @@ public static function table(Table $table): Table
178230 ->label('Type')
179231 ->placeholder(__('core::core.filter').' Type')
180232 ->options(['Post' => 'Post', 'Page' => 'Page']),
233+ SelectFilter::make('section')
234+ ->label('Section')
235+ ->placeholder(__('core::core.filter').' Section')
236+ ->options(['Header' => 'Header', 'Main' => 'Main', 'Footer' => 'Footer']),
181237 ]);
182238 }
183239
0 commit comments