diff --git a/app/Filament/Pages/Dashboard.php b/app/Filament/Pages/Dashboard.php index c6c161b85..d1387e324 100644 --- a/app/Filament/Pages/Dashboard.php +++ b/app/Filament/Pages/Dashboard.php @@ -2,8 +2,6 @@ namespace App\Filament\Pages; -use App\Actions\GetOoklaSpeedtestServers; -use App\Actions\Ookla\StartSpeedtest; use App\Filament\Widgets\RecentDownloadChartWidget; use App\Filament\Widgets\RecentDownloadLatencyChartWidget; use App\Filament\Widgets\RecentJitterChartWidget; @@ -11,14 +9,9 @@ use App\Filament\Widgets\RecentUploadChartWidget; use App\Filament\Widgets\RecentUploadLatencyChartWidget; use App\Filament\Widgets\StatsOverviewWidget; -use App\Helpers\Ookla; use Carbon\Carbon; use Cron\CronExpression; -use Filament\Actions\Action; -use Filament\Forms; -use Filament\Notifications\Notification; use Filament\Pages\Dashboard as BasePage; -use Filament\Support\Enums\IconPosition; class Dashboard extends BasePage { @@ -41,55 +34,6 @@ public function getSubheading(): ?string return 'Next speedtest at: '.$nextRunDate; } - protected function getHeaderActions(): array - { - return [ - Action::make('home') - ->label('Public Dashboard') - ->icon('heroicon-o-chart-bar') - ->iconPosition(IconPosition::Before) - ->color('gray') - ->hidden(fn (): bool => ! config('speedtest.public_dashboard')) - ->url(shouldOpenInNewTab: true, url: '/'), - - Action::make('speedtest') - ->form([ - Forms\Components\Select::make('server_id') - ->label('Select Server') - ->helperText('Leave empty to run the speedtest without specifying a server.') - ->options(function (): array { - return array_filter([ - 'Manual servers' => Ookla::getConfigServers(), - 'Closest servers' => GetOoklaSpeedtestServers::run(), - ]); - }) - ->searchable(), - ]) - ->action(function (array $data) { - $serverId = $data['server_id'] ?? null; - - StartSpeedtest::run( - scheduled: false, - serverId: $serverId, - ); - - Notification::make() - ->title('Speedtest started') - ->success() - ->send(); - }) - ->modalHeading('Run Speedtest') - ->modalWidth('lg') - ->modalSubmitActionLabel('Start') - ->button() - ->color('primary') - ->label('Run Speedtest') - ->icon('heroicon-o-rocket-launch') - ->iconPosition(IconPosition::Before) - ->hidden(! auth()->user()->is_admin), - ]; - } - protected function getHeaderWidgets(): array { return [ diff --git a/app/Livewire/Topbar/RunSpeedtestAction.php b/app/Livewire/Topbar/RunSpeedtestAction.php new file mode 100644 index 000000000..fc58a0a5b --- /dev/null +++ b/app/Livewire/Topbar/RunSpeedtestAction.php @@ -0,0 +1,82 @@ +label('Dashboard') + ->icon('heroicon-o-chart-bar') + ->iconPosition(IconPosition::Before) + ->color('gray') + ->hidden(fn (): bool => ! config('speedtest.public_dashboard')) + ->url(shouldOpenInNewTab: true, url: '/') + ->extraAttributes([ + 'id' => 'dashboardAction', + ]); + } + + public function speedtestAction(): Action + { + return Action::make('speedtest') + ->form([ + Select::make('server_id') + ->label('Select Server') + ->helperText('Leave empty to run the speedtest without specifying a server.') + ->options(function (): array { + return array_filter([ + 'Manual servers' => Ookla::getConfigServers(), + 'Closest servers' => GetOoklaSpeedtestServers::run(), + ]); + }) + ->searchable(), + ]) + ->action(function (array $data) { + $serverId = $data['server_id'] ?? null; + + StartSpeedtest::run( + scheduled: false, + serverId: $serverId, + ); + + Notification::make() + ->title('Speedtest started') + ->success() + ->send(); + }) + ->modalHeading('Run Speedtest') + ->modalWidth('lg') + ->modalSubmitActionLabel('Start') + ->button() + ->color('primary') + ->label('Speedtest') + ->icon('heroicon-o-rocket-launch') + ->iconPosition(IconPosition::Before) + ->hidden(! auth()->user()->is_admin) + ->extraAttributes([ + 'id' => 'speedtestAction', + ]); + } + + public function render() + { + return view('livewire.topbar.run-speedtest-action'); + } +} diff --git a/app/Providers/FilamentServiceProvider.php b/app/Providers/FilamentServiceProvider.php new file mode 100644 index 000000000..96274b131 --- /dev/null +++ b/app/Providers/FilamentServiceProvider.php @@ -0,0 +1,36 @@ + Blade::render("@livewire('topbar.run-speedtest-action')"), + ); + } +} diff --git a/bootstrap/providers.php b/bootstrap/providers.php index 22744d111..7600f34b1 100644 --- a/bootstrap/providers.php +++ b/bootstrap/providers.php @@ -2,5 +2,6 @@ return [ App\Providers\AppServiceProvider::class, + App\Providers\FilamentServiceProvider::class, App\Providers\Filament\AdminPanelProvider::class, ]; diff --git a/public/css/app/panel.css b/public/css/app/panel.css new file mode 100644 index 000000000..42da397e6 --- /dev/null +++ b/public/css/app/panel.css @@ -0,0 +1,11 @@ +.fi-topbar #dashboardAction .fi-btn-label, +.fi-topbar #speedtestAction .fi-btn-label { + display: none; +} + +@media (min-width: 768px) { + .fi-topbar #dashboardAction .fi-btn-label, + .fi-topbar #speedtestAction .fi-btn-label { + display: block; + } +} diff --git a/resources/css/panel.css b/resources/css/panel.css new file mode 100644 index 000000000..42da397e6 --- /dev/null +++ b/resources/css/panel.css @@ -0,0 +1,11 @@ +.fi-topbar #dashboardAction .fi-btn-label, +.fi-topbar #speedtestAction .fi-btn-label { + display: none; +} + +@media (min-width: 768px) { + .fi-topbar #dashboardAction .fi-btn-label, + .fi-topbar #speedtestAction .fi-btn-label { + display: block; + } +} diff --git a/resources/views/livewire/topbar/run-speedtest-action.blade.php b/resources/views/livewire/topbar/run-speedtest-action.blade.php new file mode 100644 index 000000000..3c88447e0 --- /dev/null +++ b/resources/views/livewire/topbar/run-speedtest-action.blade.php @@ -0,0 +1,9 @@ +