diff --git a/app/Filament/Widgets/Concerns/HasChartFilters.php b/app/Filament/Widgets/Concerns/HasChartFilters.php new file mode 100644 index 000000000..ce12d9384 --- /dev/null +++ b/app/Filament/Widgets/Concerns/HasChartFilters.php @@ -0,0 +1,15 @@ + 'Last 24 hours', + 'week' => 'Last 7 days', + 'month' => 'Last 30 days', + ]; + } +} diff --git a/app/Filament/Widgets/RecentDownloadChartWidget.php b/app/Filament/Widgets/RecentDownloadChartWidget.php index 53feffba4..2c3030f60 100644 --- a/app/Filament/Widgets/RecentDownloadChartWidget.php +++ b/app/Filament/Widgets/RecentDownloadChartWidget.php @@ -3,6 +3,7 @@ namespace App\Filament\Widgets; use App\Enums\ResultStatus; +use App\Filament\Widgets\Concerns\HasChartFilters; use App\Helpers\Average; use App\Helpers\Number; use App\Models\Result; @@ -10,6 +11,8 @@ class RecentDownloadChartWidget extends ChartWidget { + use HasChartFilters; + protected static ?string $heading = 'Download (Mbps)'; protected int|string|array $columnSpan = 'full'; @@ -18,15 +21,11 @@ class RecentDownloadChartWidget extends ChartWidget protected static ?string $pollingInterval = '60s'; - public ?string $filter = '24h'; + public ?string $filter = null; - protected function getFilters(): ?array + public function mount(): void { - return [ - '24h' => 'Last 24h', - 'week' => 'Last week', - 'month' => 'Last month', - ]; + $this->filter = $this->filter ?? config('speedtest.default_chart_range', '24h'); } protected function getData(): array diff --git a/app/Filament/Widgets/RecentDownloadLatencyChartWidget.php b/app/Filament/Widgets/RecentDownloadLatencyChartWidget.php index 6b75ffc97..639f5c454 100644 --- a/app/Filament/Widgets/RecentDownloadLatencyChartWidget.php +++ b/app/Filament/Widgets/RecentDownloadLatencyChartWidget.php @@ -3,11 +3,14 @@ namespace App\Filament\Widgets; use App\Enums\ResultStatus; +use App\Filament\Widgets\Concerns\HasChartFilters; use App\Models\Result; use Filament\Widgets\ChartWidget; class RecentDownloadLatencyChartWidget extends ChartWidget { + use HasChartFilters; + protected static ?string $heading = 'Download Latency'; protected int|string|array $columnSpan = 'full'; @@ -16,15 +19,11 @@ class RecentDownloadLatencyChartWidget extends ChartWidget protected static ?string $pollingInterval = '60s'; - public ?string $filter = '24h'; + public ?string $filter = null; - protected function getFilters(): ?array + public function mount(): void { - return [ - '24h' => 'Last 24h', - 'week' => 'Last week', - 'month' => 'Last month', - ]; + $this->filter = $this->filter ?? config('speedtest.default_chart_range', '24h'); } protected function getData(): array diff --git a/app/Filament/Widgets/RecentJitterChartWidget.php b/app/Filament/Widgets/RecentJitterChartWidget.php index 0c88525d6..19a345a7c 100644 --- a/app/Filament/Widgets/RecentJitterChartWidget.php +++ b/app/Filament/Widgets/RecentJitterChartWidget.php @@ -3,11 +3,14 @@ namespace App\Filament\Widgets; use App\Enums\ResultStatus; +use App\Filament\Widgets\Concerns\HasChartFilters; use App\Models\Result; use Filament\Widgets\ChartWidget; class RecentJitterChartWidget extends ChartWidget { + use HasChartFilters; + protected static ?string $heading = 'Jitter'; protected int|string|array $columnSpan = 'full'; @@ -16,15 +19,11 @@ class RecentJitterChartWidget extends ChartWidget protected static ?string $pollingInterval = '60s'; - public ?string $filter = '24h'; + public ?string $filter = null; - protected function getFilters(): ?array + public function mount(): void { - return [ - '24h' => 'Last 24h', - 'week' => 'Last week', - 'month' => 'Last month', - ]; + $this->filter = $this->filter ?? config('speedtest.default_chart_range', '24h'); } protected function getData(): array diff --git a/app/Filament/Widgets/RecentPingChartWidget.php b/app/Filament/Widgets/RecentPingChartWidget.php index 5077cc6be..b95325791 100644 --- a/app/Filament/Widgets/RecentPingChartWidget.php +++ b/app/Filament/Widgets/RecentPingChartWidget.php @@ -3,12 +3,15 @@ namespace App\Filament\Widgets; use App\Enums\ResultStatus; +use App\Filament\Widgets\Concerns\HasChartFilters; use App\Helpers\Average; use App\Models\Result; use Filament\Widgets\ChartWidget; class RecentPingChartWidget extends ChartWidget { + use HasChartFilters; + protected static ?string $heading = 'Ping (ms)'; protected int|string|array $columnSpan = 'full'; @@ -17,15 +20,11 @@ class RecentPingChartWidget extends ChartWidget protected static ?string $pollingInterval = '60s'; - public ?string $filter = '24h'; + public ?string $filter = null; - protected function getFilters(): ?array + public function mount(): void { - return [ - '24h' => 'Last 24h', - 'week' => 'Last week', - 'month' => 'Last month', - ]; + $this->filter = $this->filter ?? config('speedtest.default_chart_range', '24h'); } protected function getData(): array diff --git a/app/Filament/Widgets/RecentUploadChartWidget.php b/app/Filament/Widgets/RecentUploadChartWidget.php index d58d5c38e..12fd7b892 100644 --- a/app/Filament/Widgets/RecentUploadChartWidget.php +++ b/app/Filament/Widgets/RecentUploadChartWidget.php @@ -3,6 +3,7 @@ namespace App\Filament\Widgets; use App\Enums\ResultStatus; +use App\Filament\Widgets\Concerns\HasChartFilters; use App\Helpers\Average; use App\Helpers\Number; use App\Models\Result; @@ -10,6 +11,8 @@ class RecentUploadChartWidget extends ChartWidget { + use HasChartFilters; + protected static ?string $heading = 'Upload (Mbps)'; protected int|string|array $columnSpan = 'full'; @@ -18,15 +21,11 @@ class RecentUploadChartWidget extends ChartWidget protected static ?string $pollingInterval = '60s'; - public ?string $filter = '24h'; + public ?string $filter = null; - protected function getFilters(): ?array + public function mount(): void { - return [ - '24h' => 'Last 24h', - 'week' => 'Last week', - 'month' => 'Last month', - ]; + $this->filter = $this->filter ?? config('speedtest.default_chart_range', '24h'); } protected function getData(): array diff --git a/app/Filament/Widgets/RecentUploadLatencyChartWidget.php b/app/Filament/Widgets/RecentUploadLatencyChartWidget.php index 08f2808b4..977098b4f 100644 --- a/app/Filament/Widgets/RecentUploadLatencyChartWidget.php +++ b/app/Filament/Widgets/RecentUploadLatencyChartWidget.php @@ -3,11 +3,14 @@ namespace App\Filament\Widgets; use App\Enums\ResultStatus; +use App\Filament\Widgets\Concerns\HasChartFilters; use App\Models\Result; use Filament\Widgets\ChartWidget; class RecentUploadLatencyChartWidget extends ChartWidget { + use HasChartFilters; + protected static ?string $heading = 'Upload Latency'; protected int|string|array $columnSpan = 'full'; @@ -16,15 +19,11 @@ class RecentUploadLatencyChartWidget extends ChartWidget protected static ?string $pollingInterval = '60s'; - public ?string $filter = '24h'; + public ?string $filter = null; - protected function getFilters(): ?array + public function mount(): void { - return [ - '24h' => 'Last 24h', - 'week' => 'Last week', - 'month' => 'Last month', - ]; + $this->filter = $this->filter ?? config('speedtest.default_chart_range', '24h'); } protected function getData(): array diff --git a/config/speedtest.php b/config/speedtest.php index 944a9dac9..8fe4c7792 100644 --- a/config/speedtest.php +++ b/config/speedtest.php @@ -6,7 +6,6 @@ /** * General settings. */ - 'build_date' => Carbon::parse('2025-10-24'), 'build_version' => 'v1.6.9', @@ -17,6 +16,7 @@ 'public_dashboard' => env('PUBLIC_DASHBOARD', false), + 'default_chart_range' => env('DEFAULT_CHART_RANGE', '24h'), /** * Speedtest settings. @@ -31,25 +31,21 @@ 'checkinternet_url' => env('SPEEDTEST_CHECKINTERNET_URL', 'https://icanhazip.com'), - /** * IP filtering settings. */ - 'allowed_ips' => env('ALLOWED_IPS'), 'skip_ips' => env('SPEEDTEST_SKIP_IPS', ''), - /** * Threshold settings. */ + 'threshold_enabled' => env('THRESHOLD_ENABLED', false), - 'threshold_enabled' => env('THRESHOLD_ENABLED', false), - - 'threshold_download' => env('THRESHOLD_DOWNLOAD', 0), + 'threshold_download' => env('THRESHOLD_DOWNLOAD', 0), - 'threshold_upload' => env('THRESHOLD_UPLOAD', 0), + 'threshold_upload' => env('THRESHOLD_UPLOAD', 0), - 'threshold_ping' => env('THRESHOLD_PING', 0) , + 'threshold_ping' => env('THRESHOLD_PING', 0), ];