From 218c90ff7663c05452afdf99968d149b6321e21c Mon Sep 17 00:00:00 2001 From: Alf Drollinger Date: Wed, 6 Mar 2024 16:14:25 +0100 Subject: [PATCH] Sync Resources w-i-p --- app/Providers/Filament/AdminPanelProvider.php | 3 ++ config/sync.php | 5 ++ ...03_06_142650_01_create_platforms_table.php | 40 ++++++++++++++++ ...024_03_06_142651_02_create_syncs_table.php | 32 +++++++++++++ .../sync/resources/lang/en/translations.php | 4 +- packages/sync/src/Commands/InstallCommand.php | 4 +- packages/sync/src/Models/Sync.php | 4 +- packages/sync/src/PlatformPlugin.php | 2 +- .../sync/src/Resources/PlatformResource.php | 47 +++++++++++++++++-- .../PlatformResource/Pages/ListPlatforms.php | 33 +++++++++++++ packages/sync/src/Resources/SyncResource.php | 12 ++--- .../Pages/{ListPage.php => ListSyncs.php} | 2 +- packages/sync/src/SyncServiceProvider.php | 2 +- 13 files changed, 171 insertions(+), 19 deletions(-) create mode 100644 config/sync.php create mode 100644 database/migrations/2024_03_06_142650_01_create_platforms_table.php create mode 100644 database/migrations/2024_03_06_142651_02_create_syncs_table.php create mode 100644 packages/sync/src/Resources/PlatformResource/Pages/ListPlatforms.php rename packages/sync/src/Resources/SyncResource/Pages/{ListPage.php => ListSyncs.php} (95%) diff --git a/app/Providers/Filament/AdminPanelProvider.php b/app/Providers/Filament/AdminPanelProvider.php index 02b149e72..94fdf5830 100644 --- a/app/Providers/Filament/AdminPanelProvider.php +++ b/app/Providers/Filament/AdminPanelProvider.php @@ -89,6 +89,9 @@ public function panel(Panel $panel): Panel \Leandrocfe\FilamentApexCharts\FilamentApexChartsPlugin::make(), + + \Moox\Sync\PlatformPlugin::make(), + ]); } } diff --git a/config/sync.php b/config/sync.php new file mode 100644 index 000000000..a0d987680 --- /dev/null +++ b/config/sync.php @@ -0,0 +1,5 @@ +bigIncrements('id'); + $table->string('title'); + $table->string('slug'); + $table->string('domain'); + $table->boolean('selection')->nullable(); + $table->tinyInteger('order')->nullable(); + $table->boolean('locked')->nullable(); + $table->boolean('master')->nullable(); + $table->string('thumbnail')->nullable(); + $table->unsignedBigInteger('platformable_id'); + $table->string('platformable_type'); + + $table->index('platformable_id'); + $table->index('platformable_type'); + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('platforms'); + } +}; diff --git a/database/migrations/2024_03_06_142651_02_create_syncs_table.php b/database/migrations/2024_03_06_142651_02_create_syncs_table.php new file mode 100644 index 000000000..bfdab6077 --- /dev/null +++ b/database/migrations/2024_03_06_142651_02_create_syncs_table.php @@ -0,0 +1,32 @@ +id(); + $table->string('name')->nullable(); + $table->timestamp('started_at')->nullable()->index(); + $table->timestamp('finished_at')->nullable(); + $table->boolean('failed')->default(false)->index(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + + { + Schema::dropIfExists('sync'); + } +}; diff --git a/packages/sync/resources/lang/en/translations.php b/packages/sync/resources/lang/en/translations.php index d3e8c2356..21ce9cb2f 100644 --- a/packages/sync/resources/lang/en/translations.php +++ b/packages/sync/resources/lang/en/translations.php @@ -3,10 +3,12 @@ return [ 'single' => 'Sync', 'plural' => 'Syncs', + 'platform' => 'Platform', + 'platforms' => 'Platforms', 'breadcrumb' => 'Sync', 'title' => 'Sync', 'navigation_label' => 'Sync', - 'navigation_group' => 'Sync Group', + 'navigation_group' => 'Sync', 'totalone' => 'Sync One', 'totaltwo' => 'Sync Two', 'totalthree' => 'Sync Three', diff --git a/packages/sync/src/Commands/InstallCommand.php b/packages/sync/src/Commands/InstallCommand.php index 27c20dd56..6beb34723 100644 --- a/packages/sync/src/Commands/InstallCommand.php +++ b/packages/sync/src/Commands/InstallCommand.php @@ -111,8 +111,8 @@ public function register_plugins(): void $pluginsToAdd = multiselect( label: 'These plugins will be installed:', - options: ['SyncPlugin'], - default: ['SyncPlugin'], + options: ['SyncPlugin', 'PlatformPlugin'], + default: ['SyncPlugin', 'PlatformPlugin'], ); $function = '::make(),'; diff --git a/packages/sync/src/Models/Sync.php b/packages/sync/src/Models/Sync.php index dbb7354b5..1754073b0 100644 --- a/packages/sync/src/Models/Sync.php +++ b/packages/sync/src/Models/Sync.php @@ -22,12 +22,12 @@ class Sync extends Model public function sourcePlatform() { - //return $this->belongsTo(Platform::class, 'source_platform_id'); + return $this->belongsTo(Platform::class, 'source_platform_id'); } public function targetPlatform() { - //return $this->belongsTo(Platform::class, 'target_platform_id'); + return $this->belongsTo(Platform::class, 'target_platform_id'); } public function syncable() diff --git a/packages/sync/src/PlatformPlugin.php b/packages/sync/src/PlatformPlugin.php index e3b738d2e..2eb1e1275 100644 --- a/packages/sync/src/PlatformPlugin.php +++ b/packages/sync/src/PlatformPlugin.php @@ -7,7 +7,7 @@ use Filament\Support\Concerns\EvaluatesClosures; use Moox\Sync\Resources\PlatformResource; -class SyncPlugin implements Plugin +class PlatformPlugin implements Plugin { use EvaluatesClosures; diff --git a/packages/sync/src/Resources/PlatformResource.php b/packages/sync/src/Resources/PlatformResource.php index 82eff3838..61c9c28e9 100644 --- a/packages/sync/src/Resources/PlatformResource.php +++ b/packages/sync/src/Resources/PlatformResource.php @@ -2,7 +2,6 @@ namespace Moox\Sync\Resources; -use App\Filament\Resources\PlatformResource\Pages; use Filament\Forms\Components\FileUpload; use Filament\Forms\Components\Grid; use Filament\Forms\Components\Section; @@ -14,15 +13,17 @@ use Filament\Tables\Actions\EditAction; use Filament\Tables\Actions\ViewAction; use Filament\Tables\Columns\IconColumn; +use Filament\Tables\Columns\ImageColumn; use Filament\Tables\Columns\TextColumn; use Filament\Tables\Table; use Moox\Sync\Models\Platform; +use Moox\Sync\Resources\PlatformResource\Pages\ListPlatforms; class PlatformResource extends Resource { protected static ?string $model = Platform::class; - protected static ?string $navigationIcon = 'heroicon-o-collection'; + protected static ?string $navigationIcon = 'heroicon-o-server-stack'; protected static ?string $recordTitleAttribute = 'title'; @@ -190,10 +191,50 @@ public static function getRelations(): array public static function getPages(): array { return [ - // 'index' => Pages\ListPlatforms::route('/'), + 'index' => ListPlatforms::route('/'), // 'create' => Pages\CreatePlatform::route('/create'), // 'view' => Pages\ViewPlatform::route('/{record}'), // 'edit' => Pages\EditPlatform::route('/{record}/edit'), ]; } + + public static function getModelLabel(): string + { + return __('sync::translations.platform'); + } + + public static function getPluralModelLabel(): string + { + return __('sync::translations.platforms'); + } + + public static function getNavigationLabel(): string + { + return __('sync::translations.platforms'); + } + + public static function getBreadcrumb(): string + { + return __('sync::translations.breadcrumb'); + } + + public static function shouldRegisterNavigation(): bool + { + return true; + } + + public static function getNavigationBadge(): ?string + { + return number_format(static::getModel()::count()); + } + + public static function getNavigationGroup(): ?string + { + return __('sync::translations.navigation_group'); + } + + public static function getNavigationSort(): ?int + { + return 1801; + } } diff --git a/packages/sync/src/Resources/PlatformResource/Pages/ListPlatforms.php b/packages/sync/src/Resources/PlatformResource/Pages/ListPlatforms.php new file mode 100644 index 000000000..4538424e2 --- /dev/null +++ b/packages/sync/src/Resources/PlatformResource/Pages/ListPlatforms.php @@ -0,0 +1,33 @@ +using(function (array $data, string $model): Platform { + return $model::create($data); + }), + ]; + } +} diff --git a/packages/sync/src/Resources/SyncResource.php b/packages/sync/src/Resources/SyncResource.php index e91a651a0..c22f8a1ff 100644 --- a/packages/sync/src/Resources/SyncResource.php +++ b/packages/sync/src/Resources/SyncResource.php @@ -16,12 +16,13 @@ use Filament\Tables\Filters\SelectFilter; use Filament\Tables\Table; use Moox\Sync\Models\Sync; +use Moox\Sync\Resources\SyncResource\Pages\ListSyncs; class SyncResource extends Resource { protected static ?string $model = Sync::class; - protected static ?string $navigationIcon = 'heroicon-o-play'; + protected static ?string $navigationIcon = 'heroicon-o-arrows-right-left'; protected static ?string $recordTitleAttribute = 'syncable_type'; @@ -128,15 +129,10 @@ public static function table(Table $table): Table ->bulkActions([DeleteBulkAction::make()]); } - public static function getRelations(): array - { - return []; - } - public static function getPages(): array { return [ - //'index' => Pages\ListSyncs::route('/'), + 'index' => ListSyncs::route('/'), //'create' => Pages\CreateSync::route('/create'), //'view' => Pages\ViewSync::route('/{record}'), //'edit' => Pages\EditSync::route('/{record}/edit'), @@ -180,6 +176,6 @@ public static function getNavigationGroup(): ?string public static function getNavigationSort(): ?int { - return 2001; + return 1801; } } diff --git a/packages/sync/src/Resources/SyncResource/Pages/ListPage.php b/packages/sync/src/Resources/SyncResource/Pages/ListSyncs.php similarity index 95% rename from packages/sync/src/Resources/SyncResource/Pages/ListPage.php rename to packages/sync/src/Resources/SyncResource/Pages/ListSyncs.php index 178f03125..207fdc4cf 100644 --- a/packages/sync/src/Resources/SyncResource/Pages/ListPage.php +++ b/packages/sync/src/Resources/SyncResource/Pages/ListSyncs.php @@ -7,7 +7,7 @@ use Moox\Sync\Models\Sync; use Moox\Sync\Resources\SyncResource; -class ListPage extends ListRecords +class ListSyncs extends ListRecords { public static string $resource = SyncResource::class; diff --git a/packages/sync/src/SyncServiceProvider.php b/packages/sync/src/SyncServiceProvider.php index f13611629..7bc554bf0 100644 --- a/packages/sync/src/SyncServiceProvider.php +++ b/packages/sync/src/SyncServiceProvider.php @@ -17,7 +17,7 @@ public function configurePackage(Package $package): void ->hasConfigFile() ->hasViews() ->hasTranslations() - ->hasMigrations(['01_create_syncs_table', '02_create_platforms_table']) + ->hasMigrations(['01_create_platforms_table', '02_create_syncs_table']) ->hasCommand(InstallCommand::class); } }