Skip to content

Commit

Permalink
Builder wip
Browse files Browse the repository at this point in the history
  • Loading branch information
adrolli committed Dec 4, 2024
1 parent fb91c83 commit b7e9e1b
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 128 deletions.
44 changes: 14 additions & 30 deletions packages/builder/DEVLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,28 @@ We work on these tasks in order from top to bottom:

## Tasks

### General (WIP)

From publishable item we learn that TitleWithSlug should implement it's own section, it currently seems to add a comma, why?
Another issue is that the List page is missing the eloquent builder use statement, why?
After fixing that, the list page has other issues too.
Tabs are not generated from the Publish block, should overwrite Tabs block

We need to document the new section API and section classes.

And we need to fix the issue with the FullItem, maybe we need a new way to handle relations like author, user, etc.
Failed to create entity: SQLSTATE[HY000]: General error: 1824 Failed to open the referenced table 'authors' (Connection: mysql, SQL: alter table `preview_preview_full_items` add constraint `preview_preview_full_items_author_id_foreign` foreign key (`author_id`) references `authors` (`id`) on delete cascade)

### Entity

- [WIP] We currently work on generating Presets in Preview Context and optimize the generated resources
- [WIP] PreviewSimItem is working like a charm including actions, filters, bulk actions and taxonomies
- [ ] Delete does not delete the record
- [ ] Status field is not working as expected, completely weird behavior
- [x] PreviewSimItem is working like a charm including actions, filters, bulk actions, tabs and taxonomies
- [WIP] PreviewPubItem
- [ ] Saving is not working, trait or code in pages or resource missing? Must be for TitleWithSlug block
- [ ] List page is missing the eloquent builder use statement, why?
- [ ] After fixing that, the list page has other issues too.
- [ ] Uniqueness is not implemented or not used?
- [ ] Taxonomies needs to be tested, TaxonomyInPages has issues
- [ ] Page / AbstractPage generators need section-based API implementation?
- [ ] Relations needs
- [ ] to be implemented first, because relations is a bit different to taxonomies
- [ ] to be generated in the Resource
- [ ] to be generated in the Config
- [WIP] PreviewPubItem
- [ ] We need to bring this on the Simple Item level first
- [ ] Tabs needs to be implemented and should replace the simple tabs
- [ ] Taxonomies needs to be tested, TaxonomyInPages has issues
- [ ] TitleWithSlug should implement it's own section
- [ ] Relations
- [ ] Actions need to work as expected
- [ ] RelationManager?
- [ ] Page / AbstractPage generators need section-based API implementation?
- [ ] We need to work on the publish feature with custom actions, see https://youtu.be/bjv_RiBUtNs?si=cellheQYyxhiHxRg&t=167
- [ ] Then we need to implement the relation feature
- [WIP] PreviewFullItem
- [ ] Add author when fixed
- [ ] PreviewFullItem
- [ ] We need a new way to handle relations like author, user, etc. from the block to fix:
Failed to create entity: SQLSTATE[HY000]: General error: 1824 Failed to open the referenced table 'authors' (Connection: mysql, SQL: alter table `preview_preview_full_items` add constraint `preview_preview_full_items_author_id_foreign` foreign key (`author_id`) references `authors` (`id`) on delete cascade)
- [ ] We need to bring this on the Publish Item level first
- [ ] We need to work on all existing blocks and generate theme here
- [ ] Maybe add the three widgets here, needs wiget-generator and template?
Expand All @@ -52,10 +39,7 @@ Failed to create entity: SQLSTATE[HY000]: General error: 1824 Failed to open the
- [ ] Then we need to implement the soft delete feature
- [ ] Then it need Category specific implementation with nested set
- [ ] Iterate over all blocks, presets and contexts to find out if they are working as expected
- [ ] Moox Core Features need to be refactored to be able to generate them without issues, eliminate methods and move to traits
- [ ] Publish feature seems to miss the save method
- [ ] Relations, like Taxonomies, but "on the left"
- [ ] Relations like Taxonomies, and what about Relationsmanagers?
- [ ] Moox Core Features need to be documented
- [ ] Naming convention InModel InResource InPages and Single for single-use traits
- [ ] TabsInResource - contains TODO
- [ ] TabsInListPage - just getTabs needs to be defined
Expand All @@ -64,11 +48,11 @@ Failed to create entity: SQLSTATE[HY000]: General error: 1824 Failed to open the
- [ ] Add --migration option to create command
- [ ] Would Builder now be able to generate itself based on the current migrations?
- [ ] How would we generate a complete different type of resource, like a Media Manager? The only thing we need is a different table, switching to a grid.

