forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneralPage.php
More file actions
114 lines (100 loc) · 4.98 KB
/
GeneralPage.php
File metadata and controls
114 lines (100 loc) · 4.98 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
namespace App\Filament\Pages\Settings;
use App\Rules\ValidCronExpression;
use App\Settings\GeneralSettings;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Pages\SettingsPage;
use Illuminate\Support\Facades\Http;
use Squire\Models\Timezone;
class GeneralPage extends SettingsPage
{
protected static ?string $navigationIcon = 'heroicon-o-cog';
protected static ?string $navigationGroup = 'Settings';
protected static ?int $navigationSort = 1;
protected static ?string $title = 'General';
protected static ?string $navigationLabel = 'General';
protected static string $settings = GeneralSettings::class;
protected function getFormSchema(): array
{
return [
Grid::make([
'default' => 1,
'md' => 3,
])
->schema([
Grid::make([
'default' => 1,
])
->schema([
Section::make('Site Settings')
->schema([
TextInput::make('site_name')
->maxLength(50)
->required()
->columnSpan(['md' => 2]),
Select::make('timezone')
->options(Timezone::all()->pluck('code', 'code'))
->searchable()
->required(),
TextInput::make('time_format')
->helperText('Use [DateTime Format](https://www.php.net/manual/en/datetime.format.php) options to change the format of the datetime in views.')
->placeholder('M j, Y G:i:s')
->maxLength(25)
->required(),
])
->compact()
->columns([
'default' => 1,
'md' => 2,
]),
Section::make('Speedtest Settings')
->schema([
TextInput::make('speedtest_schedule')
->rules([new ValidCronExpression()])
->helperText('Leave empty to disable the schedule. You can also use the cron expression generator [HERE](https://crontab.cronhub.io/) to help you make schedules.')
->nullable()
->columnSpan(1),
Select::make('speedtest_server')
->label('Speedtest server ID')
->helperText('Leave empty to let the system pick the best server.')
->nullable()
->multiple()
->maxItems(10)
->searchable()
->getSearchResultsUsing(function (string $search) {
$url = "https://www.speedtest.net/api/js/servers?engine=js&search={$search}&https_functional=true&limit=10";
$response = Http::get($url);
$options = $response->collect()->map(function ($item) {
return [
'id' => $item['id'],
'name' => $item['id'].': '.$item['name'].' ('.$item['sponsor'].')',
];
});
if (! $options->count() && is_numeric($search)) {
$options = collect([
[
'id' => $search,
'name' => $search.': No server found, manually add this ID.',
],
]);
}
return $options->pluck('name', 'id');
})
->columnSpan(2),
])
->compact()
->columns([
'default' => 1,
'md' => 2,
]),
])
->columnSpan([
'md' => 2,
]),
]),
];
}
}