From b5b182730e1fcea4470867dcdb1ecd1274044493 Mon Sep 17 00:00:00 2001 From: Alf Drollinger Date: Wed, 6 Mar 2024 15:18:46 +0100 Subject: [PATCH] Sync w-i-p --- composer.lock | 14 +- .../01_create_platforms_table.php.stub | 40 ++++ ...hp.stub => 02_create_syncs_table.php.stub} | 0 packages/sync/src/Models/Platform.php | 44 ++++ packages/sync/src/Models/Sync.php | 32 ++- packages/sync/src/PlatformPlugin.php | 35 +++ .../sync/src/Resources/PlatformResource.php | 199 ++++++++++++++++++ packages/sync/src/Resources/SyncResource.php | 144 +++++++++---- .../Resources/SyncResource/Pages/ListPage.php | 8 - .../SyncResource/Widgets/SyncWidgets.php | 30 --- packages/sync/src/SyncServiceProvider.php | 2 +- 11 files changed, 453 insertions(+), 95 deletions(-) create mode 100644 packages/sync/database/migrations/01_create_platforms_table.php.stub rename packages/sync/database/migrations/{create_builders_table.php.stub => 02_create_syncs_table.php.stub} (100%) create mode 100644 packages/sync/src/Models/Platform.php create mode 100644 packages/sync/src/PlatformPlugin.php create mode 100644 packages/sync/src/Resources/PlatformResource.php delete mode 100644 packages/sync/src/Resources/SyncResource/Widgets/SyncWidgets.php diff --git a/composer.lock b/composer.lock index 30279ecdf..660e12093 100644 --- a/composer.lock +++ b/composer.lock @@ -3650,7 +3650,7 @@ }, { "name": "moox/builder", - "version": "dev-main", + "version": "dev-feature/sync", "dist": { "type": "path", "url": "packages/builder", @@ -3696,7 +3696,7 @@ }, { "name": "moox/core", - "version": "dev-main", + "version": "dev-feature/sync", "dist": { "type": "path", "url": "packages/core", @@ -3749,7 +3749,7 @@ }, { "name": "moox/jobs", - "version": "dev-main", + "version": "dev-feature/sync", "dist": { "type": "path", "url": "packages/jobs", @@ -3803,7 +3803,7 @@ }, { "name": "moox/page", - "version": "dev-main", + "version": "dev-feature/sync", "dist": { "type": "path", "url": "packages/page", @@ -3849,7 +3849,7 @@ }, { "name": "moox/press", - "version": "dev-main", + "version": "dev-feature/sync", "dist": { "type": "path", "url": "packages/press", @@ -3895,7 +3895,7 @@ }, { "name": "moox/sync", - "version": "dev-main", + "version": "dev-feature/sync", "dist": { "type": "path", "url": "packages/sync", @@ -3941,7 +3941,7 @@ }, { "name": "moox/user", - "version": "dev-main", + "version": "dev-feature/sync", "dist": { "type": "path", "url": "packages/user", diff --git a/packages/sync/database/migrations/01_create_platforms_table.php.stub b/packages/sync/database/migrations/01_create_platforms_table.php.stub new file mode 100644 index 000000000..8e6cb489d --- /dev/null +++ b/packages/sync/database/migrations/01_create_platforms_table.php.stub @@ -0,0 +1,40 @@ +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/packages/sync/database/migrations/create_builders_table.php.stub b/packages/sync/database/migrations/02_create_syncs_table.php.stub similarity index 100% rename from packages/sync/database/migrations/create_builders_table.php.stub rename to packages/sync/database/migrations/02_create_syncs_table.php.stub diff --git a/packages/sync/src/Models/Platform.php b/packages/sync/src/Models/Platform.php new file mode 100644 index 000000000..cb470643e --- /dev/null +++ b/packages/sync/src/Models/Platform.php @@ -0,0 +1,44 @@ + 'boolean', + 'locked' => 'boolean', + 'master' => 'boolean', + ]; + + public function sources() + { + return $this->hasMany(Sync::class, 'source_platform_id'); + } + + public function targets() + { + return $this->hasMany(Sync::class, 'target_platform_id'); + } + + public function platformable() + { + return $this->morphTo(); + } +} diff --git a/packages/sync/src/Models/Sync.php b/packages/sync/src/Models/Sync.php index be66474d0..dbb7354b5 100644 --- a/packages/sync/src/Models/Sync.php +++ b/packages/sync/src/Models/Sync.php @@ -6,18 +6,32 @@ class Sync extends Model { - protected $table = 'sync'; - protected $fillable = [ - 'name', - 'started_at', - 'finished_at', - 'failed', + 'syncable_id', + 'syncable_type', + 'source_platform_id', + 'target_platform_id', + 'last_sync', ]; + protected $searchableFields = ['*']; + protected $casts = [ - 'failed' => 'bool', - 'started_at' => 'datetime', - 'finished_at' => 'datetime', + 'last_sync' => 'datetime', ]; + + public function sourcePlatform() + { + //return $this->belongsTo(Platform::class, 'source_platform_id'); + } + + public function targetPlatform() + { + //return $this->belongsTo(Platform::class, 'target_platform_id'); + } + + public function syncable() + { + return $this->morphTo(); + } } diff --git a/packages/sync/src/PlatformPlugin.php b/packages/sync/src/PlatformPlugin.php new file mode 100644 index 000000000..e3b738d2e --- /dev/null +++ b/packages/sync/src/PlatformPlugin.php @@ -0,0 +1,35 @@ +resources([ + PlatformResource::class, + ]); + } + + public function boot(Panel $panel): void + { + // + } + + public static function make(): static + { + return app(static::class); + } +} diff --git a/packages/sync/src/Resources/PlatformResource.php b/packages/sync/src/Resources/PlatformResource.php new file mode 100644 index 000000000..82eff3838 --- /dev/null +++ b/packages/sync/src/Resources/PlatformResource.php @@ -0,0 +1,199 @@ +schema([ + Section::make()->schema([ + Grid::make(['default' => 0])->schema([ + TextInput::make('title') + ->rules(['max:255', 'string']) + ->required() + ->placeholder('Title') + ->columnSpan([ + 'default' => 12, + 'md' => 12, + 'lg' => 12, + ]), + + TextInput::make('slug') + ->rules(['max:255', 'string']) + ->required() + ->placeholder('Slug') + ->columnSpan([ + 'default' => 12, + 'md' => 12, + 'lg' => 12, + ]), + + TextInput::make('domain') + ->rules(['max:255', 'string']) + ->required() + ->placeholder('Domain') + ->columnSpan([ + 'default' => 12, + 'md' => 12, + 'lg' => 12, + ]), + + Toggle::make('selection') + ->rules(['boolean']) + ->nullable() + ->columnSpan([ + 'default' => 12, + 'md' => 12, + 'lg' => 12, + ]), + + TextInput::make('order') + ->rules(['max:255']) + ->nullable() + ->placeholder('Order') + ->columnSpan([ + 'default' => 12, + 'md' => 12, + 'lg' => 12, + ]), + + Toggle::make('locked') + ->rules(['boolean']) + ->nullable() + ->columnSpan([ + 'default' => 12, + 'md' => 12, + 'lg' => 12, + ]), + + Toggle::make('master') + ->rules(['boolean']) + ->nullable() + ->columnSpan([ + 'default' => 12, + 'md' => 12, + 'lg' => 12, + ]), + + FileUpload::make('thumbnail') + ->rules(['file']) + ->nullable() + ->image() + ->placeholder('Thumbnail') + ->columnSpan([ + 'default' => 12, + 'md' => 12, + 'lg' => 12, + ]), + + TextInput::make('platformable_id') + ->rules(['max:255']) + ->required() + ->placeholder('Platformable Id') + ->columnSpan([ + 'default' => 12, + 'md' => 12, + 'lg' => 12, + ]), + + TextInput::make('platformable_type') + ->rules(['max:255', 'string']) + ->required() + ->placeholder('Platformable Type') + ->columnSpan([ + 'default' => 12, + 'md' => 12, + 'lg' => 12, + ]), + ]), + ]), + ]); + } + + public static function table(Table $table): Table + { + return $table + ->poll('60s') + ->columns([ + TextColumn::make('title') + ->toggleable() + ->searchable(true, null, true) + ->limit(50), + TextColumn::make('slug') + ->toggleable() + ->searchable(true, null, true) + ->limit(50), + TextColumn::make('domain') + ->toggleable() + ->searchable(true, null, true) + ->limit(50), + IconColumn::make('selection') + ->toggleable() + ->boolean(), + TextColumn::make('order') + ->toggleable() + ->searchable(true, null, true) + ->limit(50), + IconColumn::make('locked') + ->toggleable() + ->boolean(), + IconColumn::make('master') + ->toggleable() + ->boolean(), + ImageColumn::make('thumbnail') + ->toggleable() + ->circular(), + TextColumn::make('platformable_id') + ->toggleable() + ->searchable(true, null, true) + ->limit(50), + TextColumn::make('platformable_type') + ->toggleable() + ->searchable(true, null, true) + ->limit(50), + ]) + ->actions([ViewAction::make(), EditAction::make()]) + ->bulkActions([DeleteBulkAction::make()]); + } + + public static function getRelations(): array + { + return [ + // PlatformResource\RelationManagers\SyncsRelationManager::class, + // PlatformResource\RelationManagers\SyncsRelationManager::class, + ]; + } + + public static function getPages(): array + { + return [ + // 'index' => Pages\ListPlatforms::route('/'), + // 'create' => Pages\CreatePlatform::route('/create'), + // 'view' => Pages\ViewPlatform::route('/{record}'), + // 'edit' => Pages\EditPlatform::route('/{record}/edit'), + ]; + } +} diff --git a/packages/sync/src/Resources/SyncResource.php b/packages/sync/src/Resources/SyncResource.php index ccfd205df..e91a651a0 100644 --- a/packages/sync/src/Resources/SyncResource.php +++ b/packages/sync/src/Resources/SyncResource.php @@ -2,18 +2,20 @@ namespace Moox\Sync\Resources; -use Filament\Forms\Components\DateTimePicker; +use Filament\Forms\Components\DatePicker; +use Filament\Forms\Components\Grid; +use Filament\Forms\Components\Section; +use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; -use Filament\Forms\Components\Toggle; use Filament\Forms\Form; use Filament\Resources\Resource; use Filament\Tables\Actions\DeleteBulkAction; use Filament\Tables\Actions\EditAction; +use Filament\Tables\Actions\ViewAction; use Filament\Tables\Columns\TextColumn; +use Filament\Tables\Filters\SelectFilter; use Filament\Tables\Table; use Moox\Sync\Models\Sync; -use Moox\Sync\Resources\SyncResource\Pages\ListPage; -use Moox\Sync\Resources\SyncResource\Widgets\SyncWidgets; class SyncResource extends Resource { @@ -21,61 +23,123 @@ class SyncResource extends Resource protected static ?string $navigationIcon = 'heroicon-o-play'; + protected static ?string $recordTitleAttribute = 'syncable_type'; + public static function form(Form $form): Form { - return $form - ->schema([ - TextInput::make('name') - ->maxLength(255), - DateTimePicker::make('started_at'), - DateTimePicker::make('finished_at'), - Toggle::make('failed') - ->required(), - ]); + return $form->schema([ + Section::make()->schema([ + Grid::make(['default' => 0])->schema([ + TextInput::make('syncable_id') + ->rules(['max:255']) + ->required() + ->placeholder('Syncable Id') + ->columnSpan([ + 'default' => 12, + 'md' => 12, + 'lg' => 12, + ]), + + TextInput::make('syncable_type') + ->rules(['max:255', 'string']) + ->required() + ->placeholder('Syncable Type') + ->columnSpan([ + 'default' => 12, + 'md' => 12, + 'lg' => 12, + ]), + + Select::make('source_platform_id') + ->rules(['exists:platforms,id']) + ->required() + ->relationship('sourcePlatform', 'title') + ->searchable() + ->placeholder('Source Platform') + ->columnSpan([ + 'default' => 12, + 'md' => 12, + 'lg' => 12, + ]), + + Select::make('target_platform_id') + ->rules(['exists:platforms,id']) + ->required() + ->relationship('targetPlatform', 'title') + ->searchable() + ->placeholder('Target Platform') + ->columnSpan([ + 'default' => 12, + 'md' => 12, + 'lg' => 12, + ]), + + DatePicker::make('last_sync') + ->rules(['date']) + ->required() + ->placeholder('Last Sync') + ->columnSpan([ + 'default' => 12, + 'md' => 12, + 'lg' => 12, + ]), + ]), + ]), + ]); } public static function table(Table $table): Table { return $table + ->poll('60s') ->columns([ - TextColumn::make('name') - ->label(__('sync::translations.name')) - ->sortable(), - TextColumn::make('started_at') - ->label(__('sync::translations.started_at')) - ->since() - ->sortable(), - TextColumn::make('failed') - ->label(__('sync::translations.failed')) - ->sortable(), + TextColumn::make('syncable_id') + ->toggleable() + ->searchable(true, null, true) + ->limit(50), + TextColumn::make('syncable_type') + ->toggleable() + ->searchable(true, null, true) + ->limit(50), + TextColumn::make('sourcePlatform.title') + ->toggleable() + ->limit(50), + TextColumn::make('targetPlatform.title') + ->toggleable() + ->limit(50), + TextColumn::make('last_sync') + ->toggleable() + ->date(), ]) - ->defaultSort('name', 'desc') - ->actions([ - EditAction::make(), + ->filters([ + SelectFilter::make('source_platform_id') + ->relationship('sourcePlatform', 'title') + ->indicator('Platform') + ->multiple() + ->label('Platform'), + + SelectFilter::make('target_platform_id') + ->relationship('targetPlatform', 'title') + ->indicator('Platform') + ->multiple() + ->label('Platform'), ]) - ->bulkActions([ - DeleteBulkAction::make(), - ]); + ->actions([ViewAction::make(), EditAction::make()]) + ->bulkActions([DeleteBulkAction::make()]); } public static function getRelations(): array { - return [ - // - ]; + return []; } public static function getPages(): array { return [ - 'index' => ListPage::route('/'), - ]; - } - - public static function getWidgets(): array - { - return [ - SyncWidgets::class, + //'index' => Pages\ListSyncs::route('/'), + //'create' => Pages\CreateSync::route('/create'), + //'view' => Pages\ViewSync::route('/{record}'), + //'edit' => Pages\EditSync::route('/{record}/edit'), ]; } diff --git a/packages/sync/src/Resources/SyncResource/Pages/ListPage.php b/packages/sync/src/Resources/SyncResource/Pages/ListPage.php index 31b158608..178f03125 100644 --- a/packages/sync/src/Resources/SyncResource/Pages/ListPage.php +++ b/packages/sync/src/Resources/SyncResource/Pages/ListPage.php @@ -6,7 +6,6 @@ use Filament\Resources\Pages\ListRecords; use Moox\Sync\Models\Sync; use Moox\Sync\Resources\SyncResource; -use Moox\Sync\Resources\SyncResource\Widgets\SyncWidgets; class ListPage extends ListRecords { @@ -17,13 +16,6 @@ public function getActions(): array return []; } - public function getHeaderWidgets(): array - { - return [ - SyncWidgets::class, - ]; - } - public function getTitle(): string { return __('sync::translations.title'); diff --git a/packages/sync/src/Resources/SyncResource/Widgets/SyncWidgets.php b/packages/sync/src/Resources/SyncResource/Widgets/SyncWidgets.php deleted file mode 100644 index 08c36a53c..000000000 --- a/packages/sync/src/Resources/SyncResource/Widgets/SyncWidgets.php +++ /dev/null @@ -1,30 +0,0 @@ -select($aggregationColumns) - ->first(); - - return [ - Stat::make(__('sync::translations.totalone'), $aggregatedInfo->count ?? 0), - Stat::make(__('sync::translations.totaltwo'), $aggregatedInfo->count ?? 0), - Stat::make(__('sync::translations.totalthree'), $aggregatedInfo->count ?? 0), - ]; - } -} diff --git a/packages/sync/src/SyncServiceProvider.php b/packages/sync/src/SyncServiceProvider.php index 80c04da4a..f13611629 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(['create_syncs_table']) + ->hasMigrations(['01_create_syncs_table', '02_create_platforms_table']) ->hasCommand(InstallCommand::class); } }