From 791f04c5d9c903a333d8bff5d538db40df888b61 Mon Sep 17 00:00:00 2001 From: Vehikl Date: Thu, 16 Jan 2025 17:01:41 -0500 Subject: [PATCH] Work In Progress --- app/Features/CustomModal.php | 17 +++++++++++++ app/Features/Feature.php | 6 ++--- app/Features/JavaVersion.php | 6 ++--- app/Features/MinecraftEula.php | 8 +++--- app/Filament/Server/Widgets/ServerConsole.php | 25 ++++++++++++++----- package.json | 3 ++- .../components/server-console.blade.php | 6 ++++- .../views/livewire/custom-modal.blade.php | 17 +++++++++++++ 8 files changed, 70 insertions(+), 18 deletions(-) create mode 100644 app/Features/CustomModal.php create mode 100644 resources/views/livewire/custom-modal.blade.php diff --git a/app/Features/CustomModal.php b/app/Features/CustomModal.php new file mode 100644 index 000000000..9e517fb98 --- /dev/null +++ b/app/Features/CustomModal.php @@ -0,0 +1,17 @@ +form([ diff --git a/app/Features/MinecraftEula.php b/app/Features/MinecraftEula.php index a3f681a54..20b72d4d6 100644 --- a/app/Features/MinecraftEula.php +++ b/app/Features/MinecraftEula.php @@ -9,21 +9,21 @@ use Filament\Notifications\Notification; class MinecraftEula extends Feature { - public static function listeners(): array + public function listeners(): array { return [ 'you need to agree to the eula in order to run the server', ]; } - public static function featureName(): string + public function featureName(): string { return 'eula'; } - public static function action(): Action + public function action(): Action { - return Action::make('eula') + return Action::make($this->featureName()) ->form([ Placeholder::make('eula') ->label('By pressing I Accept below you are indicating your agreement to the Minecraft® EULA.'), diff --git a/app/Filament/Server/Widgets/ServerConsole.php b/app/Filament/Server/Widgets/ServerConsole.php index 853d806ed..f28eed5eb 100644 --- a/app/Filament/Server/Widgets/ServerConsole.php +++ b/app/Filament/Server/Widgets/ServerConsole.php @@ -3,6 +3,7 @@ namespace App\Filament\Server\Widgets; use App\Exceptions\Http\HttpForbiddenException; +use App\Features\Feature; use App\Models\Permission; use App\Models\Server; use App\Models\User; @@ -10,10 +11,9 @@ use App\Services\Nodes\NodeJWTService; use App\Services\Servers\GetUserPermissionsService; use Filament\Widgets\Widget; use Illuminate\Support\Arr; -use Illuminate\Support\Collection; -use Illuminate\Support\Facades\Log; use Livewire\Attributes\On; use App\Features; +use App\Features\CustomModal; class ServerConsole extends Widget { @@ -33,6 +33,14 @@ class ServerConsole extends Widget public string $input = ''; + public function modal(): CustomModal + { + return CustomModal::make('modal-eula') + ->heading('Info!') + ->description('Description') + ->registerActions([/* if neccessary */]); + } + protected function getToken(): string { if (!$this->user || !$this->server || $this->user->cannot(Permission::ACTION_WEBSOCKET_CONNECT, $this->server)) { @@ -108,18 +116,23 @@ class ServerConsole extends Widget } } + /** + * @return Feature[] + */ public function getActiveFeatures(): array { return [new Features\MinecraftEula(), new Features\JavaVersion()]; } #[On('line-to-check')] - public function lineToCheck(string $line) + public function lineToCheck(string $line): void { foreach ($this->getActiveFeatures() as $feature) { - if ($feature->matchesListeners($line)) { - Log::info('Feature listens for this', compact(['feature', 'line'])); - } + if ($feature->matchesListeners($line)) { + logger()->info('Feature listens for this', compact(['feature', 'line'])); + + $this->dispatch('open-modal', id: "modal-{$feature->featureName()}"); + } } } } diff --git a/package.json b/package.json index c08b6d02e..cd1204ed0 100644 --- a/package.json +++ b/package.json @@ -154,5 +154,6 @@ "displayName": true, "fileName": true } - } + }, + "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" } diff --git a/resources/views/filament/components/server-console.blade.php b/resources/views/filament/components/server-console.blade.php index 1b6b65af3..176c9acc4 100644 --- a/resources/views/filament/components/server-console.blade.php +++ b/resources/views/filament/components/server-console.blade.php @@ -1,3 +1,4 @@ +@php use App\Features\CustomModal; @endphp @assets @@ -105,7 +106,7 @@ } const checkListeners = (line) => { - $dispatch('line-to-check', { line }) + $dispatch('line-to-check', { line }); } const handleTransferStatus = (status) => @@ -193,4 +194,7 @@ }); @endscript + + {{ $this->modal()->render() }} + diff --git a/resources/views/livewire/custom-modal.blade.php b/resources/views/livewire/custom-modal.blade.php new file mode 100644 index 000000000..04d437827 --- /dev/null +++ b/resources/views/livewire/custom-modal.blade.php @@ -0,0 +1,17 @@ + +
+ {{ $getHeading() }} +
+ +
+ {{ $getDescription() }} +
+ +
+ @if ($actions = $getActions()) + + @endif +
+