forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDashboard.php
More file actions
94 lines (74 loc) · 2.29 KB
/
Dashboard.php
File metadata and controls
94 lines (74 loc) · 2.29 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
83
84
85
86
87
88
89
90
91
92
93
94
<?php
namespace App\Filament\Pages;
use App\Filament\Widgets\RecentJitterChart;
use App\Filament\Widgets\RecentPingChart;
use App\Filament\Widgets\RecentSpeedChart;
use App\Filament\Widgets\StatsOverview;
use App\Jobs\ExecSpeedtest;
use App\Models\Result;
use App\Settings\GeneralSettings;
use Filament\Notifications\Notification;
use Filament\Pages\Actions\Action;
use Filament\Pages\Dashboard as BasePage;
use Illuminate\Contracts\View\View;
class Dashboard extends BasePage
{
public string $lastResult = 'never';
public int $resultsCount;
protected static string $view = 'filament.pages.dashboard';
public function render(): View
{
$this->resultsCount = Result::count();
if ($this->resultsCount) {
$result = Result::latest()
->first();
$settings = new GeneralSettings();
$this->lastResult = $result->created_at
->timezone($settings->timezone)
->format($settings->time_format);
}
return view(static::$view, $this->getViewData())
->layout(static::$layout, $this->getLayoutData());
}
protected function getActions(): array
{
return [
Action::make('speedtest')
->label('Queue Speedtest')
->action('queueSpeedtest'),
];
}
public function getHeaderWidgets(): array
{
return [
StatsOverview::class,
];
}
public function getFooterWidgets(): array
{
if (! $this->resultsCount) {
return [];
}
return [
RecentSpeedChart::class,
RecentPingChart::class,
RecentJitterChart::class,
];
}
public function queueSpeedtest(GeneralSettings $settings)
{
$ookla_server_id = null;
if (! blank($settings->speedtest_server)) {
$item = array_rand($settings->speedtest_server);
$ookla_server_id = $settings->speedtest_server[$item];
}
$speedtest = [
'ookla_server_id' => $ookla_server_id,
];
ExecSpeedtest::dispatch(speedtest: $speedtest, scheduled: false);
Notification::make()
->title('Speedtest added to the queue')
->success()
->send();
}
}