mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 14:36:17 +00:00
2.x - databases
This commit is contained in:
13
app/Web/Components/Page.php
Normal file
13
app/Web/Components/Page.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Web\Components;
|
||||
|
||||
use App\Web\Traits\HasWidgets;
|
||||
use Filament\Pages\Page as BasePage;
|
||||
|
||||
abstract class Page extends BasePage
|
||||
{
|
||||
use HasWidgets;
|
||||
|
||||
protected static string $view = 'web.components.page';
|
||||
}
|
@ -3,14 +3,11 @@
|
||||
namespace App\Web\Pages\Servers;
|
||||
|
||||
use App\Models\Server;
|
||||
use App\Web\Traits\PageHasWidgets;
|
||||
use App\Web\Components\Page;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Pages\Page;
|
||||
|
||||
class Create extends Page
|
||||
{
|
||||
use PageHasWidgets;
|
||||
|
||||
protected static ?string $slug = 'servers/create';
|
||||
|
||||
protected static bool $shouldRegisterNavigation = false;
|
||||
|
34
app/Web/Pages/Servers/Databases/Backups.php
Normal file
34
app/Web/Pages/Servers/Databases/Backups.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Web\Pages\Servers\Databases;
|
||||
|
||||
use App\Models\Backup;
|
||||
use App\Models\Server;
|
||||
use App\Web\Components\Page;
|
||||
use App\Web\Traits\PageHasServer;
|
||||
|
||||
class Backups extends Page
|
||||
{
|
||||
use PageHasServer;
|
||||
use Traits\Navigation;
|
||||
|
||||
protected static ?string $slug = 'servers/{server}/databases/backups';
|
||||
|
||||
protected static bool $shouldRegisterNavigation = false;
|
||||
|
||||
protected static ?string $title = 'Backups';
|
||||
|
||||
public Server $server;
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return auth()->user()?->can('viewAny', [Backup::class, static::getServerFromRoute()]) ?? false;
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
|
||||
];
|
||||
}
|
||||
}
|
96
app/Web/Pages/Servers/Databases/Index.php
Normal file
96
app/Web/Pages/Servers/Databases/Index.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace App\Web\Pages\Servers\Databases;
|
||||
|
||||
use App\Actions\Database\CreateDatabase;
|
||||
use App\Models\Database;
|
||||
use App\Models\Server;
|
||||
use App\Web\Components\Page;
|
||||
use App\Web\Traits\PageHasServer;
|
||||
use Exception;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\Checkbox;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Support\Enums\MaxWidth;
|
||||
|
||||
class Index extends Page
|
||||
{
|
||||
use PageHasServer;
|
||||
use Traits\Navigation;
|
||||
|
||||
protected static ?string $slug = 'servers/{server}/databases';
|
||||
|
||||
protected static bool $shouldRegisterNavigation = false;
|
||||
|
||||
protected static ?string $title = 'Databases';
|
||||
|
||||
public Server $server;
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return auth()->user()?->can('viewAny', [Database::class, static::getServerFromRoute()]) ?? false;
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('Create Database')
|
||||
->icon('heroicon-o-plus')
|
||||
->modalWidth(MaxWidth::Large)
|
||||
->authorize(fn () => auth()->user()?->can('create', [Database::class, $this->server]))
|
||||
->form([
|
||||
TextInput::make('name')
|
||||
->rules(fn (callable $get) => CreateDatabase::rules($this->server, $get())['name']),
|
||||
Checkbox::make('user')
|
||||
->label('Create User')
|
||||
->default(false)
|
||||
->reactive(),
|
||||
TextInput::make('username')
|
||||
->label('Username')
|
||||
->rules(fn (callable $get) => CreateDatabase::rules($this->server, $get())['username'])
|
||||
->hidden(fn (callable $get) => $get('user') !== true),
|
||||
TextInput::make('password')
|
||||
->label('Password')
|
||||
->rules(fn (callable $get) => CreateDatabase::rules($this->server, $get())['password'])
|
||||
->hidden(fn (callable $get) => $get('user') !== true),
|
||||
Checkbox::make('remote')
|
||||
->label('Remote')
|
||||
->default(false)
|
||||
->hidden(fn (callable $get) => $get('user') !== true)
|
||||
->reactive(),
|
||||
TextInput::make('host')
|
||||
->label('Host')
|
||||
->rules(fn (callable $get) => CreateDatabase::rules($this->server, $get())['host'])
|
||||
->hidden(fn (callable $get) => $get('remote') !== true),
|
||||
])
|
||||
->modalSubmitActionLabel('Create')
|
||||
->action(function (array $data) {
|
||||
try {
|
||||
app(CreateDatabase::class)->create($this->server, $data);
|
||||
|
||||
$this->dispatch('$refresh');
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
->title('Database Created!')
|
||||
->send();
|
||||
} catch (Exception $e) {
|
||||
Notification::make()
|
||||
->danger()
|
||||
->title($e->getMessage())
|
||||
->send();
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
public function getWidgets(): array
|
||||
{
|
||||
return [
|
||||
[Widgets\DatabasesList::class, ['server' => $this->server]],
|
||||
];
|
||||
}
|
||||
}
|
45
app/Web/Pages/Servers/Databases/Traits/Navigation.php
Normal file
45
app/Web/Pages/Servers/Databases/Traits/Navigation.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Web\Pages\Servers\Databases\Traits;
|
||||
|
||||
use App\Web\Pages\Servers\Databases\Backups as Backups;
|
||||
use App\Web\Pages\Servers\Databases\Index as Databases;
|
||||
use App\Web\Pages\Servers\Databases\Users as Users;
|
||||
use Filament\Navigation\NavigationGroup;
|
||||
use Filament\Navigation\NavigationItem;
|
||||
|
||||
trait Navigation
|
||||
{
|
||||
public bool $hasSecondSubNavigation = true;
|
||||
|
||||
public function getSecondSubNavigation(): array
|
||||
{
|
||||
$items = [];
|
||||
|
||||
if (Databases::canAccess()) {
|
||||
$items[] = NavigationItem::make(Databases::getNavigationLabel())
|
||||
->icon('heroicon-o-circle-stack')
|
||||
->isActiveWhen(fn () => request()->routeIs(Databases::getRouteName()))
|
||||
->url(Databases::getUrl(parameters: ['server' => $this->server]));
|
||||
}
|
||||
|
||||
if (Users::canAccess()) {
|
||||
$items[] = NavigationItem::make(Users::getNavigationLabel())
|
||||
->icon('heroicon-o-users')
|
||||
->isActiveWhen(fn () => request()->routeIs(Users::getRouteName()))
|
||||
->url(Users::getUrl(parameters: ['server' => $this->server]));
|
||||
}
|
||||
|
||||
if (Backups::canAccess()) {
|
||||
$items[] = NavigationItem::make(Backups::getNavigationLabel())
|
||||
->icon('heroicon-o-circle-stack')
|
||||
->isActiveWhen(fn () => request()->routeIs(Backups::getRouteName()))
|
||||
->url(Backups::getUrl(parameters: ['server' => $this->server]));
|
||||
}
|
||||
|
||||
return [
|
||||
NavigationGroup::make()
|
||||
->items($items),
|
||||
];
|
||||
}
|
||||
}
|
88
app/Web/Pages/Servers/Databases/Users.php
Normal file
88
app/Web/Pages/Servers/Databases/Users.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Web\Pages\Servers\Databases;
|
||||
|
||||
use App\Actions\Database\CreateDatabase;
|
||||
use App\Actions\Database\CreateDatabaseUser;
|
||||
use App\Models\DatabaseUser;
|
||||
use App\Models\Server;
|
||||
use App\Web\Components\Page;
|
||||
use App\Web\Traits\PageHasServer;
|
||||
use Exception;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\Checkbox;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Support\Enums\MaxWidth;
|
||||
|
||||
class Users extends Page
|
||||
{
|
||||
use PageHasServer;
|
||||
use Traits\Navigation;
|
||||
|
||||
protected static ?string $slug = 'servers/{server}/databases/users';
|
||||
|
||||
protected static bool $shouldRegisterNavigation = false;
|
||||
|
||||
protected static ?string $title = 'Database Users';
|
||||
|
||||
public Server $server;
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return auth()->user()?->can('viewAny', [DatabaseUser::class, static::getServerFromRoute()]) ?? false;
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('Create User')
|
||||
->icon('heroicon-o-plus')
|
||||
->modalWidth(MaxWidth::Large)
|
||||
->authorize(fn () => auth()->user()?->can('create', [DatabaseUser::class, $this->server]))
|
||||
->form([
|
||||
TextInput::make('username')
|
||||
->label('Username')
|
||||
->rules(fn (callable $get) => CreateDatabaseUser::rules($this->server, $get())['username']),
|
||||
TextInput::make('password')
|
||||
->label('Password')
|
||||
->rules(fn (callable $get) => CreateDatabaseUser::rules($this->server, $get())['password']),
|
||||
Checkbox::make('remote')
|
||||
->label('Remote')
|
||||
->default(false)
|
||||
->reactive(),
|
||||
TextInput::make('host')
|
||||
->label('Host')
|
||||
->rules(fn (callable $get) => CreateDatabase::rules($this->server, $get())['host'])
|
||||
->hidden(fn (callable $get) => $get('remote') !== true),
|
||||
])
|
||||
->modalSubmitActionLabel('Create')
|
||||
->action(function (array $data) {
|
||||
try {
|
||||
app(CreateDatabaseUser::class)->create($this->server, $data);
|
||||
|
||||
$this->dispatch('$refresh');
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
->title('Database user created!')
|
||||
->send();
|
||||
} catch (Exception $e) {
|
||||
Notification::make()
|
||||
->danger()
|
||||
->title($e->getMessage())
|
||||
->send();
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
public function getWidgets(): array
|
||||
{
|
||||
return [
|
||||
[Widgets\DatabaseUsersList::class, ['server' => $this->server]],
|
||||
];
|
||||
}
|
||||
}
|
147
app/Web/Pages/Servers/Databases/Widgets/DatabaseUsersList.php
Normal file
147
app/Web/Pages/Servers/Databases/Widgets/DatabaseUsersList.php
Normal file
@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace App\Web\Pages\Servers\Databases\Widgets;
|
||||
|
||||
use App\Actions\Database\DeleteDatabaseUser;
|
||||
use App\Actions\Database\LinkUser;
|
||||
use App\Models\DatabaseUser;
|
||||
use App\Models\Server;
|
||||
use Exception;
|
||||
use Filament\Forms\Components\CheckboxList;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Support\Enums\MaxWidth;
|
||||
use Filament\Tables\Actions\Action;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Widgets\TableWidget as Widget;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class DatabaseUsersList extends Widget
|
||||
{
|
||||
public Server $server;
|
||||
|
||||
protected $listeners = ['$refresh'];
|
||||
|
||||
protected function getTableQuery(): Builder
|
||||
{
|
||||
return DatabaseUser::query()->where('server_id', $this->server->id);
|
||||
}
|
||||
|
||||
protected static ?string $heading = '';
|
||||
|
||||
protected function getTableColumns(): array
|
||||
{
|
||||
return [
|
||||
TextColumn::make('id')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('username')
|
||||
->searchable(),
|
||||
TextColumn::make('status')
|
||||
->label('Status')
|
||||
->badge()
|
||||
->color(fn (DatabaseUser $databaseUser) => DatabaseUser::$statusColors[$databaseUser->status])
|
||||
->sortable(),
|
||||
TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->formatStateUsing(fn ($record) => $record->created_at_by_timezone)
|
||||
->sortable(),
|
||||
];
|
||||
}
|
||||
|
||||
public function getTable(): Table
|
||||
{
|
||||
return $this->table
|
||||
->actions([
|
||||
$this->passwordAction(),
|
||||
$this->linkAction(),
|
||||
$this->deleteAction(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function passwordAction(): Action
|
||||
{
|
||||
return Action::make('password')
|
||||
->hiddenLabel()
|
||||
->icon('heroicon-o-key')
|
||||
->color('secondary')
|
||||
->modalHeading('Database user\'s password')
|
||||
->modalWidth(MaxWidth::Large)
|
||||
->tooltip('Show the password')
|
||||
->authorize(fn ($record) => auth()->user()->can('view', $record))
|
||||
->form([
|
||||
TextInput::make('password')
|
||||
->label('Password')
|
||||
->default(fn (DatabaseUser $record) => $record->password)
|
||||
->disabled(),
|
||||
])
|
||||
->action(function (DatabaseUser $record, array $data) {
|
||||
//
|
||||
})
|
||||
->modalSubmitAction(false)
|
||||
->modalCancelActionLabel('Close');
|
||||
}
|
||||
|
||||
private function linkAction(): Action
|
||||
{
|
||||
return Action::make('link')
|
||||
->hiddenLabel()
|
||||
->icon('heroicon-o-link')
|
||||
->modalHeading('Link user to databases')
|
||||
->modalWidth(MaxWidth::Large)
|
||||
->tooltip('Link user')
|
||||
->modalSubmitActionLabel('Save')
|
||||
->authorize(fn ($record) => auth()->user()->can('update', $record))
|
||||
->form([
|
||||
CheckboxList::make('databases')
|
||||
->label('Databases')
|
||||
->options($this->server->databases()->pluck('name', 'name')->toArray())
|
||||
->rules(fn (callable $get) => LinkUser::rules($this->server, $get()))
|
||||
->default(fn (DatabaseUser $record) => $record->databases),
|
||||
])
|
||||
->action(function (DatabaseUser $record, array $data) {
|
||||
try {
|
||||
app(LinkUser::class)->link($record, $data);
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
->title('User linked to databases!')
|
||||
->send();
|
||||
} catch (Exception $e) {
|
||||
Notification::make()
|
||||
->danger()
|
||||
->title($e->getMessage())
|
||||
->send();
|
||||
|
||||
throw $e;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private function deleteAction(): Action
|
||||
{
|
||||
return Action::make('delete')
|
||||
->hiddenLabel()
|
||||
->icon('heroicon-o-trash')
|
||||
->modalHeading('Delete Database User')
|
||||
->color('danger')
|
||||
->tooltip('Delete')
|
||||
->authorize(fn ($record) => auth()->user()->can('delete', $record))
|
||||
->requiresConfirmation()
|
||||
->action(function (DatabaseUser $record) {
|
||||
try {
|
||||
app(DeleteDatabaseUser::class)->delete($this->server, $record);
|
||||
} catch (Exception $e) {
|
||||
Notification::make()
|
||||
->danger()
|
||||
->title($e->getMessage())
|
||||
->send();
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->dispatch('$refresh');
|
||||
});
|
||||
}
|
||||
}
|
77
app/Web/Pages/Servers/Databases/Widgets/DatabasesList.php
Normal file
77
app/Web/Pages/Servers/Databases/Widgets/DatabasesList.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Web\Pages\Servers\Databases\Widgets;
|
||||
|
||||
use App\Actions\Database\DeleteDatabase;
|
||||
use App\Models\Database;
|
||||
use App\Models\Server;
|
||||
use Exception;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Tables\Actions\Action;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Widgets\TableWidget as Widget;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class DatabasesList extends Widget
|
||||
{
|
||||
public Server $server;
|
||||
|
||||
protected $listeners = ['$refresh'];
|
||||
|
||||
protected function getTableQuery(): Builder
|
||||
{
|
||||
return Database::query()->where('server_id', $this->server->id);
|
||||
}
|
||||
|
||||
protected static ?string $heading = '';
|
||||
|
||||
protected function getTableColumns(): array
|
||||
{
|
||||
return [
|
||||
TextColumn::make('id')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('name')
|
||||
->searchable(),
|
||||
TextColumn::make('status')
|
||||
->label('Status')
|
||||
->badge()
|
||||
->color(fn (Database $database) => Database::$statusColors[$database->status])
|
||||
->sortable(),
|
||||
TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->formatStateUsing(fn ($record) => $record->created_at_by_timezone)
|
||||
->sortable(),
|
||||
];
|
||||
}
|
||||
|
||||
public function getTable(): Table
|
||||
{
|
||||
return $this->table
|
||||
->actions([
|
||||
Action::make('delete')
|
||||
->hiddenLabel()
|
||||
->icon('heroicon-o-trash')
|
||||
->modalHeading('Delete Database')
|
||||
->color('danger')
|
||||
->tooltip('Delete')
|
||||
->authorize(fn ($record) => auth()->user()->can('delete', $record))
|
||||
->requiresConfirmation()
|
||||
->action(function (Database $record) {
|
||||
try {
|
||||
app(DeleteDatabase::class)->delete($this->server, $record);
|
||||
} catch (Exception $e) {
|
||||
Notification::make()
|
||||
->danger()
|
||||
->title($e->getMessage())
|
||||
->send();
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->dispatch('$refresh');
|
||||
}),
|
||||
]);
|
||||
}
|
||||
}
|
@ -3,14 +3,11 @@
|
||||
namespace App\Web\Pages\Servers;
|
||||
|
||||
use App\Models\Server;
|
||||
use App\Web\Traits\PageHasWidgets;
|
||||
use App\Web\Components\Page;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Pages\Page;
|
||||
|
||||
class Index extends Page
|
||||
{
|
||||
use PageHasWidgets;
|
||||
|
||||
protected static ?string $slug = 'servers';
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-server-stack';
|
||||
|
@ -4,15 +4,13 @@
|
||||
|
||||
use App\Models\Server;
|
||||
use App\Models\ServerLog;
|
||||
use App\Web\Components\Page;
|
||||
use App\Web\Pages\Servers\Logs\Widgets\LogsList;
|
||||
use App\Web\Traits\PageHasServer;
|
||||
use App\Web\Traits\PageHasWidgets;
|
||||
use Filament\Pages\Page;
|
||||
|
||||
class Index extends Page
|
||||
{
|
||||
use PageHasServer;
|
||||
use PageHasWidgets;
|
||||
|
||||
protected static ?string $slug = 'servers/{server}/logs';
|
||||
|
||||
|
@ -23,16 +23,18 @@ protected function getTableQuery(): Builder
|
||||
return ServerLog::query()->where('server_id', $this->server->id);
|
||||
}
|
||||
|
||||
protected static ?string $heading = 'Logs';
|
||||
protected static ?string $heading = '';
|
||||
|
||||
protected function getTableColumns(): array
|
||||
{
|
||||
return [
|
||||
TextColumn::make('name')
|
||||
->label('Event')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('created_at_by_timezone')
|
||||
TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->formatStateUsing(fn ($record) => $record->created_at_by_timezone)
|
||||
->sortable(),
|
||||
];
|
||||
}
|
||||
@ -68,7 +70,8 @@ public function getTable(): Table
|
||||
])
|
||||
->actions([
|
||||
Action::make('view')
|
||||
->label('View')
|
||||
->hiddenLabel()
|
||||
->tooltip('View')
|
||||
->icon('heroicon-o-eye')
|
||||
->authorize(fn ($record) => auth()->user()->can('view', $record))
|
||||
->modalHeading('View Log')
|
||||
@ -81,7 +84,8 @@ public function getTable(): Table
|
||||
->modalSubmitAction(false)
|
||||
->modalCancelActionLabel('Close'),
|
||||
Action::make('download')
|
||||
->label('Download')
|
||||
->hiddenLabel()
|
||||
->tooltip('Download')
|
||||
->color('secondary')
|
||||
->icon('heroicon-o-archive-box-arrow-down')
|
||||
->authorize(fn ($record) => auth()->user()->can('view', $record))
|
||||
|
@ -5,17 +5,15 @@
|
||||
use App\Actions\PHP\InstallNewPHP;
|
||||
use App\Models\Server;
|
||||
use App\Models\Service;
|
||||
use App\Web\Components\Page;
|
||||
use App\Web\Pages\Servers\PHP\Widgets\PHPList;
|
||||
use App\Web\Traits\PageHasServer;
|
||||
use App\Web\Traits\PageHasWidgets;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Pages\Page;
|
||||
|
||||
class Index extends Page
|
||||
{
|
||||
use PageHasServer;
|
||||
use PageHasWidgets;
|
||||
|
||||
protected static ?string $slug = 'servers/{server}/php';
|
||||
|
||||
@ -23,11 +21,6 @@ class Index extends Page
|
||||
|
||||
protected static ?string $title = 'PHP';
|
||||
|
||||
protected function getExtraAttributes(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public Server $server;
|
||||
|
||||
public static function canAccess(): bool
|
||||
|
@ -28,6 +28,8 @@ class PHPList extends Widget
|
||||
{
|
||||
public Server $server;
|
||||
|
||||
protected $listeners = ['$refresh'];
|
||||
|
||||
protected function getTableQuery(): Builder
|
||||
{
|
||||
return Service::query()->where('type', 'php')->where('server_id', $this->server->id);
|
||||
@ -51,8 +53,9 @@ protected function getTableColumns(): array
|
||||
->color(fn (Service $service) => $service->is_default ? 'primary' : 'gray')
|
||||
->state(fn (Service $service) => $service->is_default ? 'Yes' : 'No')
|
||||
->sortable(),
|
||||
TextColumn::make('created_at_by_timezone')
|
||||
->label('Installed At'),
|
||||
TextColumn::make('created_at')
|
||||
->label('Installed At')
|
||||
->formatStateUsing(fn ($record) => $record->created_at_by_timezone),
|
||||
];
|
||||
}
|
||||
|
||||
@ -77,7 +80,7 @@ public function getTable(): Table
|
||||
private function installExtensionAction(): Action
|
||||
{
|
||||
return Action::make('install-extension')
|
||||
->authorize(fn (Service $php) => auth()->user()?->can('update', [$php, $this->server]))
|
||||
->authorize(fn (Service $php) => auth()->user()?->can('update', $php))
|
||||
->label('Install Extension')
|
||||
->modalHeading('Install PHP Extension')
|
||||
->modalWidth(MaxWidth::Large)
|
||||
@ -114,7 +117,7 @@ private function installExtensionAction(): Action
|
||||
private function defaultPHPCliAction(): Action
|
||||
{
|
||||
return Action::make('default-php-cli')
|
||||
->authorize(fn (Service $php) => auth()->user()?->can('update', [$php, $this->server]))
|
||||
->authorize(fn (Service $php) => auth()->user()?->can('update', $php))
|
||||
->label('Make Default CLI')
|
||||
->hidden(fn (Service $service) => $service->is_default)
|
||||
->action(function (Service $service) {
|
||||
@ -141,7 +144,7 @@ private function defaultPHPCliAction(): Action
|
||||
private function editPHPIniAction(string $type): Action
|
||||
{
|
||||
return Action::make('php-ini-'.$type)
|
||||
->authorize(fn (Service $php) => auth()->user()?->can('update', [$php, $this->server]))
|
||||
->authorize(fn (Service $php) => auth()->user()?->can('update', $php))
|
||||
->label('Update PHP ini ('.$type.')')
|
||||
->modalWidth(MaxWidth::TwoExtraLarge)
|
||||
->modalSubmitActionLabel('Save')
|
||||
@ -188,7 +191,7 @@ private function editPHPIniAction(string $type): Action
|
||||
private function restartFPMAction(): Action
|
||||
{
|
||||
return Action::make('restart-fpm')
|
||||
->authorize(fn (Service $php) => auth()->user()?->can('update', [$php, $this->server]))
|
||||
->authorize(fn (Service $php) => auth()->user()?->can('update', $php))
|
||||
->label('Restart PHP FPM')
|
||||
->action(function (Service $service) {
|
||||
try {
|
||||
@ -209,7 +212,7 @@ private function restartFPMAction(): Action
|
||||
private function uninstallAction(): Action
|
||||
{
|
||||
return Action::make('uninstall')
|
||||
->authorize(fn (Service $php) => auth()->user()?->can('delete', [$php, $this->server]))
|
||||
->authorize(fn (Service $php) => auth()->user()?->can('update', $php))
|
||||
->label('Uninstall')
|
||||
->color('danger')
|
||||
->requiresConfirmation()
|
||||
|
@ -4,19 +4,17 @@
|
||||
|
||||
use App\Actions\Server\RebootServer;
|
||||
use App\Models\Server;
|
||||
use App\Web\Components\Page;
|
||||
use App\Web\Pages\Servers\Widgets\ServerDetails;
|
||||
use App\Web\Pages\Servers\Widgets\UpdateServerInfo;
|
||||
use App\Web\Traits\PageHasServer;
|
||||
use App\Web\Traits\PageHasWidgets;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Pages\Page;
|
||||
|
||||
class Settings extends Page
|
||||
{
|
||||
use PageHasServer;
|
||||
use PageHasWidgets;
|
||||
|
||||
protected static ?string $slug = 'servers/{server}/settings';
|
||||
|
||||
|
@ -4,16 +4,14 @@
|
||||
|
||||
use App\Models\Server;
|
||||
use App\Models\Site;
|
||||
use App\Web\Components\Page;
|
||||
use App\Web\Pages\Servers\Sites\Widgets\SitesList;
|
||||
use App\Web\Traits\PageHasServer;
|
||||
use App\Web\Traits\PageHasWidgets;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Pages\Page;
|
||||
|
||||
class Index extends Page
|
||||
{
|
||||
use PageHasServer;
|
||||
use PageHasWidgets;
|
||||
|
||||
protected static ?string $slug = 'servers/{server}/sites';
|
||||
|
||||
|
@ -4,18 +4,16 @@
|
||||
|
||||
use App\Models\Server;
|
||||
use App\Models\ServerLog;
|
||||
use App\Web\Components\Page;
|
||||
use App\Web\Pages\Servers\Logs\Widgets\LogsList;
|
||||
use App\Web\Pages\Servers\Widgets\Installing;
|
||||
use App\Web\Pages\Servers\Widgets\ServerStats;
|
||||
use App\Web\Traits\PageHasServer;
|
||||
use App\Web\Traits\PageHasWidgets;
|
||||
use Filament\Pages\Page;
|
||||
use Livewire\Attributes\On;
|
||||
|
||||
class View extends Page
|
||||
{
|
||||
use PageHasServer;
|
||||
use PageHasWidgets;
|
||||
|
||||
protected static ?string $slug = 'servers/{server}';
|
||||
|
||||
|
@ -42,8 +42,9 @@ public function infolist(Infolist $infolist): Infolist
|
||||
->inlineLabel()
|
||||
->hintIcon('heroicon-o-information-circle')
|
||||
->hintIconTooltip('Server unique identifier to use in the API'),
|
||||
TextEntry::make('created_at_by_timezone')
|
||||
TextEntry::make('created_at')
|
||||
->label('Created At')
|
||||
->formatStateUsing(fn ($record) => $record->created_at_by_timezone)
|
||||
->inlineLabel(),
|
||||
TextEntry::make('last_updated_check')
|
||||
->label('Last Updated Check')
|
||||
|
@ -55,8 +55,14 @@ public function infolist(Infolist $infolist): Infolist
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->tooltip('Check Connection')
|
||||
->action(function (Server $record) {
|
||||
$previousStatus = $record->status;
|
||||
|
||||
$record = $record->checkConnection();
|
||||
|
||||
if ($previousStatus !== $record->status) {
|
||||
$this->redirect(url()->previous());
|
||||
}
|
||||
|
||||
$this->dispatch('$refresh');
|
||||
|
||||
Notification::make()
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Web\Pages\Servers\Widgets;
|
||||
|
||||
use App\Models\Server;
|
||||
use App\Web\Pages\Servers\Settings;
|
||||
use App\Web\Pages\Servers\View;
|
||||
use Filament\Tables\Actions\Action;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
@ -41,8 +42,9 @@ protected function getTableColumns(): array
|
||||
->color(fn (Server $server) => Server::$statusColors[$server->status])
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('created_at_by_timezone')
|
||||
TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->formatStateUsing(fn ($record) => $record->created_at_by_timezone)
|
||||
->searchable()
|
||||
->sortable(),
|
||||
];
|
||||
@ -57,7 +59,7 @@ public function getTable(): Table
|
||||
->label('Settings')
|
||||
->icon('heroicon-o-cog-6-tooth')
|
||||
->authorize(fn ($record) => auth()->user()->can('update', $record))
|
||||
->url(fn (Server $record) => '/'),
|
||||
->url(fn (Server $record) => Settings::getUrl(parameters: ['server' => $record])),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -2,16 +2,13 @@
|
||||
|
||||
namespace App\Web\Pages\Settings\Profile;
|
||||
|
||||
use App\Web\Components\Page;
|
||||
use App\Web\Pages\Settings\Profile\Widgets\ProfileInformation;
|
||||
use App\Web\Pages\Settings\Profile\Widgets\TwoFactor;
|
||||
use App\Web\Pages\Settings\Profile\Widgets\UpdatePassword;
|
||||
use App\Web\Traits\PageHasWidgets;
|
||||
use Filament\Pages\Page;
|
||||
|
||||
class Index extends Page
|
||||
{
|
||||
use PageHasWidgets;
|
||||
|
||||
protected static ?string $navigationGroup = 'Settings';
|
||||
|
||||
protected static ?string $slug = 'settings/profile';
|
||||
|
@ -4,17 +4,14 @@
|
||||
|
||||
use App\Actions\Projects\CreateProject;
|
||||
use App\Models\Project;
|
||||
use App\Web\Traits\PageHasWidgets;
|
||||
use App\Web\Components\Page;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Support\Enums\MaxWidth;
|
||||
|
||||
class Index extends Page
|
||||
{
|
||||
use PageHasWidgets;
|
||||
|
||||
protected static ?string $navigationGroup = 'Settings';
|
||||
|
||||
protected static ?string $slug = 'settings/projects';
|
||||
|
@ -4,20 +4,17 @@
|
||||
|
||||
use App\Actions\Projects\DeleteProject;
|
||||
use App\Models\Project;
|
||||
use App\Web\Components\Page;
|
||||
use App\Web\Pages\Settings\Projects\Widgets\AddUser;
|
||||
use App\Web\Pages\Settings\Projects\Widgets\ProjectUsersList;
|
||||
use App\Web\Pages\Settings\Projects\Widgets\UpdateProject;
|
||||
use App\Web\Traits\PageHasWidgets;
|
||||
use Exception;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Pages\Page;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
class Settings extends Page
|
||||
{
|
||||
use PageHasWidgets;
|
||||
|
||||
protected static ?string $slug = 'settings/projects/{project}';
|
||||
|
||||
protected static ?string $title = 'Project Settings';
|
||||
|
@ -25,8 +25,9 @@ protected function getTableColumns(): array
|
||||
TextColumn::make('name')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('created_at_by_timezone')
|
||||
TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->formatStateUsing(fn ($record) => $record->created_at_by_timezone)
|
||||
->searchable()
|
||||
->sortable(),
|
||||
];
|
||||
|
@ -3,15 +3,12 @@
|
||||
namespace App\Web\Pages\Settings\ServerProviders;
|
||||
|
||||
use App\Enums\ServerProvider;
|
||||
use App\Web\Traits\PageHasWidgets;
|
||||
use App\Web\Components\Page;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Support\Enums\MaxWidth;
|
||||
|
||||
class Index extends Page
|
||||
{
|
||||
use PageHasWidgets;
|
||||
|
||||
protected static ?string $navigationGroup = 'Settings';
|
||||
|
||||
protected static ?string $slug = 'settings/server-providers';
|
||||
|
@ -41,8 +41,9 @@ protected function getTableColumns(): array
|
||||
->formatStateUsing(function (ServerProvider $record) {
|
||||
return $record->project_id ? 'No' : 'Yes';
|
||||
}),
|
||||
TextColumn::make('created_at_by_timezone')
|
||||
TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->formatStateUsing(fn ($record) => $record->created_at_by_timezone)
|
||||
->searchable()
|
||||
->sortable(),
|
||||
];
|
||||
|
@ -4,18 +4,15 @@
|
||||
|
||||
use App\Actions\User\CreateUser;
|
||||
use App\Models\User;
|
||||
use App\Web\Traits\PageHasWidgets;
|
||||
use App\Web\Components\Page;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Support\Enums\MaxWidth;
|
||||
|
||||
class Index extends Page
|
||||
{
|
||||
use PageHasWidgets;
|
||||
|
||||
protected static ?string $navigationGroup = 'Settings';
|
||||
|
||||
protected static ?string $slug = 'users';
|
||||
|
@ -41,8 +41,9 @@ protected function getTableColumns(): array
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('timezone'),
|
||||
TextColumn::make('created_at_by_timezone')
|
||||
TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->formatStateUsing(fn ($record) => $record->created_at_by_timezone)
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('role'),
|
||||
|
@ -1,72 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Web\Traits;
|
||||
|
||||
use App\Models\Server;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
trait BelongsToServers
|
||||
{
|
||||
public static function getUrl(string $name = 'index', array $parameters = [], bool $isAbsolute = true, ?string $panel = null, ?Model $tenant = null): string
|
||||
{
|
||||
if (! isset($parameters['server'])) {
|
||||
$parameters['server'] = request()->route('server') ?? 0;
|
||||
}
|
||||
|
||||
return parent::getUrl($name, $parameters, $isAbsolute, $panel, $tenant);
|
||||
}
|
||||
|
||||
public static function getServerFromRoute(): Server
|
||||
{
|
||||
$server = request()->route('server');
|
||||
|
||||
if (! $server) {
|
||||
$server = Route::getRoutes()->match(Request::create(url()->previous()))->parameter('server');
|
||||
}
|
||||
|
||||
if (! $server instanceof Server) {
|
||||
$server = Server::query()->find($server);
|
||||
}
|
||||
|
||||
if (! $server) {
|
||||
$server = new Server;
|
||||
}
|
||||
|
||||
return $server;
|
||||
}
|
||||
|
||||
public static function canViewAny(): bool
|
||||
{
|
||||
return static::can('viewAny');
|
||||
|
||||
return auth()->user()->can('viewAny', [static::getModel(), static::getServerFromRoute()]);
|
||||
}
|
||||
|
||||
public static function canCreate(): bool
|
||||
{
|
||||
return auth()->user()->can('create', [static::getModel(), static::getServerFromRoute()]);
|
||||
}
|
||||
|
||||
public static function authorizeViewAny(): void
|
||||
{
|
||||
Gate::authorize('viewAny', [static::getModel(), static::getServerFromRoute()]);
|
||||
}
|
||||
|
||||
public static function authorizeCreate(): void
|
||||
{
|
||||
Gate::authorize('create', [static::getModel(), static::getServerFromRoute()]);
|
||||
}
|
||||
|
||||
public static function authorizeEdit(Model $record): void
|
||||
{
|
||||
Gate::authorize('update', [$record, static::getServerFromRoute()]);
|
||||
}
|
||||
|
||||
public static function authorizeView(Model $record): void
|
||||
{
|
||||
Gate::authorize('view', [$record, static::getServerFromRoute()]);
|
||||
}
|
||||
}
|
38
app/Web/Traits/HasWidgets.php
Normal file
38
app/Web/Traits/HasWidgets.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Web\Traits;
|
||||
|
||||
use Illuminate\View\ComponentAttributeBag;
|
||||
|
||||
trait HasWidgets
|
||||
{
|
||||
protected ?string $live = '5s';
|
||||
|
||||
protected array $extraAttributes = [];
|
||||
|
||||
protected function getExtraAttributes(): array
|
||||
{
|
||||
$attributes = $this->extraAttributes;
|
||||
|
||||
if ($this->getLive()) {
|
||||
$attributes['wire:poll.'.$this->getLive()] = '$dispatch(\'$refresh\')';
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
public function getExtraAttributesBag(): ComponentAttributeBag
|
||||
{
|
||||
return new ComponentAttributeBag($this->getExtraAttributes());
|
||||
}
|
||||
|
||||
public function getLive(): ?string
|
||||
{
|
||||
return $this->live;
|
||||
}
|
||||
|
||||
public function getWidgets(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Web\Traits;
|
||||
|
||||
trait PageHasCluster
|
||||
{
|
||||
// public function getMaxContentWidth(): ?string
|
||||
// {
|
||||
// return 'full';
|
||||
// }
|
||||
|
||||
public function getSubNavigation(): array
|
||||
{
|
||||
if (filled($cluster = static::getCluster())) {
|
||||
return $this->generateNavigationItems($cluster::getClusteredComponents());
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
namespace App\Web\Traits;
|
||||
|
||||
use App\Models\Server;
|
||||
use App\Web\Pages\Servers\Databases\Index as DatabasesIndex;
|
||||
use App\Web\Pages\Servers\Logs\Index as LogsIndex;
|
||||
use App\Web\Pages\Servers\PHP\Index as PHPIndex;
|
||||
use App\Web\Pages\Servers\Settings as ServerSettings;
|
||||
@ -26,35 +27,42 @@ public function getSubNavigation(): array
|
||||
$items = [];
|
||||
|
||||
if (ServerView::canAccess()) {
|
||||
$items[] = NavigationItem::make('Overview')
|
||||
$items[] = NavigationItem::make(ServerView::getNavigationLabel())
|
||||
->icon('heroicon-o-chart-pie')
|
||||
->isActiveWhen(fn () => request()->routeIs(ServerView::getRouteName()))
|
||||
->url(ServerView::getUrl(parameters: ['server' => $this->server]));
|
||||
}
|
||||
|
||||
if (SitesIndex::canAccess()) {
|
||||
$items[] = NavigationItem::make('Sites')
|
||||
$items[] = NavigationItem::make(SitesIndex::getNavigationLabel())
|
||||
->icon('heroicon-o-globe-alt')
|
||||
->isActiveWhen(fn () => request()->routeIs(SitesIndex::getRouteName().'*'))
|
||||
->url(SitesIndex::getUrl(parameters: ['server' => $this->server]));
|
||||
}
|
||||
|
||||
if (DatabasesIndex::canAccess()) {
|
||||
$items[] = NavigationItem::make(DatabasesIndex::getNavigationLabel())
|
||||
->icon('heroicon-o-circle-stack')
|
||||
->isActiveWhen(fn () => request()->routeIs(DatabasesIndex::getRouteName().'*'))
|
||||
->url(DatabasesIndex::getUrl(parameters: ['server' => $this->server]));
|
||||
}
|
||||
|
||||
if (PHPIndex::canAccess()) {
|
||||
$items[] = NavigationItem::make('PHP')
|
||||
$items[] = NavigationItem::make(PHPIndex::getNavigationLabel())
|
||||
->icon('heroicon-o-code-bracket')
|
||||
->isActiveWhen(fn () => request()->routeIs(PHPIndex::getRouteName().'*'))
|
||||
->url(PHPIndex::getUrl(parameters: ['server' => $this->server]));
|
||||
}
|
||||
|
||||
if (LogsIndex::canAccess()) {
|
||||
$items[] = NavigationItem::make('Logs')
|
||||
$items[] = NavigationItem::make(LogsIndex::getNavigationLabel())
|
||||
->icon('heroicon-o-square-3-stack-3d')
|
||||
->isActiveWhen(fn () => request()->routeIs(LogsIndex::getRouteName().'*'))
|
||||
->url(LogsIndex::getUrl(parameters: ['server' => $this->server]));
|
||||
}
|
||||
|
||||
if (ServerSettings::canAccess()) {
|
||||
$items[] = NavigationItem::make('Settings')
|
||||
$items[] = NavigationItem::make(ServerSettings::getNavigationLabel())
|
||||
->icon('heroicon-o-cog-6-tooth')
|
||||
->isActiveWhen(fn () => request()->routeIs(ServerSettings::getRouteName().'*'))
|
||||
->url(ServerSettings::getUrl(parameters: ['server' => $this->server]));
|
||||
|
@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Web\Traits;
|
||||
|
||||
use Illuminate\View\ComponentAttributeBag;
|
||||
|
||||
trait PageHasWidgets
|
||||
{
|
||||
protected array $extraAttributes = [
|
||||
'wire:poll.5s' => '$dispatch(\'$refresh\')',
|
||||
];
|
||||
|
||||
protected function getExtraAttributes(): array
|
||||
{
|
||||
return $this->extraAttributes;
|
||||
}
|
||||
|
||||
public function getView(): string
|
||||
{
|
||||
return 'web.components.page';
|
||||
}
|
||||
|
||||
public function getExtraAttributesBag(): ComponentAttributeBag
|
||||
{
|
||||
return new ComponentAttributeBag($this->getExtraAttributes());
|
||||
}
|
||||
|
||||
abstract public function getWidgets(): array;
|
||||
}
|
Reference in New Issue
Block a user