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
80 lines (66 loc) · 2.24 KB
/
Dashboard.php
File metadata and controls
80 lines (66 loc) · 2.24 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
<?php
namespace App\Filament\Pages;
use App\Console\Commands\RunOoklaSpeedtest;
use App\Filament\Widgets\RecentJitterChartWidget;
use App\Filament\Widgets\RecentPingChartWidget;
use App\Filament\Widgets\RecentSpeedChartWidget;
use App\Filament\Widgets\StatsOverviewWidget;
use App\Settings\GeneralSettings;
use Filament\Actions\Action;
use Filament\Notifications\Notification;
use Filament\Pages\Dashboard as BasePage;
use Illuminate\Support\Facades\Artisan;
class Dashboard extends BasePage
{
public bool $publicDashboard = false;
protected static ?string $pollingInterval = null;
protected static ?string $navigationIcon = 'heroicon-o-chart-bar';
protected static ?int $navigationSort = 1;
protected static string $view = 'filament.pages.dashboard';
public function mount()
{
$settings = new GeneralSettings();
$this->publicDashboard = $settings->public_dashboard_enabled;
}
protected function getHeaderActions(): array
{
return [
Action::make('home')
->label('Public Dashboard')
->color('gray')
->hidden(! $this->publicDashboard)
->url('/'),
Action::make('speedtest')
->label('Queue Speedtest')
->color('primary')
->action('queueSpeedtest')
->hidden(fn (): bool => ! auth()->user()->is_admin && ! auth()->user()->is_user),
];
}
protected function getHeaderWidgets(): array
{
return [
StatsOverviewWidget::make(),
RecentSpeedChartWidget::make(),
RecentPingChartWidget::make(),
RecentJitterChartWidget::make(),
];
}
public function queueSpeedtest(): void
{
try {
Artisan::call(RunOoklaSpeedtest::class);
} catch (\Throwable $th) {
Notification::make()
->title('Manual speedtest failed!')
->body('The starting a manual speedtest failed, check the logs.')
->warning()
->sendToDatabase(auth()->user());
return;
}
Notification::make()
->title('Speedtest added to the queue')
->success()
->send();
}
}