Skip to content

Commit

Permalink
Trait refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
adrolli committed Dec 6, 2024
1 parent f8e190e commit 8bd5b1b
Show file tree
Hide file tree
Showing 150 changed files with 7,416 additions and 322 deletions.
2 changes: 1 addition & 1 deletion config/builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@
|
*/

'author_model' => \Moox\User\Models\User::class,
'user_model' => \Moox\User\Models\User::class,

/*
|--------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion config/tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
|
*/

'author_model' => \App\Models\User::class,
'user_model' => \App\Models\User::class,

/*
|--------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion packages/audit/src/Resources/AuditResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Filament\Tables\Table;
use Moox\Audit\Resources\AuditResource\Pages\ListAudits;
use Moox\Audit\Resources\AuditResource\Pages\ViewAudit;
use Moox\Core\Traits\TabsInResource;
use Moox\Core\Traits\Tabs\TabsInResource;
use Spatie\Activitylog\Models\Activity;

class AuditResource extends Resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Filament\Resources\Pages\ListRecords;
use Moox\Audit\Resources\AuditResource;
use Moox\Core\Traits\TabsInListPage;
use Moox\Core\Traits\Tabs\TabsInListPage;
use Spatie\Activitylog\Models\Activity;

class ListAudits extends ListRecords
Expand Down
6 changes: 3 additions & 3 deletions packages/builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,19 +301,19 @@ You can configure the user model used for displaying Authors. By default it is t
|
*/

