From 63cf4bd1a8f64db1a56158c61f792f012b5d1e24 Mon Sep 17 00:00:00 2001 From: Vehikl Date: Thu, 23 Jan 2025 16:37:00 -0500 Subject: [PATCH] wip --- app/Features/CustomModal.php | 2 +- app/Features/Feature.php | 6 ++- app/Features/JavaVersion.php | 8 ++++ app/Features/MinecraftEula.php | 26 +++++++++- app/Filament/Server/Widgets/ServerConsole.php | 47 ++++++++++++++++++- .../components/server-console.blade.php | 6 ++- 6 files changed, 88 insertions(+), 7 deletions(-) diff --git a/app/Features/CustomModal.php b/app/Features/CustomModal.php index 9e517fb98..f1fb33665 100644 --- a/app/Features/CustomModal.php +++ b/app/Features/CustomModal.php @@ -10,8 +10,8 @@ use Filament\Support\Concerns\HasHeading; class CustomModal extends Field { use HasActions; - use HasHeading; use HasDescription; + use HasHeading; protected string $view = 'livewire.custom-modal'; } diff --git a/app/Features/Feature.php b/app/Features/Feature.php index bfc8b5094..31e6765e8 100644 --- a/app/Features/Feature.php +++ b/app/Features/Feature.php @@ -2,7 +2,8 @@ namespace App\Features; -use Filament\Actions\Action; +use Filament\Forms\Components\Actions\Action; +use Filament\Forms\Components\Field; abstract class Feature { @@ -12,7 +13,8 @@ abstract class Feature /** eula */ abstract public function featureName(): string; - abstract public function action(): Action; + // abstract public function action(): Action; + abstract public function modal(): Field; public function matchesListeners(string $line): bool { diff --git a/app/Features/JavaVersion.php b/app/Features/JavaVersion.php index 734c9fd44..48265a9bd 100644 --- a/app/Features/JavaVersion.php +++ b/app/Features/JavaVersion.php @@ -25,6 +25,14 @@ class JavaVersion extends Feature return 'java_version'; } + public function modal(): \Filament\Forms\Components\Field + { + return CustomModal::make('modal-java-version') + ->heading('Java Version') + ->description('bla bla') + ->registerActions([/* if neccessary */]); + } + public function action(): Action { return Action::make('eula') diff --git a/app/Features/MinecraftEula.php b/app/Features/MinecraftEula.php index 20b72d4d6..bb59405d3 100644 --- a/app/Features/MinecraftEula.php +++ b/app/Features/MinecraftEula.php @@ -3,7 +3,8 @@ namespace App\Features; use App\Repositories\Daemon\DaemonFileRepository; -use Filament\Actions\Action; +use Filament\Forms\Components\Actions\Action; +use Filament\Forms\Components\Field; use Filament\Forms\Components\Placeholder; use Filament\Notifications\Notification; @@ -21,6 +22,29 @@ class MinecraftEula extends Feature return 'eula'; } + public function modal(): Field + { + return CustomModal::make('modal-eula') + ->heading('Minecraft EULA') + ->description('By pressing "I Accept" below you are indicating your agreement to the Minecraft EULA') + ->registerActions([ + + Action::make($this->featureName()) + ->action(function (DaemonFileRepository $fileRepository) { + try { + $fileRepository->putContent('eula.txt', 'eula=true'); + } catch (\Exception $e) { + Notification::make() + ->title('Error') + ->body($e->getMessage()) + ->danger() + ->send(); + } + } + ), + ]); + } + public function action(): Action { return Action::make($this->featureName()) diff --git a/app/Filament/Server/Widgets/ServerConsole.php b/app/Filament/Server/Widgets/ServerConsole.php index f28eed5eb..454674022 100644 --- a/app/Filament/Server/Widgets/ServerConsole.php +++ b/app/Filament/Server/Widgets/ServerConsole.php @@ -9,14 +9,23 @@ use App\Models\Server; use App\Models\User; use App\Services\Nodes\NodeJWTService; use App\Services\Servers\GetUserPermissionsService; +use Filament\Forms\Components\Actions; +use Filament\Forms\Components\Placeholder; +use Filament\Forms\Concerns\InteractsWithForms; +use Filament\Forms\Contracts\HasForms; +use Filament\Forms\Form; +use Filament\Forms\Get; use Filament\Widgets\Widget; use Illuminate\Support\Arr; use Livewire\Attributes\On; use App\Features; use App\Features\CustomModal; +use Filament\Forms\Components\TextInput; -class ServerConsole extends Widget +class ServerConsole extends Widget implements HasForms { + use InteractsWithForms; + protected static string $view = 'filament.components.server-console'; protected int|string|array $columnSpan = 'full'; @@ -41,6 +50,39 @@ class ServerConsole extends Widget ->registerActions([/* if neccessary */]); } + protected function getUserModal(): Form + { + return $this->makeForm() + ->schema([ + Placeholder::make('see me'), + TextInput::make('name'), + Actions::make([ + Actions\Action::make('closeUserModal') + ->label('Close') + ->color('secondary') + ->extraAttributes([ + 'x-on:click' => 'isOpen = false', // close modal [FASTER] + ]), + Actions\Action::make('saveUserModal') + ->label('Save') + ->color('primary') + ->action(function (Get $get) { + logger($get('name')); + }), + ])->fullWidth(), + ]); + } + + public function getModals(): array + { + $modals = []; + foreach ($this->getActiveFeatures() as $feature) { + $modals[] = $feature->modal(); + } + + return $modals; + } + protected function getToken(): string { if (!$this->user || !$this->server || $this->user->cannot(Permission::ACTION_WEBSOCKET_CONNECT, $this->server)) { @@ -131,7 +173,8 @@ class ServerConsole extends Widget if ($feature->matchesListeners($line)) { logger()->info('Feature listens for this', compact(['feature', 'line'])); - $this->dispatch('open-modal', id: "modal-{$feature->featureName()}"); + // $this->dispatch('open-modal', id: "modal-{$feature->featureName()}"); + $this->dispatch('open-modal', id: 'edit-user'); } } } diff --git a/resources/views/filament/components/server-console.blade.php b/resources/views/filament/components/server-console.blade.php index 176c9acc4..f677076bd 100644 --- a/resources/views/filament/components/server-console.blade.php +++ b/resources/views/filament/components/server-console.blade.php @@ -195,6 +195,10 @@ @endscript - {{ $this->modal()->render() }} + + + {{ $this->getUserModal() }} + +