diff --git a/packages/builder/DEVLOG.md b/packages/builder/DEVLOG.md index 5b0e6c4bc..d62e8f722 100644 --- a/packages/builder/DEVLOG.md +++ b/packages/builder/DEVLOG.md @@ -6,13 +6,18 @@ We work on these tasks in order from top to bottom: ### Entity -- [ ] Config and translations have wrong filenames and must be wired correctly -- [ ] Do we use the entity_blocks and entity_tabs tables anymore? -- [ ] Iterate over all blocks, presets and contexts to find out if they are working as expected -- [ ] Need to generate Tabs, Taxonomy and Relations partials, may already work partially -- [ ] Add --migration option to create command +- [WIP] Iterate over all blocks, presets and contexts to find out if they are working as expected + + - [ ] The Resource needs a more complex layout introducing regions + - [ ] Presets need to be able to define where blocks should be placed + + - [ ] Add default actions or try to add the Publish Traits first, then use actions to test the entities + + - [ ] Config and translations have wrong filenames and must be wired correctly + - [ ] Need to generate Tabs, Taxonomy and Relations partials, may already work partially + - [ ] Refactor DeleteCommand to use new services -- [ ] Polish Entity Builder +- [ ] Add --migration option to create command - [ ] Would Builder now be able to generate itself? ### Extras diff --git a/packages/builder/src/Blocks/AbstractBlock.php b/packages/builder/src/Blocks/AbstractBlock.php index 151e47006..d71716ee0 100644 --- a/packages/builder/src/Blocks/AbstractBlock.php +++ b/packages/builder/src/Blocks/AbstractBlock.php @@ -68,6 +68,18 @@ abstract class AbstractBlock 'resource' => [], ]; + protected array $formSections = [ + 'resource' => [], + ]; + + protected array $metaFields = [ + 'resource' => [], + ]; + + protected array $metaSections = [ + 'resource' => [], + ]; + protected array $tableColumns = [ 'resource' => [], ]; diff --git a/packages/builder/src/Blocks/Publish.php b/packages/builder/src/Blocks/Publish.php index 55303515e..42a53ac31 100644 --- a/packages/builder/src/Blocks/Publish.php +++ b/packages/builder/src/Blocks/Publish.php @@ -36,12 +36,16 @@ public function __construct( ], ], 'pages' => [ - 'list' => ['use Illuminate\Database\Eloquent\Builder;'], + 'list' => [ + 'use Moox\Core\Traits\SinglePublishInListPage;', + 'use Illuminate\Database\Eloquent\Builder;', + ], ], ]; $this->traits['model'] = ['SinglePublishInModel']; $this->traits['resource'] = ['SinglePublishInResource']; + $this->traits['pages']['list'] = ['SinglePublishInListPage']; $this->methods['model'] = [ 'scopes' => [ @@ -71,9 +75,18 @@ public function __construct( ]; $this->formFields['resource'] = [ + ]; + + $this->formSections['resource'] = [ + ]; + + $this->metaFields['resource'] = [ "DateTimePicker::make('publish_at') - ->label(__('core::core.publish_at')) - ->nullable()", + ->label(__('core::core.publish_at')) + ->nullable()", + ]; + + $this->metaSections['resource'] = [ ]; $this->tableColumns['resource'] = [ diff --git a/packages/builder/src/Blocks/Text.php b/packages/builder/src/Blocks/Text.php index 26636cac0..ca27ee147 100644 --- a/packages/builder/src/Blocks/Text.php +++ b/packages/builder/src/Blocks/Text.php @@ -21,7 +21,6 @@ public function __construct( $this->useStatements['resource'] = [ 'forms' => ['use Filament\Forms\Components\TextInput;'], 'columns' => ['use Filament\Tables\Columns\TextColumn;'], - 'filters' => ['use Filament\Tables\Filters\TextFilter;'], ]; $this->formFields['resource'] = [ @@ -37,10 +36,6 @@ public function __construct( .($this->searchable ? '->searchable()' : ''), ]; - $this->filters['resource'] = [ - "TextFilter::make('{$this->name}')", - ]; - $this->migrations['fields'] = [ "\$table->string('{$this->name}', {$this->length})" .($this->nullable ? '->nullable()' : ''), diff --git a/packages/builder/src/Blocks/TextArea.php b/packages/builder/src/Blocks/TextArea.php index c6430c24d..cdea97c77 100644 --- a/packages/builder/src/Blocks/TextArea.php +++ b/packages/builder/src/Blocks/TextArea.php @@ -22,7 +22,6 @@ public function __construct( 'resource' => [ 'forms' => ['use Filament\Forms\Components\Textarea;'], 'columns' => ['use Filament\Tables\Columns\TextColumn;'], - 'filters' => ['use Filament\Tables\Filters\TextFilter;'], ], ]; @@ -41,10 +40,6 @@ public function __construct( .($this->sortable ? '->sortable()' : ''), ]; - $this->filters['resource'] = [ - "TextFilter::make('{$this->name}')", - ]; - $this->migrations['fields'] = [ "\$table->text('{$this->name}')" .($this->nullable ? '->nullable()' : ''), diff --git a/packages/builder/src/Generators/Entity/Pages/AbstractPageGenerator.php b/packages/builder/src/Generators/Entity/Pages/AbstractPageGenerator.php index d907039df..6bcd4be68 100644 --- a/packages/builder/src/Generators/Entity/Pages/AbstractPageGenerator.php +++ b/packages/builder/src/Generators/Entity/Pages/AbstractPageGenerator.php @@ -90,4 +90,46 @@ protected function getTemplateFile(): string return $templatePath; } + + protected function formatUseStatements(): string + { + $statements = []; + foreach ($this->getBlocks() as $block) { + $pageType = strtolower($this->getPageType()); + + $blockStatements = $block->getUseStatements('pages'); + if (isset($blockStatements[$pageType])) { + $statements = array_merge($statements, $blockStatements[$pageType]); + } + + $blockTraits = $block->getTraits('pages'); + if (isset($blockTraits[$pageType])) { + foreach ($blockTraits[$pageType] as $trait) { + $statements[] = 'use Moox\Core\Traits\\'.$trait.';'; + } + } + } + + return implode("\n", array_map(function ($statement) { + return rtrim($statement, ';').';'; + }, array_unique($statements))); + } + + protected function formatTraits(): string + { + $traits = []; + foreach ($this->getBlocks() as $block) { + $pageType = strtolower($this->getPageType()); + $blockTraits = $block->getTraits('pages'); + if (isset($blockTraits[$pageType])) { + $traits = array_merge($traits, $blockTraits[$pageType]); + } + } + + if (empty($traits)) { + return ''; + } + + return 'use '.implode(', ', array_unique($traits)).';'; + } } diff --git a/packages/builder/src/Templates/Entity/resource.php.stub b/packages/builder/src/Templates/Entity/resource.php.stub index 62e2b28f6..9c06845bd 100644 --- a/packages/builder/src/Templates/Entity/resource.php.stub +++ b/packages/builder/src/Templates/Entity/resource.php.stub @@ -5,6 +5,8 @@ declare(strict_types=1); namespace {{ namespace }}; use Filament\Resources\Resource; +use Filament\Forms\Components\Grid; +use Filament\Forms\Components\Section; {{ use_statements }} class {{ class_name }}Resource extends Resource @@ -19,7 +21,30 @@ class {{ class_name }}Resource extends Resource { {{ form_setup }} return $form->schema([ - {{ form_schema }} + Grid::make(2) + ->schema([ + Grid::make() + ->schema([ + Section::make() + ->schema([ + {{ form_schema }} + ]), + + {{ form_sections }} + ]) + ->columnSpan(['lg' => 2]), + Grid::make() + ->schema([ + Section::make() + ->schema([ + {{ meta_fields }} + ]), + + {{ meta_sections }} + ]) + ->columnSpan(['lg' => 1]), + ]) + ->columns(['lg' => 3]), ]); } diff --git a/packages/core/src/Traits/SinglePublishInListPage.php b/packages/core/src/Traits/SinglePublishInListPage.php new file mode 100644 index 000000000..d108ccf6f --- /dev/null +++ b/packages/core/src/Traits/SinglePublishInListPage.php @@ -0,0 +1,39 @@ +using(function (array $data, string $model): Item { + return $model::create($data); + }) + ->hidden(fn () => $this->activeTab === 'deleted'), + Action::make('emptyTrash') + ->label(__('core::core.empty_trash')) + ->icon('heroicon-o-trash') + ->color('danger') + ->action(function () { + $trashedCount = Item::onlyTrashed()->count(); + Item::onlyTrashed()->forceDelete(); + Notification::make() + ->title(__('core::core.trash_emptied_successfully')) + ->body(trans_choice('core::core.items_permanently_deleted', $trashedCount, ['count' => $trashedCount])) + ->success() + ->send(); + }) + ->requiresConfirmation() + ->visible(fn () => $this->activeTab === 'deleted' && Item::onlyTrashed()->exists()), + ]; + } +} diff --git a/packages/core/src/Traits/SinglePublishInPages.php b/packages/core/src/Traits/SinglePublishInPages.php deleted file mode 100644 index be7910a49..000000000 --- a/packages/core/src/Traits/SinglePublishInPages.php +++ /dev/null @@ -1,15 +0,0 @@ -