- All Blocks need to be updated
- [ ] All Blocks need to be updated
- [ ] Toggleable option like in Text
- [ ] Filterable option like in Text, and filterable needs to be implemented in ResourceGenerator (only generate filters if filterable is true)
- [ ] The new section API
- [ ] Document the new section API

### Merge and Release

Expand Down
34 changes: 25 additions & 9 deletions packages/builder/src/Blocks/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,30 @@

class Author extends AbstractBlock
{
protected bool $searchable;

protected bool $toggleable;

protected bool $sortable;

protected string $userModel;

public function __construct(
string $name = 'author',
string $label = 'Author',
string $description = 'Author management',
bool $nullable = false,
bool $searchable = true,
bool $toggleable = true,
bool $sortable = true,
string $userModel = 'App\Models\User',
) {
parent::__construct($name, $label, $description);
parent::__construct($name, $label, $description, $nullable);

$this->searchable = $searchable;
$this->toggleable = $toggleable;
$this->sortable = $sortable;
$this->userModel = $userModel;

$this->useStatements = [
'resource' => [
Expand All @@ -31,18 +49,16 @@ public function __construct(

$this->formFields['resource'] = [
"Select::make('author_id')
->relationship('author', 'name')
->searchable()
->preload()
->required()",
->relationship('author', 'name')"
.($this->nullable ? '' : '->required()'),
];

$this->tableColumns['resource'] = [
"TextColumn::make('author.name')
->label(__('core::core.author'))
->sortable()
->searchable()
->toggleable()",
->label(__('core::core.author'))"
.($this->sortable ? '' : '->sortable()')
.($this->searchable ? '' : '->searchable()')
.($this->toggleable ? '' : '->toggleable()'),
];

$this->migrations['fields'] = [
Expand Down
16 changes: 6 additions & 10 deletions packages/builder/src/Blocks/ColorPicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,20 @@ public function __construct(
'resource' => [
'forms' => ['use Filament\Forms\Components\ColorPicker;'],
'columns' => ['use Filament\Tables\Columns\ColorColumn;'],
'filters' => ['use Filament\Tables\Filters\TextFilter;'],
],
];

$this->formFields['resource'] = [
"ColorPicker::make('{$this->name}')
->label('{$this->label}')"
.($this->nullable ? '' : '->required()'),
];
$this->addSection('form')
->withFields([
"ColorPicker::make('{$this->name}')
->label('{$this->label}')"
.($this->nullable ? '' : '->required()'),
]);

$this->tableColumns['resource'] = [
"ColorColumn::make('{$this->name}')",
];

$this->filters['resource'] = [
"TextFilter::make('{$this->name}')",
];

$this->migrations['fields'] = [
"\$table->string('{$this->name}', 7)"
.($this->nullable ? '->nullable()' : ''),
Expand Down
16 changes: 6 additions & 10 deletions packages/builder/src/Blocks/MarkdownEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,22 @@ public function __construct(
'resource' => [
'forms' => ['use Filament\Forms\Components\MarkdownEditor;'],
'columns' => ['use Filament\Tables\Columns\TextColumn;'],
'filters' => ['use Filament\Tables\Filters\TextFilter;'],
],
];

$this->formFields['resource'] = [
"MarkdownEditor::make('{$this->name}')
->label('{$this->label}')"
.($this->nullable ? '' : '->required()'),
];
$this->addSection('form')
->withFields([
"MarkdownEditor::make('{$this->name}')
->label('{$this->label}')"
.($this->nullable ? '' : '->required()'),
]);

$this->tableColumns['resource'] = [
"TextColumn::make('{$this->name}')
->markdown()"
.($this->searchable ? '->searchable()' : ''),
];

$this->filters['resource'] = [
"TextFilter::make('{$this->name}')",
];

$this->migrations['fields'] = [
"\$table->text('{$this->name}')"
.($this->nullable ? '->nullable()' : ''),
Expand Down
64 changes: 21 additions & 43 deletions packages/builder/src/Blocks/Publish.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ public function __construct(
],
'pages' => [
'list' => [
'use Moox\Core\Traits\SinglePublishInListPage;',
// This is missing in the generated list page, why?
'use Illuminate\Database\Eloquent\Builder;',
// while this is generated
'use Moox\Core\Traits\SinglePublishInListPage;',
],
],
];
Expand Down Expand Up @@ -71,20 +72,11 @@ public function __construct(
}',
];

$this->formFields['resource'] = [
];

$this->formSections['resource'] = [
];

$this->metaFields['resource'] = [
'static::getFormActions()',
'static::getPublishAtFormField()',
];

$this->metaSections['resource'] = [
];

$this->tableColumns['resource'] = [
"TextColumn::make('publish_at')
->label(__('core::core.publish_at'))
Expand Down Expand Up @@ -148,7 +140,7 @@ public function __construct(
];

$this->config['tabs'] = [
"'all' => [
'all' => [
'label' => 'trans//core::core.all',
'icon' => 'gmdi-filter-list',
'query' => [
Expand All @@ -158,60 +150,41 @@ public function __construct(
'value' => null,
],
],
],",
"'published' => [
],
'published' => [
'label' => 'trans//core::core.published',
'icon' => 'gmdi-check-circle',
'query' => [
[
'field' => 'publish_at',
'operator' => '<=',
'value' => function () {
return now();
},
],
[
'field' => 'deleted_at',
'operator' => '=',
'value' => null,
'value' => 'now()',
],
],
],",
"'scheduled' => [
],
'scheduled' => [
'label' => 'trans//core::core.scheduled',
'icon' => 'gmdi-schedule',
'query' => [
[
'field' => 'publish_at',
'operator' => '>',
'value' => function () {
return now();
},
],
[
'field' => 'deleted_at',
'operator' => '=',
'value' => null,
'value' => 'now()',
],
],
],",
"'draft' => [
],
'draft' => [
'label' => 'trans//core::core.draft',
'icon' => 'gmdi-text-snippet',
'icon' => 'gmdi-drafts',
'query' => [
[
'field' => 'publish_at',
'operator' => '=',
'value' => null,
],
[
'field' => 'deleted_at',
'field' => 'published_at',
'operator' => '=',
'value' => null,
],
],
],",
"'deleted' => [
],
'deleted' => [
'label' => 'trans//core::core.deleted',
'icon' => 'gmdi-delete',
'query' => [
Expand All @@ -221,7 +194,12 @@ public function __construct(
'value' => null,
],
],
],",
],
];
}

public function getTabs(): array
{
return $this->config['tabs'];
}
}
16 changes: 6 additions & 10 deletions packages/builder/src/Blocks/RichEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ public function __construct(
'resource' => [
'forms' => ['use Filament\Forms\Components\RichEditor;'],
'columns' => ['use Filament\Tables\Columns\TextColumn;'],
'filters' => ['use Filament\Tables\Filters\TextFilter;'],
],
];

$this->formFields['resource'] = [
"RichEditor::make('{$this->name}')
->label('{$this->label}')"
.($this->nullable ? '' : '->required()'),
];
$this->addSection('form')
->withFields([
"RichEditor::make('{$this->name}')
->label('{$this->label}')"
.($this->nullable ? '' : '->required()'),
]);

$this->tableColumns['resource'] = [
"TextColumn::make('{$this->name}')
Expand All @@ -36,10 +36,6 @@ public function __construct(
.($this->searchable ? '->searchable()' : ''),
];

$this->filters['resource'] = [
"TextFilter::make('{$this->name}')",
];

$this->migrations['fields'] = [
"\$table->text('{$this->name}')"
.($this->nullable ? '->nullable()' : ''),
Expand Down
Loading

0 comments on commit b7e9e1b

Please sign in to comment.