Skip to content

Commit d541b85

Browse files
committed
Draft
1 parent 225f77c commit d541b85

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1450
-2
lines changed

app/Providers/Filament/AdminPanelProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Moox\Data\Filament\Plugins\StaticLanguagePlugin;
2626
use Moox\Data\Filament\Plugins\StaticLocalePlugin;
2727
use Moox\Data\Filament\Plugins\StaticTimezonePlugin;
28+
use Moox\Draft\Moox\Plugins\DraftPlugin;
2829
use Moox\Expiry\ExpiryPlugin;
2930
use Moox\Item\Moox\Plugins\ItemPlugin;
3031
use Moox\Jobs\JobsBatchesPlugin;
@@ -94,6 +95,7 @@ public function panel(Panel $panel): Panel
9495
->spa()
9596
->plugins([
9697

98+
DraftPlugin::make(),
9799
ItemPlugin::make(),
98100
AuditPlugin::make(),
99101

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"moox/audit": "*",
2727
"moox/build": "*",
2828
"moox/category": "*",
29+
"moox/draft": "*",
2930
"moox/expiry": "*",
3031
"moox/flags": "*",
3132
"moox/frontend": "*",
@@ -151,4 +152,4 @@
151152
},
152153
"minimum-stability": "dev",
153154
"prefer-stable": false
154-
}
155+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('drafts', function (Blueprint $table) {
15+
$table->id();
16+
$table->boolean('is_active')->default(true);
17+
$table->json('data')->nullable();
18+
$table->string('image')->nullable();
19+
$table->foreignId('author_id')->nullable()->constrained('users')->nullOnDelete();
20+
$table->string('type')->nullable();
21+
$table->dateTime('due_at')->nullable();
22+
$table->string('color')->nullable();
23+
$table->uuid('uuid')->unique();
24+
$table->ulid('ulid')->unique();
25+
$table->string('status')->nullable();
26+
$table->timestamps();
27+
});
28+
}
29+
30+
/**
31+
* Reverse the migrations.
32+
*/
33+
public function down(): void
34+
{
35+
Schema::dropIfExists('drafts');
36+
}
37+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('draft_translations', function (Blueprint $table) {
15+
$table->increments('id');
16+
$table->unsignedBigInteger('draft_id');
17+
$table->string('locale')->index();
18+
$table->string('title');
19+
$table->string('slug')->unique();
20+
$table->text('description')->nullable();
21+
$table->text('content')->nullable();
22+
23+
$table->unique(['draft_id', 'locale']);
24+
$table->foreign('draft_id')->references('id')->on('drafts')->onDelete('cascade');
25+
});
26+
}
27+
28+
/**
29+
* Reverse the migrations.
30+
*/
31+
public function down(): void
32+
33+
{
34+
Schema::dropIfExists('draft_translations');
35+
}
36+
};

docs/_devlog/Alf.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
- [ ] static-locales:280 - GET https://moox.test/storage/%7B%221%22:%7B%22file_name%22:%22Alf-Hamburg-Profil-High.jpg%22,%22title%22:%22Alf-Hamburg-Profil-High%22,%22description%22:null,%22internal_note%22:null,%22alt%22:%22Alf-Hamburg-Profil-High%22%7D%7D 404 (Not Found)
66
- [ ] remove debug code
7-
- [ ] remove boilerplate code taxonomy, finish core implementation
7+
- [ ] remove boilerplate code taxonomy
8+
- [ ] finish core implementation docs
89
- [ ] Implement Item Entity
910
- [x] Item Model
1011
- [x] Item migration

