forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataIntegrationPage.php
More file actions
126 lines (113 loc) · 6.6 KB
/
DataIntegrationPage.php
File metadata and controls
126 lines (113 loc) · 6.6 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
115
116
117
118
119
120
121
122
123
124
125
126
<?php
namespace App\Filament\Pages\Settings;
use App\Jobs\Influxdb\v2\BulkWriteResults;
use App\Jobs\Influxdb\v2\TestConnectionJob;
use App\Settings\DataIntegrationSettings;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Filament\Pages\SettingsPage;
use Illuminate\Support\Facades\Auth;
class DataIntegrationPage extends SettingsPage
{
protected static ?string $navigationIcon = 'heroicon-o-circle-stack';
protected static ?string $navigationGroup = 'Settings';
protected static ?int $navigationSort = 2;
protected static ?string $title = 'Data Integration';
protected static ?string $navigationLabel = 'Data Integration';
protected static string $settings = DataIntegrationSettings::class;
public static function canAccess(): bool
{
return auth()->user()->is_admin;
}
public static function shouldRegisterNavigation(): bool
{
return auth()->user()->is_admin;
}
public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Grid::make([
'default' => 1,
'md' => 3,
])
->schema([
Forms\Components\Section::make('InfluxDB v2')
->description('When enabled, all new Speedtest results will also be sent to InfluxDB.')
->schema([
Forms\Components\Toggle::make('influxdb_v2_enabled')
->label('Enable')
->reactive()
->columnSpanFull(),
Forms\Components\Grid::make(['default' => 1, 'md' => 3])
->hidden(fn (Forms\Get $get) => $get('influxdb_v2_enabled') !== true)
->schema([
Forms\Components\TextInput::make('influxdb_v2_url')
->label('URL')
->placeholder('http://your-influxdb-instance')
->maxLength(255)
->required(fn (Forms\Get $get) => $get('influxdb_v2_enabled') === true)
->columnSpan(['md' => 1]),
Forms\Components\TextInput::make('influxdb_v2_org')
->label('Org')
->maxLength(255)
->required(fn (Forms\Get $get) => $get('influxdb_v2_enabled') === true)
->columnSpan(['md' => 1]),
Forms\Components\TextInput::make('influxdb_v2_bucket')
->placeholder('speedtest-tracker')
->label('Bucket')
->maxLength(255)
->required(fn (Forms\Get $get) => $get('influxdb_v2_enabled') === true)
->columnSpan(['md' => 2]),
Forms\Components\TextInput::make('influxdb_v2_token')
->label('Token')
->maxLength(255)
->password()
->required(fn (Forms\Get $get) => $get('influxdb_v2_enabled') === true)
->disableAutocomplete()
->columnSpan(['md' => 2]),
Forms\Components\Checkbox::make('influxdb_v2_verify_ssl')
->label('Verify SSL')
->columnSpanFull(),
// Button to send old data to InfluxDB
Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('Export current results')
->label('Export current results')
->action(function () {
Notification::make()
->title('Starting bulk data write to Influxdb')
->info()
->send();
BulkWriteResults::dispatch(Auth::user());
})
->color('primary')
->icon('heroicon-o-cloud-arrow-up')
->visible(fn (): bool => app(DataIntegrationSettings::class)->influxdb_v2_enabled),
]),
// Button to test InfluxDB connection
Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('Test connection')
->label('Test connection')
->action(function () {
Notification::make()
->title('Sending test data to Influxdb')
->info()
->send();
TestConnectionJob::dispatch(Auth::user());
})
->color('primary')
->icon('heroicon-o-check-circle')
->visible(fn (): bool => app(DataIntegrationSettings::class)->influxdb_v2_enabled),
]),
]),
])
->compact()
->columns([
'default' => 1,
'md' => 2,
]),
]),
]);
}
}