diff --git a/app/Filament/Pages/Tools/ListOoklaServers.php b/app/Filament/Pages/Tools/ListOoklaServers.php new file mode 100644 index 000000000..e59cda37c --- /dev/null +++ b/app/Filament/Pages/Tools/ListOoklaServers.php @@ -0,0 +1,115 @@ +fetchServers(); + } + + public function fetchServers(): void + { + $this->isLoading = true; + + try { + $servers = GetOoklaSpeedtestServers::fetch(); + + $this->servers = json_encode($servers, JSON_PRETTY_PRINT); + + $this->form->fill([ + 'servers' => $this->servers, + ]); + } catch (\Exception $e) { + Notification::make() + ->title('Error fetching servers') + ->body($e->getMessage()) + ->danger() + ->send(); + + $this->servers = ''; + $this->form->fill([ + 'servers' => '', + ]); + } finally { + $this->isLoading = false; + } + } + + public function form(Form $form): Form + { + return $form + ->schema([ + Textarea::make('servers') + ->label(false) + ->rows(20) + ->columnSpanFull() + ->extraAttributes(['class' => 'font-mono']) + ->disabled(), + ]); + } + + protected function getHeaderActions(): array + { + return [ + Action::make('refreshServers') + ->label('Refresh') + ->icon('heroicon-o-arrow-path') + ->action(function () { + $this->fetchServers(); + + Notification::make() + ->title('Servers refreshed successfully') + ->success() + ->send(); + }), + + Action::make('copyServers') + ->label('Copy to Clipboard') + ->icon('heroicon-o-clipboard') + ->disabled(fn () => blank($this->servers)) + ->requiresConfirmation(false) + ->action(function () { + $this->js('navigator.clipboard.writeText('.json_encode($this->servers).')'); + + Notification::make() + ->title('Copied to clipboard') + ->success() + ->send(); + }), + ]; + } +} diff --git a/resources/views/filament/pages/tools/list-ookla-servers.blade.php b/resources/views/filament/pages/tools/list-ookla-servers.blade.php new file mode 100644 index 000000000..525d2fc40 --- /dev/null +++ b/resources/views/filament/pages/tools/list-ookla-servers.blade.php @@ -0,0 +1,14 @@ + + @if ($isLoading) +
+
+ +

Loading Ookla servers...

+
+
+ @else + + {{ $this->form }} + + @endif +