This commit is contained in:
Vehikl 2025-01-23 17:05:11 -05:00
parent 63cf4bd1a8
commit ad494b68b6
5 changed files with 80 additions and 14 deletions

View File

@ -2,11 +2,16 @@
namespace App\Features;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Components\Field;
use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Actions\Contracts\HasActions;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
abstract class Feature
abstract class Feature implements HasActions, HasForms
{
use InteractsWithActions, InteractsWithForms;
/** you need to agree to the eula in order to run the server */
abstract public function listeners(): array;
@ -14,7 +19,7 @@ abstract class Feature
abstract public function featureName(): string;
// abstract public function action(): Action;
abstract public function modal(): Field;
abstract public function modal(): Form;
public function matchesListeners(string $line): bool
{

View File

@ -4,7 +4,11 @@ namespace App\Features;
use App\Repositories\Daemon\DaemonFileRepository;
use Filament\Actions\Action;
use Filament\Forms\Components\Actions;
use Filament\Forms\Components\Placeholder;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Notifications\Notification;
class JavaVersion extends Feature
@ -25,12 +29,27 @@ class JavaVersion extends Feature
return 'java_version';
}
public function modal(): \Filament\Forms\Components\Field
public function modal(): Form
{
return CustomModal::make('modal-java-version')
->heading('Java Version')
->description('bla bla')
->registerActions([/* if neccessary */]);
return $this->makeForm()
->schema([
Placeholder::make('see me bitches'),
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 action(): Action

View File

@ -3,9 +3,13 @@
namespace App\Features;
use App\Repositories\Daemon\DaemonFileRepository;
use Filament\Forms\Components\Actions;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Components\Field;
use Filament\Forms\Components\Placeholder;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Notifications\Notification;
class MinecraftEula extends Feature
@ -22,7 +26,43 @@ class MinecraftEula extends Feature
return 'eula';
}
public function modal(): Field
public function modal(): Form
{
return $this->makeForm()
->schema([
Placeholder::make('By pressing "I Accept" below you are indicating your agreement to the Minecraft EULA'),
Actions::make([
Actions\Action::make('closeModal')
->label('Close')
->color('secondary')
->extraAttributes([
'x-on:click' => 'isOpen = false', // close modal [FASTER]
]),
Actions\Action::make('acceptEula')
->label('Save')
->color('primary')
->extraAttributes([
// 'x-on:click' => '$dispatch("minecraft-eula-accept")', // close modal [FASTER]
])
->action(function (DaemonFileRepository $fileRepository) {
try {
dd('success');
$fileRepository->putContent('eula.txt', 'eula=true');
} catch (\Exception $e) {
dd($e);
Notification::make()
->title('Error')
->body($e->getMessage())
->danger()
->send();
}
}),
])
->fullWidth()->label('Minecraft EULA'),
]);
}
public function field(): Field
{
return CustomModal::make('modal-eula')
->heading('Minecraft EULA')

View File

@ -173,8 +173,8 @@ class ServerConsole extends Widget implements HasForms
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: 'edit-user');
$this->dispatch('open-modal', id: "modal-{$feature->featureName()}");
// $this->dispatch('open-modal', id: 'edit-user');
}
}
}

View File

@ -196,9 +196,11 @@
@endscript
<x-filament::modal id="edit-user" :close-by-clicking-away="false">
{{ $this->getUserModal() }}
@foreach ($this->getActiveFeatures() as $feature)
<x-filament::modal id="modal-{{ $feature->featureName() }}" :close-by-clicking-away="false">
{{ $feature->modal() }}
</x-filament::modal>
@endforeach
</x-filament::widget>