'author_model' => \App\Models\User::class,
'user_model' => \App\Models\User::class,
```

You may probably use Moox User

```php
'author_model' => \Moox\User\Models\User::class,
'user_model' => \Moox\User\Models\User::class,
```

or Moox Press User instead:

```php
'author_model' => \Moox\Press\Models\WpUser::class,
'user_model' => \Moox\Press\Models\WpUser::class,
```

## Do not track Previews
Expand Down
8 changes: 4 additions & 4 deletions packages/builder/src/Blocks/Publish.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public function __construct(
// This is missing in the generated list page, why?
'use Illuminate\Database\Eloquent\Builder;',
// while this is generated
'use Moox\Core\Traits\SinglePublishInListPage;',
'use Moox\Core\Traits\Publish\SinglePublishInListPage;',
],
],
];

$this->traits['model'] = ['Moox\Core\Traits\SinglePublishInModel'];
$this->traits['resource'] = ['Moox\Core\Traits\SinglePublishInResource'];
$this->traits['pages']['list'] = ['Moox\Core\Traits\SinglePublishInListPage'];
$this->traits['model'] = ['Moox\Core\Traits\Publish\SinglePublishInModel'];
$this->traits['resource'] = ['Moox\Core\Traits\Publish\SinglePublishInResource'];
$this->traits['pages']['list'] = ['Moox\Core\Traits\Publish\SinglePublishInListPage'];

$this->methods['model'] = [
'scopes' => [
Expand Down
10 changes: 5 additions & 5 deletions packages/builder/src/Blocks/Simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public function __construct(
],
];

$this->traits['resource'] = ['Moox\Core\Traits\SingleSimpleInResource'];
$this->traits['pages']['list'] = ['Moox\Core\Traits\SingleSimpleInListPage'];
$this->traits['pages']['view'] = ['Moox\Core\Traits\SingleSimpleInViewPage'];
$this->traits['pages']['create'] = ['Moox\Core\Traits\SingleSimpleInCreatePage'];
$this->traits['pages']['edit'] = ['Moox\Core\Traits\SingleSimpleInEditPage'];
$this->traits['resource'] = ['Moox\Core\Traits\Simple\SingleSimpleInResource'];
$this->traits['pages']['list'] = ['Moox\Core\Traits\Simple\SingleSimpleInListPage'];
$this->traits['pages']['view'] = ['Moox\Core\Traits\Simple\SingleSimpleInViewPage'];
$this->traits['pages']['create'] = ['Moox\Core\Traits\Simple\SingleSimpleInCreatePage'];
$this->traits['pages']['edit'] = ['Moox\Core\Traits\Simple\SingleSimpleInEditPage'];

$this->addSection('meta')
->asMeta()
Expand Down
9 changes: 9 additions & 0 deletions packages/builder/src/Blocks/SoftDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ public function __construct(
->visible(fn (\$livewire, \$record) => \$record && ! \$record->trashed())",
];

$this->actions['pages']['list']['header'] = [
"Action::make('create')
->label(__('core::core.create'))
->color('success')
->button()
->extraAttributes(['class' => 'w-full'])
->action(fn (\$livewire) => \$livewire->create())",
];

$this->actions['bulk'] = [
"DeleteBulkAction::make()
->hidden(fn () => request()->routeIs('*.trash'))",
Expand Down
4 changes: 2 additions & 2 deletions packages/builder/src/Blocks/Tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public function __construct(
) {
parent::__construct($name, $label, $description);

$this->traits['resource'] = ['Moox\Core\Traits\TabsInResource'];
$this->traits['pages']['list'] = ['Moox\Core\Traits\TabsInListPage'];
$this->traits['resource'] = ['Moox\Core\Traits\Tabs\TabsInResource'];
$this->traits['pages']['list'] = ['Moox\Core\Traits\Tabs\TabsInListPage'];

$this->methods['pages']['list']['mount'] = '$this->mountTabsInListPage();';

Expand Down
10 changes: 5 additions & 5 deletions packages/builder/src/Blocks/Taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ public function __construct(
'hierarchical' => $nested,
];

$this->traits['model'] = ['Moox\Core\Traits\TaxonomyInModel'];
$this->traits['resource'] = ['Moox\Core\Traits\TaxonomyInResource'];
$this->traits['pages']['create'] = ['Moox\Core\Traits\TaxonomyInPages'];
$this->traits['pages']['view'] = ['Moox\Core\Traits\TaxonomyInPages'];
$this->traits['pages']['edit'] = ['Moox\Core\Traits\TaxonomyInPages'];
$this->traits['model'] = ['Moox\Core\Traits\Taxonomy\TaxonomyInModel'];
$this->traits['resource'] = ['Moox\Core\Traits\Taxonomy\TaxonomyInResource'];
$this->traits['pages']['create'] = ['Moox\Core\Traits\Taxonomy\TaxonomyInPages'];
$this->traits['pages']['view'] = ['Moox\Core\Traits\Taxonomy\TaxonomyInPages'];
$this->traits['pages']['edit'] = ['Moox\Core\Traits\Taxonomy\TaxonomyInPages'];

$this->methods['model'] = [
'protected function getResourceName(): string
Expand Down
8 changes: 4 additions & 4 deletions packages/builder/src/Models/FullItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Moox\Core\Traits\AuthorInModel;
use Moox\Core\Traits\SinglePublishInModel;
use Moox\Core\Traits\TaxonomyInModel;
use Moox\Core\Traits\Publish\SinglePublishInModel;
use Moox\Core\Traits\Taxonomy\TaxonomyInModel;
use Moox\Core\Traits\UserRelation\UserInModel;

class FullItem extends Model
{
use AuthorInModel, HasFactory, SinglePublishInModel, SoftDeletes, TaxonomyInModel;
use HasFactory, SinglePublishInModel, SoftDeletes, TaxonomyInModel, UserInModel;

protected $table = 'full_items';

Expand Down
8 changes: 4 additions & 4 deletions packages/builder/src/Models/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Moox\Core\Traits\AuthorInModel;
use Moox\Core\Traits\SinglePublishInModel;
use Moox\Core\Traits\TaxonomyInModel;
use Moox\Core\Traits\Publish\SinglePublishInModel;
use Moox\Core\Traits\Taxonomy\TaxonomyInModel;
use Moox\Core\Traits\UserRelation\UserInModel;

class Item extends Model
{
use AuthorInModel, HasFactory, SinglePublishInModel, SoftDeletes, TaxonomyInModel;
use HasFactory, SinglePublishInModel, SoftDeletes, TaxonomyInModel, UserInModel;

protected $table = 'items';

Expand Down
2 changes: 1 addition & 1 deletion packages/builder/src/Models/SimpleItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Moox\Core\Traits\TaxonomyInModel;
use Moox\Core\Traits\Taxonomy\TaxonomyInModel;

class SimpleItem extends Model
{
Expand Down
4 changes: 2 additions & 2 deletions packages/builder/src/Presets/SoftDeleteItemPreset.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Moox\Builder\Presets;

use Moox\Builder\Blocks\AddressSection;
use Moox\Builder\Blocks\Simple;
use Moox\Builder\Blocks\SimpleStatus;
use Moox\Builder\Blocks\SimpleType;
use Moox\Builder\Blocks\SoftDelete;
use Moox\Builder\Blocks\Tabs;
use Moox\Builder\Blocks\Taxonomy;
use Moox\Builder\Blocks\TextArea;
Expand All @@ -18,7 +18,6 @@ class SoftDeleteItemPreset extends AbstractPreset
protected function initializePreset(): void
{
$this->blocks = [
new Simple,
new TitleWithSlug(
titleFieldName: 'title',
slugFieldName: 'slug',
Expand Down Expand Up @@ -57,6 +56,7 @@ enum: ['Probably', 'Never', 'Done', 'Maybe'],
new SimpleType(
enum: ['Post', 'Page'],
),
new SoftDelete,
];
}
}
24 changes: 12 additions & 12 deletions packages/builder/src/Resources/FullItemResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,16 @@
/* ! Author ! */
use Moox\Builder\Resources\FullItemResource\Widgets\FullItemWidgets;
/* ! Publish ! */
use Moox\Core\Traits\AuthorInResource;
/* ! Tabs ! */
use Moox\Core\Traits\SinglePublishInResource;
use Moox\Core\Traits\Publish\SinglePublishInResource;
/* ! Taxonomy ! */
use Moox\Core\Traits\TabsInResource;
use Moox\Core\Traits\TaxonomyInResource;
use Moox\Core\Traits\Tabs\TabsInResource;
use Moox\Core\Traits\Taxonomy\TaxonomyInResource;
use Moox\Core\Traits\UserRelation\UserInResource;

/* ! FullItem => Entity */
class FullItemResource extends Resource
{
/* ! Author ! */
use AuthorInResource;

/* ! Publish ! */
use SinglePublishInResource;

Expand All @@ -72,14 +69,17 @@ class FullItemResource extends Resource
/* ! Taxonomy ! */
use TaxonomyInResource;

/* ! Author ! */
use UserInResource;

protected static ?string $model = FullItem::class;

protected static ?string $navigationIcon = 'gmdi-engineering';

public static function form(Form $form): Form
{
/* ! Author ! */
static::initAuthorModel();
static::initUserModel();

return $form->schema([
Grid::make(2)
Expand Down Expand Up @@ -198,7 +198,7 @@ public static function form(Form $form): Form
DateTimePicker::make('publish_at')
->label(__('core::core.publish_at')),
/* ! Author ! */
static::getAuthorFormField(),
static::getUserFormField(),
/* !! Meta Form Fields */
]),

Expand All @@ -216,7 +216,7 @@ public static function form(Form $form): Form
public static function table(Table $table): Table
{
/* ! Author ! */
static::initAuthorModel();
static::initUserModel();

/* ! Tabs ! */
$currentTab = static::getCurrentTab();
Expand Down Expand Up @@ -250,7 +250,7 @@ public static function table(Table $table): Table
->searchable()
->toggleable(),
/* ! Author ! */
static::getAuthorTableColumn(),
static::getUserTableColumn(),
TextColumn::make('type')
->label(__('core::core.type'))
->visible(! empty(config('builder.types')))
Expand Down Expand Up @@ -325,7 +325,7 @@ public static function table(Table $table): Table
/* ! Taxonomy ! */
...static::getTaxonomyFilters(),
/* ! Author ! */
...static::getAuthorFilters(),
...static::getUserFilters(),
/* !! Table Filters */
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Filament\Resources\Pages\CreateRecord;
use Moox\Builder\Resources\FullItemResource;
use Moox\Core\Traits\TaxonomyInPages;
use Moox\Core\Traits\Taxonomy\TaxonomyInPages;

class CreateFullItem extends CreateRecord
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Filament\Resources\Pages\EditRecord;
use Moox\Builder\Resources\FullItemResource;
use Moox\Core\Traits\TaxonomyInPages;
use Moox\Core\Traits\Taxonomy\TaxonomyInPages;

class EditFullItem extends EditRecord
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Moox\Builder\Models\FullItem;
use Moox\Builder\Resources\FullItemResource;
use Moox\Builder\Resources\FullItemResource\Widgets\FullItemWidgets;
use Moox\Core\Traits\TabsInListPage;
use Moox\Core\Traits\Tabs\TabsInListPage;

class ListFullItems extends ListRecords
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Filament\Resources\Pages\ViewRecord;
use Illuminate\Database\Eloquent\Model;
use Moox\Builder\Resources\FullItemResource;
use Moox\Core\Traits\TaxonomyInPages;
use Moox\Core\Traits\Taxonomy\TaxonomyInPages;

class ViewFullItem extends ViewRecord
{
Expand Down
20 changes: 10 additions & 10 deletions packages/builder/src/Resources/ItemResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@
use Moox\Builder\Resources\ItemResource\Pages\EditItem;
use Moox\Builder\Resources\ItemResource\Pages\ListItems;
use Moox\Builder\Resources\ItemResource\Pages\ViewItem;
use Moox\Core\Traits\AuthorInResource;
use Moox\Core\Traits\SinglePublishInResource;
use Moox\Core\Traits\TabsInResource;
use Moox\Core\Traits\TaxonomyInResource;
use Moox\Core\Traits\Publish\SinglePublishInResource;
use Moox\Core\Traits\Tabs\TabsInResource;
use Moox\Core\Traits\Taxonomy\TaxonomyInResource;
use Moox\Core\Traits\UserRelation\UserInResource;

class ItemResource extends Resource
{
use AuthorInResource, SinglePublishInResource, TabsInResource, TaxonomyInResource;
use SinglePublishInResource, TabsInResource, TaxonomyInResource, UserInResource;

protected static ?string $model = Item::class;

protected static ?string $navigationIcon = 'gmdi-article';

public static function form(Form $form): Form
{
static::initAuthorModel();
static::initUserModel();

return $form->schema([
Grid::make(2)
Expand Down Expand Up @@ -67,7 +67,7 @@ public static function form(Form $form): Form
->schema([
static::getFormActions(),
static::getPublishAtFormField(),
static::getAuthorFormField(),
static::getUserFormField(),
]),

Section::make()
Expand All @@ -83,7 +83,7 @@ public static function form(Form $form): Form

public static function table(Table $table): Table
{
static::initAuthorModel();
static::initUserModel();

$currentTab = static::getCurrentTab();

Expand Down Expand Up @@ -112,7 +112,7 @@ public static function table(Table $table): Table
->limit(30)
->searchable()
->toggleable(),
static::getAuthorTableColumn(),
static::getUserTableColumn(),
...static::getTaxonomyColumns(),
static::getStatusTableColumn(),

Expand Down Expand Up @@ -145,7 +145,7 @@ public static function table(Table $table): Table
])
->filters([
...static::getTableFilters(),
...static::getAuthorFilters(),
...static::getUserFilters(),
...static::getTaxonomyFilters(),
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Filament\Resources\Pages\CreateRecord;
use Moox\Builder\Resources\ItemResource;
use Moox\Core\Traits\TaxonomyInPages;
use Moox\Core\Traits\Taxonomy\TaxonomyInPages;

class CreateItem extends CreateRecord
{
Expand Down
Loading

0 comments on commit 8bd5b1b

Please sign in to comment.