packages/core/src/CoreServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Support\Facades\Gate;
88
use Moox\Core\Console\Commands\MooxInstaller;
99
use Moox\Core\Console\Commands\PackageServiceCommand;
10+
use Moox\Core\Services\TabStateManager;
1011
use Moox\Core\Services\TaxonomyService;
1112
use Moox\Core\Traits\GoogleIcons;
1213
use Moox\Core\Traits\TranslatableConfig;
@@ -25,6 +26,7 @@ public function boot(): void
2526
{
2627
parent::boot();
2728

29+
$this->app->singleton(TabStateManager::class);
2830
$this->app->singleton(TaxonomyService::class);
2931

3032
if (config('core.use_google_icons', true)) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Moox\Core\Entities\Items\Draft;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
abstract class BaseDraftModel extends Model
8+
{
9+
public static function getResourceName(): string
10+
{
11+
$className = class_basename(static::class);
12+
13+
return strtolower($className);
14+
}
15+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
3+
namespace Moox\Core\Entities\Items\Draft;
4+
5+
use Filament\Forms\Components\Actions;
6+
use Illuminate\Contracts\Database\Eloquent\Builder;
7+
use Moox\Core\Entities\BaseResource;
8+
use Moox\Core\Traits\Tabs\HasResourceTabs;
9+
10+
class BaseDraftResource extends BaseResource
11+
{
12+
use HasResourceTabs;
13+
14+
public static function enableCreate(): bool
15+
{
16+
return true;
17+
}
18+
19+
public static function enableEdit(): bool
20+
{
21+
return true;
22+
}
23+
24+
public static function enableView(): bool
25+
{
26+
return true;
27+
}
28+
29+
public static function enableDelete(): bool
30+
{
31+
return true;
32+
}
33+
34+
/**
35+
* @return mixed[]
36+
*/
37+
public static function getTableActions(): array
38+
{
39+
$actions = [];
40+
41+
if (static::enableEdit()) {
42+
$actions[] = static::getEditTableAction();
43+
}
44+
45+
if (static::enableView()) {
46+
$actions[] = static::getViewTableAction();
47+
}
48+
49+
return $actions;
50+
}
51+
52+
/**
53+
* @return mixed[]
54+
*/
55+
public static function getBulkActions(): array
56+
{
57+
$actions = [];
58+
59+
if (static::enableDelete()) {
60+
$actions[] = static::getDeleteBulkAction();
61+
}
62+
63+
return $actions;
64+
}
65+
66+
public static function getFormActions(): Actions
67+
{
68+
$actions = [
69+
static::getSaveAction()->extraAttributes(attributes: ['class' => 'w-full']),
70+
static::getCancelAction()->extraAttributes(attributes: ['class' => 'w-full']),
71+
];
72+
73+
if (static::enableCreate()) {
74+
$actions[] = static::getSaveAndCreateAnotherAction()->extraAttributes(attributes: ['class' => 'w-full']);
75+
}
76+
77+
if (static::enableDelete()) {
78+
$actions[] = static::getDeleteAction()->extraAttributes(attributes: ['class' => 'w-full']);
79+
}
80+
81+
if (static::enableEdit()) {
82+
$actions[] = static::getEditAction()->extraAttributes(attributes: ['class' => 'w-full']);
83+
}
84+
85+
return Actions::make($actions);
86+
}
87+
88+
public static function getFooterActions(): Actions
89+
{
90+
return Actions::make([
91+
static::getSaveAction(),
92+
static::getCancelAction(),
93+
]);
94+
}
95+
96+
public static function query(): Builder
97+
{
98+
return parent::getEloquentQuery();
99+
}
100+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Moox\Core\Entities\Items\Draft\Pages;
4+
5+
use Filament\Resources\Pages\CreateRecord;
6+
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Database\Eloquent\SoftDeletes;
8+
use Illuminate\Database\Eloquent\SoftDeletingScope;
9+
use Moox\Core\Traits\ResolveResourceClass;
10+
11+
abstract class BaseCreateDraft extends CreateRecord
12+
{
13+
use ResolveResourceClass;
14+
15+
protected function resolveRecord($key): Model
16+
{
17+
$model = static::getModel();
18+
19+
$query = $model::query();
20+
21+
if (in_array(SoftDeletes::class, class_uses_recursive($model))) {
22+
$query->withoutGlobalScope(SoftDeletingScope::class);
23+
}
24+
25+
return $query->find($key) ?? $model::make();
26+
}
27+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Moox\Core\Entities\Items\Draft\Pages;
4+
5+
use Filament\Resources\Pages\EditRecord;
6+
use Moox\Core\Traits\ResolveResourceClass;
7+
8+
abstract class BaseEditDraft extends EditRecord
9+
{
10+
use ResolveResourceClass;
11+
12+
protected function getFormActions(): array
13+
{
14+
return [];
15+
}
16+
}

0 commit comments

Comments
 (0)