Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pelican-vehikl committed Jan 23, 2025
1 parent 791f04c commit 63cf4bd
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/Features/CustomModal.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
class CustomModal extends Field
{
use HasActions;
use HasHeading;
use HasDescription;
use HasHeading;

protected string $view = 'livewire.custom-modal';
}
6 changes: 4 additions & 2 deletions app/Features/Feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -12,7 +13,8 @@ abstract public function listeners(): array;
/** 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
{
Expand Down
8 changes: 8 additions & 0 deletions app/Features/JavaVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ public function featureName(): string
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')
Expand Down
26 changes: 25 additions & 1 deletion app/Features/MinecraftEula.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -21,6 +22,29 @@ public function featureName(): string
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())
Expand Down
47 changes: 45 additions & 2 deletions app/Filament/Server/Widgets/ServerConsole.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,23 @@
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';
Expand All @@ -41,6 +50,39 @@ public function modal(): CustomModal
->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)) {
Expand Down Expand Up @@ -131,7 +173,8 @@ public function lineToCheck(string $line): void
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');
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion resources/views/filament/components/server-console.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ class="w-full focus:outline-none focus:ring-0 border-none"
</script>
@endscript

{{ $this->modal()->render() }}

<x-filament::modal id="edit-user" :close-by-clicking-away="false">
{{ $this->getUserModal() }}
</x-filament::modal>


</x-filament::widget>

0 comments on commit 63cf4bd

Please sign in to comment.