mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 11:04:45 +02:00
Update database section on EditServer
This commit is contained in:
parent
482e8ed6b2
commit
6b5b480902
@ -44,7 +44,6 @@ class DatabasesRelationManager extends RelationManager
|
|||||||
->columns([
|
->columns([
|
||||||
Tables\Columns\TextColumn::make('database')->icon('tabler-database'),
|
Tables\Columns\TextColumn::make('database')->icon('tabler-database'),
|
||||||
Tables\Columns\TextColumn::make('username')->icon('tabler-user'),
|
Tables\Columns\TextColumn::make('username')->icon('tabler-user'),
|
||||||
//Tables\Columns\TextColumn::make('password'),
|
|
||||||
Tables\Columns\TextColumn::make('remote'),
|
Tables\Columns\TextColumn::make('remote'),
|
||||||
Tables\Columns\TextColumn::make('server.name')
|
Tables\Columns\TextColumn::make('server.name')
|
||||||
->icon('tabler-brand-docker')
|
->icon('tabler-brand-docker')
|
||||||
@ -55,7 +54,6 @@ class DatabasesRelationManager extends RelationManager
|
|||||||
->actions([
|
->actions([
|
||||||
Tables\Actions\DeleteAction::make(),
|
Tables\Actions\DeleteAction::make(),
|
||||||
Tables\Actions\ViewAction::make()->color('primary'),
|
Tables\Actions\ViewAction::make()->color('primary'),
|
||||||
//Tables\Actions\EditAction::make(),
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Filament\Resources\ServerResource\Pages;
|
namespace App\Filament\Resources\ServerResource\Pages;
|
||||||
|
|
||||||
|
use App\Models\Database;
|
||||||
use App\Services\Databases\DatabaseManagementService;
|
use App\Services\Databases\DatabaseManagementService;
|
||||||
|
use App\Services\Databases\DatabasePasswordService;
|
||||||
use Filament\Forms\Components\Actions\Action;
|
use Filament\Forms\Components\Actions\Action;
|
||||||
use Filament\Forms\Components\Repeater;
|
use Filament\Forms\Components\Repeater;
|
||||||
use Filament\Forms\Components\TextInput;
|
|
||||||
use LogicException;
|
use LogicException;
|
||||||
use App\Filament\Resources\ServerResource;
|
use App\Filament\Resources\ServerResource;
|
||||||
use App\Http\Controllers\Admin\ServersController;
|
use App\Http\Controllers\Admin\ServersController;
|
||||||
@ -592,34 +593,49 @@ class EditServer extends EditRecord
|
|||||||
->icon('tabler-database')
|
->icon('tabler-database')
|
||||||
->schema([
|
->schema([
|
||||||
Repeater::make('databases')
|
Repeater::make('databases')
|
||||||
->columnSpanFull()
|
|
||||||
->grid()
|
->grid()
|
||||||
|
->helperText(fn (Server $server) => $server->databases->isNotEmpty() ? '' : 'No Databases exist for this Server')
|
||||||
|
->columns(2)
|
||||||
->schema([
|
->schema([
|
||||||
TextInput::make('db_name')
|
Forms\Components\TextInput::make('database')
|
||||||
|
->columnSpan(2)
|
||||||
->label('Database Name')
|
->label('Database Name')
|
||||||
|
->disabled()
|
||||||
|
->formatStateUsing(fn ($record) => $record->database)
|
||||||
->hintAction(
|
->hintAction(
|
||||||
Action::make('Delete')
|
Action::make('Delete')
|
||||||
->color('danger')
|
->color('danger')
|
||||||
->icon('tabler-trash')
|
->icon('tabler-trash')
|
||||||
->action(fn (DatabaseManagementService $databaseManagementService, $record) => $databaseManagementService->delete($record))
|
->action(fn (DatabaseManagementService $databaseManagementService, $record) => $databaseManagementService->delete($record))
|
||||||
)
|
),
|
||||||
->formatStateUsing(fn ($record) => $record->database)
|
Forms\Components\TextInput::make('username')
|
||||||
->readOnly(),
|
->disabled()
|
||||||
TextInput::make('db_username')
|
|
||||||
->label('Username')
|
|
||||||
->inlineLabel()
|
|
||||||
->formatStateUsing(fn ($record) => $record->username)
|
->formatStateUsing(fn ($record) => $record->username)
|
||||||
->readOnly(),
|
->columnSpan(2),
|
||||||
TextInput::make('db_password')
|
Forms\Components\TextInput::make('password')
|
||||||
->label('Password')
|
->disabled()
|
||||||
->inlineLabel()
|
->hintAction(
|
||||||
->formatStateUsing(fn ($record) => $record->password)
|
Action::make('rotate')
|
||||||
->readOnly(),
|
->icon('tabler-refresh')
|
||||||
TextInput::make('db_max_connections')
|
->requiresConfirmation()
|
||||||
->label('Max Connections')
|
->action(fn (DatabasePasswordService $service, $record, $set, $get) => $this->rotatePassword($service, $record, $set, $get))
|
||||||
->inlineLabel()
|
)
|
||||||
->formatStateUsing(fn ($record) => $record->max_connections < 1 ? 'Unlimited' : $record->max_connections)
|
->formatStateUsing(fn (Database $database) => $database->password)
|
||||||
->readOnly(),
|
->columnSpan(2),
|
||||||
|
Forms\Components\TextInput::make('remote')
|
||||||
|
->disabled()
|
||||||
|
->formatStateUsing(fn ($record) => $record->remote)
|
||||||
|
->columnSpan(1)
|
||||||
|
->label('Connections From'),
|
||||||
|
Forms\Components\TextInput::make('max_connections')
|
||||||
|
->disabled()
|
||||||
|
->formatStateUsing(fn ($record) => $record->max_connections)
|
||||||
|
->columnSpan(1),
|
||||||
|
Forms\Components\TextInput::make('JDBC')
|
||||||
|
->disabled()
|
||||||
|
->label('JDBC Connection String')
|
||||||
|
->columnSpan(2)
|
||||||
|
->formatStateUsing(fn (Forms\Get $get, $record) => 'jdbc:mysql://' . $get('username') . ':' . urlencode($record->password) . '@' . $record->host->host . ':' . $record->host->port . '/' . $get('database')),
|
||||||
])
|
])
|
||||||
->relationship('databases')
|
->relationship('databases')
|
||||||
->deletable(false)
|
->deletable(false)
|
||||||
@ -825,4 +841,13 @@ class EditServer extends EditRecord
|
|||||||
->mapWithKeys(fn ($value) => [$value => $value])
|
->mapWithKeys(fn ($value) => [$value => $value])
|
||||||
->all();
|
->all();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function rotatePassword(DatabasePasswordService $service, $record, $set, $get): void
|
||||||
|
{
|
||||||
|
$newPassword = $service->handle($record);
|
||||||
|
$jdbcString = 'jdbc:mysql://' . $get('username') . ':' . urlencode($newPassword) . '@' . $record->host->host . ':' . $record->host->port . '/' . $get('database');
|
||||||
|
|
||||||
|
$set('password', $newPassword);
|
||||||
|
$set('JDBC', $jdbcString);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user