forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunSpeedtestAction.php
More file actions
82 lines (74 loc) · 2.65 KB
/
RunSpeedtestAction.php
File metadata and controls
82 lines (74 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
namespace App\Livewire\Topbar;
use App\Actions\GetOoklaSpeedtestServers;
use App\Actions\Ookla\StartSpeedtest;
use App\Helpers\Ookla;
use Filament\Actions\Action;
use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Actions\Contracts\HasActions;
use Filament\Forms\Components\Select;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Notifications\Notification;
use Filament\Support\Enums\IconPosition;
use Livewire\Component;
class RunSpeedtestAction extends Component implements HasActions, HasForms
{
use InteractsWithActions, InteractsWithForms;
public function dashboardAction(): Action
{
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: '/')
->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');
}
}