From 97e143d284486c06881d0ad6a17353f517045854 Mon Sep 17 00:00:00 2001 From: Curtis Delicata Date: Sat, 31 Aug 2024 02:15:18 +0000 Subject: [PATCH] Rename --- .../App/Resources/DatabaseResource.php | 48 +++++++--- .../Pages/CreateResource.php | 6 +- .../Pages/EditResource.php | 6 +- .../Pages/ListResources.php | 6 +- .../App/Resources/ResourceResource.php | 93 ------------------- 5 files changed, 43 insertions(+), 116 deletions(-) rename app/Filament/App/Resources/{ResourceResource => DatabaseResource}/Pages/CreateResource.php (82%) rename app/Filament/App/Resources/{ResourceResource => DatabaseResource}/Pages/EditResource.php (86%) rename app/Filament/App/Resources/{ResourceResource => DatabaseResource}/Pages/ListResources.php (68%) delete mode 100644 app/Filament/App/Resources/ResourceResource.php diff --git a/app/Filament/App/Resources/DatabaseResource.php b/app/Filament/App/Resources/DatabaseResource.php index 18feec73..730a423c 100644 --- a/app/Filament/App/Resources/DatabaseResource.php +++ b/app/Filament/App/Resources/DatabaseResource.php @@ -2,33 +2,43 @@ namespace App\Filament\App\Resources; -use App\Filament\App\Resources\ResourceResource\Pages; -use App\Filament\App\Resources\ResourceResource\RelationManagers; -use App\Models\Resource as ResourceModel; +use App\Filament\App\Resources\DatabaseResource\Pages; +use App\Models\Database; use Filament\Forms; -use Filament\Forms\Form; use Filament\Resources\Resource; use Filament\Tables; use Filament\Tables\Table; -use Illuminate\Database\Eloquent\Builder; -use Illuminate\Database\Eloquent\SoftDeletingScope; +use App\Services\MySqlDatabaseService; -class ResourceResource extends Resource +class DatabaseResource extends Resource { protected static ?string $model = Database::class; protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack'; - public static function form(Form $form): Form + public static function form(Forms\Form $form): Forms\Form { return $form ->schema([ Forms\Components\TextInput::make('name') ->required() ->maxLength(255), - Forms\Components\TextInput::make('user_id') + Forms\Components\Select::make('charset') ->required() - ->numeric(), + ->options([ + 'utf8mb4' => 'UTF-8 Unicode (utf8mb4)', + 'latin1' => 'Latin1 (latin1)', + // Add more options as needed + ]) + ->default('utf8mb4'), + Forms\Components\Select::make('collation') + ->required() + ->options([ + 'utf8mb4_unicode_ci' => 'UTF-8 Unicode (utf8mb4_unicode_ci)', + 'latin1_swedish_ci' => 'Latin1 Swedish (latin1_swedish_ci)', + // Add more options as needed + ]) + ->default('utf8mb4_unicode_ci'), ]); } @@ -38,19 +48,29 @@ public static function table(Table $table): Table ->columns([ Tables\Columns\TextColumn::make('name') ->searchable(), - Tables\Columns\TextColumn::make('user_id') - ->numeric() - ->sortable(), + Tables\Columns\TextColumn::make('charset'), + Tables\Columns\TextColumn::make('collation'), + Tables\Columns\TextColumn::make('created_at') + ->dateTime(), ]) ->filters([ // ]) ->actions([ Tables\Actions\EditAction::make(), + Tables\Actions\DeleteAction::make() + ->before(function (Database $record, MySqlDatabaseService $service) { + $service->dropDatabase($record->name); + }), ]) ->bulkActions([ Tables\Actions\BulkActionGroup::make([ - Tables\Actions\DeleteBulkAction::make(), + Tables\Actions\DeleteBulkAction::make() + ->before(function (Collection $records, MySqlDatabaseService $service) { + foreach ($records as $record) { + $service->dropDatabase($record->name); + } + }), ]), ]); } diff --git a/app/Filament/App/Resources/ResourceResource/Pages/CreateResource.php b/app/Filament/App/Resources/DatabaseResource/Pages/CreateResource.php similarity index 82% rename from app/Filament/App/Resources/ResourceResource/Pages/CreateResource.php rename to app/Filament/App/Resources/DatabaseResource/Pages/CreateResource.php index f032f62a..05070110 100644 --- a/app/Filament/App/Resources/ResourceResource/Pages/CreateResource.php +++ b/app/Filament/App/Resources/DatabaseResource/Pages/CreateResource.php @@ -1,8 +1,8 @@ schema([ - Forms\Components\TextInput::make('name') - ->required() - ->maxLength(255), - Forms\Components\Select::make('charset') - ->required() - ->options([ - 'utf8mb4' => 'UTF-8 Unicode (utf8mb4)', - 'latin1' => 'Latin1 (latin1)', - // Add more options as needed - ]) - ->default('utf8mb4'), - Forms\Components\Select::make('collation') - ->required() - ->options([ - 'utf8mb4_unicode_ci' => 'UTF-8 Unicode (utf8mb4_unicode_ci)', - 'latin1_swedish_ci' => 'Latin1 Swedish (latin1_swedish_ci)', - // Add more options as needed - ]) - ->default('utf8mb4_unicode_ci'), - ]); - } - - public static function table(Table $table): Table - { - return $table - ->columns([ - Tables\Columns\TextColumn::make('name') - ->searchable(), - Tables\Columns\TextColumn::make('charset'), - Tables\Columns\TextColumn::make('collation'), - Tables\Columns\TextColumn::make('created_at') - ->dateTime(), - ]) - ->filters([ - // - ]) - ->actions([ - Tables\Actions\EditAction::make(), - Tables\Actions\DeleteAction::make() - ->before(function (Database $record, MySqlDatabaseService $service) { - $service->dropDatabase($record->name); - }), - ]) - ->bulkActions([ - Tables\Actions\BulkActionGroup::make([ - Tables\Actions\DeleteBulkAction::make() - ->before(function (Collection $records, MySqlDatabaseService $service) { - foreach ($records as $record) { - $service->dropDatabase($record->name); - } - }), - ]), - ]); - } - - public static function getRelations(): array - { - return [ - // - ]; - } - - public static function getPages(): array - { - return [ - 'index' => Pages\ListResources::route('/'), - 'create' => Pages\CreateResource::route('/create'), - 'edit' => Pages\EditResource::route('/{record}/edit'), - ]; - } -} \ No newline at end of file