Skip to content

Commit

Permalink
Add Databases to Edit Server
Browse files Browse the repository at this point in the history
  • Loading branch information
notAreYouScared committed Jun 16, 2024
1 parent 59bbb63 commit 482e8ed
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
3 changes: 1 addition & 2 deletions app/Filament/Resources/EggResource/Pages/ListEggs.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public function table(Table $table): Table
->columns([
Tables\Columns\TextColumn::make('id')
->label('Id')
->searchable()
->sortable(),
->hidden(),
Tables\Columns\TextColumn::make('name')
->icon('tabler-egg')
->description(fn ($record): ?string => (strlen($record->description) > 120) ? substr($record->description, 0, 120).'...' : $record->description)
Expand Down
46 changes: 42 additions & 4 deletions app/Filament/Resources/ServerResource/Pages/EditServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace App\Filament\Resources\ServerResource\Pages;

use App\Services\Databases\DatabaseManagementService;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\TextInput;
use LogicException;
use App\Filament\Resources\ServerResource;
use App\Http\Controllers\Admin\ServersController;
Expand Down Expand Up @@ -587,9 +591,41 @@ public function form(Form $form): Form
Tabs\Tab::make('Databases')
->icon('tabler-database')
->schema([
Forms\Components\Placeholder::make('soon')
->label('Soon™'),
]),
Repeater::make('databases')
->columnSpanFull()
->grid()
->schema([
TextInput::make('db_name')
->label('Database Name')
->hintAction(
Action::make('Delete')
->color('danger')
->icon('tabler-trash')
->action(fn (DatabaseManagementService $databaseManagementService, $record) => $databaseManagementService->delete($record))
)
->formatStateUsing(fn ($record) => $record->database)
->readOnly(),
TextInput::make('db_username')
->label('Username')
->inlineLabel()
->formatStateUsing(fn ($record) => $record->username)
->readOnly(),
TextInput::make('db_password')
->label('Password')
->inlineLabel()
->formatStateUsing(fn ($record) => $record->password)
->readOnly(),
TextInput::make('db_max_connections')
->label('Max Connections')
->inlineLabel()
->formatStateUsing(fn ($record) => $record->max_connections < 1 ? 'Unlimited' : $record->max_connections)
->readOnly(),
])
->relationship('databases')
->deletable(false)
->addable(false)
->columnSpan(4),
])->columns(4),
Tabs\Tab::make('Actions')
->icon('tabler-settings')
->schema([
Expand Down Expand Up @@ -709,7 +745,7 @@ public function form(Form $form): Form
protected function transferServer(Form $form): Form
{
return $form
->columns(2)
->columns()
->schema([
Forms\Components\Select::make('toNode')
->label('New Node'),
Expand All @@ -724,6 +760,8 @@ protected function getHeaderActions(): array
Actions\DeleteAction::make('Delete')
->successRedirectUrl(route('filament.admin.resources.servers.index'))
->color('danger')
->disabled(fn (Server $server) => $server->databases()->count() > 0)
->label(fn (Server $server) => $server->databases()->count() > 0 ? 'Server has a Database' : 'Delete')
->after(fn (Server $server) => resolve(ServerDeletionService::class)->handle($server))
->requiresConfirmation(),
Actions\Action::make('console')
Expand Down

0 comments on commit 482e8ed

Please sign in to comment.