forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataIntegration.php
More file actions
156 lines (143 loc) · 8.53 KB
/
DataIntegration.php
File metadata and controls
156 lines (143 loc) · 8.53 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
namespace App\Filament\Pages\Settings;
use App\Jobs\Influxdb\v2\BulkWriteResults;
use App\Jobs\Influxdb\v2\TestConnectionJob;
use App\Settings\DataIntegrationSettings;
use Filament\Actions\Action;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\TagsInput;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Notifications\Notification;
use Filament\Pages\SettingsPage;
use Filament\Schemas\Components\Actions;
use Filament\Schemas\Components\Grid;
use Filament\Schemas\Components\Tabs;
use Filament\Schemas\Components\Tabs\Tab;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Illuminate\Support\Facades\Auth;
class DataIntegration extends SettingsPage
{
protected static string|\BackedEnum|null $navigationIcon = 'tabler-database';
protected static string|\UnitEnum|null $navigationGroup = 'Settings';
protected static ?int $navigationSort = 2;
public function getTitle(): string
{
return __('settings/data_integration.title');
}
public static function getNavigationLabel(): string
{
return __('settings/data_integration.label');
}
protected static string $settings = DataIntegrationSettings::class;
public static function canAccess(): bool
{
return Auth::check() && Auth::user()->is_admin;
}
public static function shouldRegisterNavigation(): bool
{
return Auth::check() && Auth::user()->is_admin;
}
public function form(Schema $schema): Schema
{
return $schema
->components([
Tabs::make()
->schema([
Tab::make(__('settings/data_integration.influxdb_v2'))
->icon(Heroicon::OutlinedCircleStack)
->schema([
Toggle::make('influxdb_v2_enabled')
->label(__('settings/data_integration.influxdb_v2_enabled'))
->helperText(__('settings/data_integration.influxdb_v2_description'))
->reactive()
->columnSpanFull(),
Grid::make(['default' => 1, 'md' => 3])
->hidden(fn (Get $get) => $get('influxdb_v2_enabled') !== true)
->schema([
TextInput::make('influxdb_v2_url')
->label(__('settings/data_integration.influxdb_v2_url'))
->placeholder(__('settings/data_integration.influxdb_v2_url_placeholder'))
->maxLength(255)
->required(fn (Get $get) => $get('influxdb_v2_enabled') === true)
->columnSpan(['md' => 1]),
TextInput::make('influxdb_v2_org')
->label(__('settings/data_integration.influxdb_v2_org'))
->maxLength(255)
->required(fn (Get $get) => $get('influxdb_v2_enabled') === true)
->columnSpan(['md' => 1]),
TextInput::make('influxdb_v2_bucket')
->placeholder(__('settings/data_integration.influxdb_v2_bucket_placeholder'))
->label(__('settings/data_integration.influxdb_v2_bucket'))
->maxLength(255)
->required(fn (Get $get) => $get('influxdb_v2_enabled') === true)
->columnSpan(['md' => 2]),
TextInput::make('influxdb_v2_token')
->label(__('settings/data_integration.influxdb_v2_token'))
->maxLength(255)
->password()
->required(fn (Get $get) => $get('influxdb_v2_enabled') === true)
->columnSpan(['md' => 2]),
Checkbox::make('influxdb_v2_verify_ssl')
->label(__('settings/data_integration.influxdb_v2_verify_ssl'))
->columnSpanFull(),
// Button to send old data to InfluxDB
Actions::make([
Action::make('Export current results')
->label(__('general.export_current_results'))
->action(function () {
Notification::make()
->title(__('settings/data_integration.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
Actions::make([
Action::make('Test connection')
->label(__('settings/data_integration.test_connection'))
->action(function () {
Notification::make()
->title(__('settings/data_integration.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),
]),
]),
])
->columnSpanFull(),
Tab::make(__('settings/data_integration.prometheus'))
->icon(Heroicon::OutlinedChartBar)
->schema([
Toggle::make('prometheus_enabled')
->label(__('settings/data_integration.prometheus_enabled'))
->helperText(__('settings/data_integration.prometheus_enabled_helper_text'))
->reactive()
->columnSpanFull(),
Grid::make(['default' => 1, 'md' => 3])
->hidden(fn (Get $get) => $get('prometheus_enabled') !== true)
->schema([
TagsInput::make('prometheus_allowed_ips')
->label(__('settings/data_integration.prometheus_allowed_ips'))
->helperText(__('settings/data_integration.prometheus_allowed_ips_helper'))
->placeholder('192.168.1.100')
->splitKeys(['Tab', ',', ' '])
->columnSpanFull(),
]),
])
->columnSpanFull(),
])
->columnSpanFull(),
]);
}
}