mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 05:14:46 +02:00

* Add Create Database btn on admin side * Remove unused function * readd function * replace refreshform function * add authorize, remove database limit check * add random words, use proper name function, catch exceptions on creation * add validation, match old client area more * Add more authorize to Database tab * Add confirmation to delete * make password hidden / revealable * better clarification * Set default and remove placeholder. * Remove server import, add database model to auth * Make same changes for the database host page * Update app/Filament/Resources/ServerResource/Pages/EditServer.php Co-authored-by: Boy132 <Boy132@users.noreply.github.com> * Update app/Filament/Resources/DatabaseHostResource/RelationManagers/DatabasesRelationManager.php Co-authored-by: Boy132 <Boy132@users.noreply.github.com> * Update app/Filament/Resources/DatabaseHostResource/RelationManagers/DatabasesRelationManager.php Co-authored-by: Boy132 <Boy132@users.noreply.github.com> * Remove each hidden * Return nothing if user has no perms * This is the way... Im done messing with it... * Fix view permission for relationship manager * Update app/Filament/Resources/DatabaseHostResource/RelationManagers/DatabasesRelationManager.php * Pint --------- Co-authored-by: Boy132 <Boy132@users.noreply.github.com> Co-authored-by: MartinOscar <40749467+RMartinOscar@users.noreply.github.com>
137 lines
5.1 KiB
PHP
137 lines
5.1 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\DatabaseHostResource\Pages;
|
|
|
|
use App\Filament\Resources\DatabaseHostResource;
|
|
use App\Filament\Resources\DatabaseHostResource\RelationManagers\DatabasesRelationManager;
|
|
use App\Models\DatabaseHost;
|
|
use App\Services\Databases\Hosts\HostUpdateService;
|
|
use Closure;
|
|
use Exception;
|
|
use Filament\Actions;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Components\Section;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Forms\Form;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Pages\EditRecord;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use PDOException;
|
|
|
|
class EditDatabaseHost extends EditRecord
|
|
{
|
|
protected static string $resource = DatabaseHostResource::class;
|
|
|
|
private HostUpdateService $hostUpdateService;
|
|
|
|
public function boot(HostUpdateService $hostUpdateService): void
|
|
{
|
|
$this->hostUpdateService = $hostUpdateService;
|
|
}
|
|
|
|
public function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->schema([
|
|
Section::make()
|
|
->columns([
|
|
'default' => 2,
|
|
'sm' => 3,
|
|
'md' => 3,
|
|
'lg' => 4,
|
|
])
|
|
->schema([
|
|
TextInput::make('host')
|
|
->columnSpan(2)
|
|
->helperText('The IP address or Domain name that should be used when attempting to connect to this MySQL host from this Panel to create new databases.')
|
|
->required()
|
|
->live(onBlur: true)
|
|
->afterStateUpdated(fn ($state, Forms\Set $set) => $set('name', $state))
|
|
->maxLength(255),
|
|
TextInput::make('port')
|
|
->columnSpan(1)
|
|
->helperText('The port that MySQL is running on for this host.')
|
|
->required()
|
|
->numeric()
|
|
->minValue(0)
|
|
->maxValue(65535),
|
|
TextInput::make('max_databases')
|
|
->label('Max databases')
|
|
->helpertext('Blank is unlimited.')
|
|
->numeric(),
|
|
TextInput::make('name')
|
|
->label('Display Name')
|
|
->helperText('A short identifier used to distinguish this location from others. Must be between 1 and 60 characters, for example, us.nyc.lvl3.')
|
|
->required()
|
|
->maxLength(60),
|
|
TextInput::make('username')
|
|
->helperText('The username of an account that has enough permissions to create new users and databases on the system.')
|
|
->required()
|
|
->maxLength(255),
|
|
TextInput::make('password')
|
|
->helperText('The password for the database user.')
|
|
->password()
|
|
->revealable()
|
|
->maxLength(255),
|
|
Select::make('node_id')
|
|
->searchable()
|
|
->preload()
|
|
->helperText('This setting only defaults to this database host when adding a database to a server on the selected node.')
|
|
->label('Linked Node')
|
|
->relationship('node', 'name'),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
Actions\DeleteAction::make()
|
|
->label(fn (DatabaseHost $databaseHost) => $databaseHost->databases()->count() > 0 ? 'Database Host Has Databases' : 'Delete')
|
|
->disabled(fn (DatabaseHost $databaseHost) => $databaseHost->databases()->count() > 0),
|
|
$this->getSaveFormAction()->formId('form'),
|
|
];
|
|
}
|
|
|
|
protected function getFormActions(): array
|
|
{
|
|
return [];
|
|
}
|
|
|
|
public function getRelationManagers(): array
|
|
{
|
|
if (DatabasesRelationManager::canViewForRecord($this->getRecord(), static::class)) {
|
|
return [
|
|
DatabasesRelationManager::class,
|
|
];
|
|
}
|
|
|
|
return [];
|
|
}
|
|
|
|
protected function handleRecordUpdate(Model $record, array $data): Model
|
|
{
|
|
if (!$record instanceof DatabaseHost) {
|
|
return $record;
|
|
}
|
|
|
|
return $this->hostUpdateService->handle($record, $data);
|
|
}
|
|
|
|
public function exception(Exception $e, Closure $stopPropagation): void
|
|
{
|
|
if ($e instanceof PDOException) {
|
|
Notification::make()
|
|
->title('Error connecting to database host')
|
|
->body($e->getMessage())
|
|
->color('danger')
|
|
->icon('tabler-database')
|
|
->danger()
|
|
->send();
|
|
|
|
$stopPropagation();
|
|
}
|
|
}
|
|
}
|