Skip to content

Commit

Permalink
Sync Resources w-i-p
Browse files Browse the repository at this point in the history
  • Loading branch information
adrolli committed Mar 6, 2024
1 parent bb6f6db commit 218c90f
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 19 deletions.
3 changes: 3 additions & 0 deletions app/Providers/Filament/AdminPanelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public function panel(Panel $panel): Panel

\Leandrocfe\FilamentApexCharts\FilamentApexChartsPlugin::make(),


\Moox\Sync\PlatformPlugin::make(),

]);
}
}
5 changes: 5 additions & 0 deletions config/sync.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
// sync does not configure anything
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

return new class extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('platforms', function (Blueprint $table) {
$table->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');
}
};
32 changes: 32 additions & 0 deletions database/migrations/2024_03_06_142651_02_create_syncs_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('syncs', function (Blueprint $table) {
$table->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');
}
};
4 changes: 3 additions & 1 deletion packages/sync/resources/lang/en/translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions packages/sync/src/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),';
Expand Down
4 changes: 2 additions & 2 deletions packages/sync/src/Models/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion packages/sync/src/PlatformPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Filament\Support\Concerns\EvaluatesClosures;
use Moox\Sync\Resources\PlatformResource;

class SyncPlugin implements Plugin
class PlatformPlugin implements Plugin
{
use EvaluatesClosures;

Expand Down
47 changes: 44 additions & 3 deletions packages/sync/src/Resources/PlatformResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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';

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Moox\Sync\Resources\PlatformResource\Pages;

use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ListRecords;
use Moox\Sync\Models\Platform;
use Moox\Sync\Resources\PlatformResource;

class ListPlatforms extends ListRecords
{
public static string $resource = PlatformResource::class;

public function getActions(): array
{
return [];
}

public function getTitle(): string
{
return __('sync::translations.title');
}

protected function getHeaderActions(): array
{
return [
CreateAction::make()
->using(function (array $data, string $model): Platform {
return $model::create($data);
}),
];
}
}
12 changes: 4 additions & 8 deletions packages/sync/src/Resources/SyncResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -180,6 +176,6 @@ public static function getNavigationGroup(): ?string

public static function getNavigationSort(): ?int
{
return 2001;
return 1801;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion packages/sync/src/SyncServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 218c90f

Please sign in to comment.