This commit is contained in:
Vehikl 2025-01-23 16:37:00 -05:00
parent 791f04c5d9
commit 63cf4bd1a8
6 changed files with 88 additions and 7 deletions

View File

@ -10,8 +10,8 @@ use Filament\Support\Concerns\HasHeading;
class CustomModal extends Field class CustomModal extends Field
{ {
use HasActions; use HasActions;
use HasHeading;
use HasDescription; use HasDescription;
use HasHeading;
protected string $view = 'livewire.custom-modal'; protected string $view = 'livewire.custom-modal';
} }

View File

@ -2,7 +2,8 @@
namespace App\Features; namespace App\Features;
use Filament\Actions\Action; use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Components\Field;
abstract class Feature abstract class Feature
{ {
@ -12,7 +13,8 @@ abstract class Feature
/** eula */ /** eula */
abstract public function featureName(): string; 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 public function matchesListeners(string $line): bool
{ {

View File

@ -25,6 +25,14 @@ class JavaVersion extends Feature
return 'java_version'; 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 public function action(): Action
{ {
return Action::make('eula') return Action::make('eula')

View File

@ -3,7 +3,8 @@
namespace App\Features; namespace App\Features;
use App\Repositories\Daemon\DaemonFileRepository; 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\Forms\Components\Placeholder;
use Filament\Notifications\Notification; use Filament\Notifications\Notification;
@ -21,6 +22,29 @@ class MinecraftEula extends Feature
return 'eula'; 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 public function action(): Action
{ {
return Action::make($this->featureName()) return Action::make($this->featureName())

View File

@ -9,14 +9,23 @@ use App\Models\Server;
use App\Models\User; use App\Models\User;
use App\Services\Nodes\NodeJWTService; use App\Services\Nodes\NodeJWTService;
use App\Services\Servers\GetUserPermissionsService; 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 Filament\Widgets\Widget;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Livewire\Attributes\On; use Livewire\Attributes\On;
use App\Features; use App\Features;
use App\Features\CustomModal; 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 static string $view = 'filament.components.server-console';
protected int|string|array $columnSpan = 'full'; protected int|string|array $columnSpan = 'full';
@ -41,6 +50,39 @@ class ServerConsole extends Widget
->registerActions([/* if neccessary */]); ->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 protected function getToken(): string
{ {
if (!$this->user || !$this->server || $this->user->cannot(Permission::ACTION_WEBSOCKET_CONNECT, $this->server)) { 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)) { if ($feature->matchesListeners($line)) {
logger()->info('Feature listens for this', compact(['feature', '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');
} }
} }
} }

View File

@ -195,6 +195,10 @@
</script> </script>
@endscript @endscript
{{ $this->modal()->render() }}
<x-filament::modal id="edit-user" :close-by-clicking-away="false">
{{ $this->getUserModal() }}
</x-filament::modal>
</x-filament::widget> </x-filament::widget>