Skip to content

Commit a14a91a

Browse files
committed
wip
1 parent 6948fb0 commit a14a91a

File tree

7 files changed

+163
-67
lines changed

7 files changed

+163
-67
lines changed

docs/_devlog/Alf.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@
77
- [x] Item migration
88
- [x] Item Resource
99
- [x] Item Pages
10+
- [ ] Item Fields (see Item README)
1011
- [ ] Item Factory
1112
- [ ] Item Frontend
12-
- [ ] Item Fields (see Item README)
13+
- [x] Item Plugin
14+
- [ ] Taxonomies
15+
- [ ] Relations
16+
- [ ] Sections
17+
- [ ] Modules
1318
- [ ] Implement Record Entity
14-
- [ ] Base with SoftDeletes
19+
- [ ] Base Record with SoftDeletes
1520
- [ ] Generate package
1621
- [ ] Add fields
1722
- [ ] Build should replace with variables, not the placeholders

packages/core/src/Entities/Items/Item/BaseItemModel.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44

55
use Illuminate\Database\Eloquent\Model;
66

7-
class BaseItemModel extends Model
7+
abstract class BaseItemModel extends Model
88
{
9-
// nothing for now
9+
public static function getResourceName(): string
10+
{
11+
$className = class_basename(static::class);
12+
13+
return strtolower($className);
14+
}
1015
}

packages/item/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ Item is a simple Moox Entity, that can be used to create and manage simple entri
1212
- Active (Toggle)
1313
- Description (Editor)
1414
- Content (Markdown)
15-
- Data (JSON)
15+
- Data (Key-Value)
1616
- Image (Media)
1717
- Author (User)
1818
- Type (Select)
19-
- DateTime (DateTime)
19+
- Due (DateTime)
2020
- Color
2121
- UUID
2222
- ULID

packages/item/database/migrations/create_items_table.php.stub

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,18 @@ return new class extends Migration
1515
$table->id();
1616
$table->string('title');
1717
$table->string('slug')->unique();
18-
$table->string('featured_image_url')->nullable();
18+
$table->boolean('is_active')->default(true);
19+
$table->text('description')->nullable();
1920
$table->text('content')->nullable();
21+
$table->json('data')->nullable();
22+
$table->string('image')->nullable();
23+
$table->foreignId('author_id')->nullable()->constrained('users')->nullOnDelete();
24+
$table->string('type')->nullable();
25+
$table->dateTime('due_at')->nullable();
26+
$table->string('color')->nullable();
27+
$table->uuid('uuid')->unique();
28+
$table->ulid('ulid')->unique();
29+
$table->string('status')->nullable();
2030
$table->timestamps();
2131
});
2232
}

packages/item/src/ItemServiceProvider.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,14 @@ public function configureMoox(Package $package): void
5555
'database/factories/ItemFactory.php',
5656
'database/migrations/create_items_table.php.stub',
5757
'resources/lang/en/item.php',
58-
'src/Moox/Item/ItemPlugin.php',
5958
'src/Models/Item.php',
60-
'src/Resources/ItemResource.php',
61-
'src/Resources/ItemResource\Pages\CreateItem.php',
62-
'src/Resources/PublishItemResource\Pages\EditPublishItem.php',
63-
'src/Resources/PublishItemResource\Pages\ListPublishItems.php',
64-
'src/Resources/PublishItemResource\Pages\ViewPublishItem.php',
59+
'src/Moox/Entities/Items/Item/Frontend/ItemFrontend.php',
60+
'src/Moox/Entities/Items/Item/Pages/CreateItem.php',
61+
'src/Moox/Entities/Items/Item/Pages/EditItem.php',
62+
'src/Moox/Entities/Items/Item/Pages/ListItems.php',
63+
'src/Moox/Entities/Items/Item/Pages/ViewItem.php',
64+
'src/Moox/Entities/Items/Item/ItemResource.php',
65+
'src/Moox/Plugins/ItemPlugin.php',
6566
])
6667
->templateRemove([
6768
'',

packages/item/src/Models/Item.php

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,51 @@
22

33
namespace Moox\Item\Models;
44

5+
use App\Models\User;
6+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
57
use Moox\Core\Entities\Items\Item\BaseItemModel;
68

79
class Item extends BaseItemModel
810
{
911
protected $fillable = [
1012
'title',
1113
'slug',
14+
'is_active',
15+
'description',
1216
'content',
13-
'tabs',
14-
'taxonomy',
15-
'taxonomy',
16-
'street',
17-
'city',
18-
'postal_code',
19-
'country',
20-
'status',
17+
'data',
18+
'image',
19+
'author_id',
2120
'type',
21+
'color',
22+
'due_at',
23+
'uuid',
24+
'ulid',
25+
'status',
2226
];
2327

2428
protected $casts = [
2529
'slug' => 'string',
2630
'title' => 'string',
31+
'is_active' => 'boolean',
32+
'data' => 'json',
33+
'due_at' => 'datetime',
34+
'uuid' => 'string',
35+
'ulid' => 'string',
2736
];
2837

29-
// protected function getResourceName(): string
30-
// {
31-
// return 'item';
32-
// }
38+
public function author(): BelongsTo
39+
{
40+
return $this->belongsTo(User::class, 'author_id');
41+
}
42+
43+
protected static function boot()
44+
{
45+
parent::boot();
46+
47+
static::creating(function ($model) {
48+
$model->uuid = (string) \Illuminate\Support\Str::uuid();
49+
$model->ulid = (string) \Illuminate\Support\Str::ulid();
50+
});
51+
}
3352
}

packages/item/src/Moox/Entities/Items/Item/ItemResource.php

Lines changed: 98 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,25 @@
33
namespace Moox\Item\Moox\Entities\Items\Item;
44

55
use Camya\Filament\Forms\Components\TitleWithSlugInput;
6+
use Filament\Forms\Components\ColorPicker;
7+
use Filament\Forms\Components\DateTimePicker;
8+
use Filament\Forms\Components\FileUpload;
69
use 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;
714
use Filament\Forms\Components\Section;
815
use Filament\Forms\Components\Select;
9-
use Filament\Forms\Components\Textarea;
1016
use Filament\Forms\Components\TextInput;
17+
use Filament\Forms\Components\Toggle;
1118
use Filament\Forms\Form;
19+
use Filament\Tables\Columns\ColorColumn;
20+
use Filament\Tables\Columns\IconColumn;
1221
use Filament\Tables\Columns\TextColumn;
1322
use Filament\Tables\Filters\Filter;
1423
use Filament\Tables\Filters\SelectFilter;
24+
use Filament\Tables\Filters\TernaryFilter;
1525
use Filament\Tables\Table;
1626
use Illuminate\Database\Eloquent\Builder;
1727
use Moox\Core\Entities\Items\Item\BaseItemResource;
@@ -20,7 +30,7 @@
2030

2131
class 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

Comments
 (0)