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 (80 loc) · 3.17 KB
/
Dashboard.php
File metadata and controls
94 lines (80 loc) · 3.17 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\Actions\Speedtests\RunOoklaSpeedtest;
use App\Filament\Widgets\RecentDownloadChartWidget;
use App\Filament\Widgets\RecentDownloadLatencyChartWidget;
use App\Filament\Widgets\RecentJitterChartWidget;
use App\Filament\Widgets\RecentPingChartWidget;
use App\Filament\Widgets\RecentUploadChartWidget;
use App\Filament\Widgets\RecentUploadLatencyChartWidget;
use App\Filament\Widgets\StatsOverviewWidget;
use Carbon\Carbon;
use Cron\CronExpression;
use Filament\Actions\Action;
use Filament\Actions\ActionGroup;
use Filament\Notifications\Notification;
use Filament\Pages\Dashboard as BasePage;
use Filament\Support\Enums\IconPosition;
use Illuminate\Support\Arr;
class Dashboard extends BasePage
{
protected static ?string $navigationIcon = 'heroicon-o-chart-bar';
protected static string $view = 'filament.pages.dashboard';
public function getSubheading(): ?string
{
if (blank(config('speedtest.schedule'))) {
return __('No speedtests scheduled.');
}
$cronExpression = new CronExpression(config('speedtest.schedule'));
$nextRunDate = Carbon::parse($cronExpression->getNextRunDate(timeZone: config('app.display_timezone')))->format(config('app.datetime_format'));
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: '/'),
ActionGroup::make([
Action::make('ookla speedtest')
->action(function () {
$servers = array_filter(
explode(',', config('speedtest.servers'))
);
$serverId = null;
if (count($servers)) {
$serverId = Arr::random($servers);
}
RunOoklaSpeedtest::run(serverId: $serverId);
Notification::make()
->title('Ookla speedtest started')
->success()
->send();
}),
])
->button()
->color('primary')
->dropdownPlacement('bottom-end')
->label('Run Speedtest')
->icon('heroicon-o-rocket-launch')
->iconPosition(IconPosition::Before)
->hidden(! auth()->user()->is_admin),
];
}
protected function getHeaderWidgets(): array
{
return [
StatsOverviewWidget::make(),
RecentDownloadChartWidget::make(),
RecentUploadChartWidget::make(),
RecentPingChartWidget::make(),
RecentJitterChartWidget::make(),
RecentDownloadLatencyChartWidget::make(),
RecentUploadLatencyChartWidget::make(),
];
}
}