Skip to content

Commit 3a100bc

Browse files
committed
Implement data cap settings in General settings page and update migration for new properties
1 parent e7934a3 commit 3a100bc

File tree

4 files changed

+138
-20
lines changed

4 files changed

+138
-20
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?php
2+
3+
namespace App\Filament\Pages\Settings;
4+
5+
use App\Settings\GeneralSettings;
6+
use BackedEnum;
7+
use CodeWithDennis\SimpleAlert\Components\SimpleAlert;
8+
use Filament\Forms\Components\Select;
9+
use Filament\Forms\Components\TextInput;
10+
use Filament\Forms\Components\Toggle;
11+
use Filament\Pages\SettingsPage;
12+
use Filament\Schemas\Components\Fieldset;
13+
use Filament\Schemas\Components\Grid;
14+
use Filament\Schemas\Components\Tabs;
15+
use Filament\Schemas\Components\Tabs\Tab;
16+
use Filament\Schemas\Components\Utilities\Get;
17+
use Filament\Schemas\Schema;
18+
use Illuminate\Support\Facades\Auth;
19+
20+
class General extends SettingsPage
21+
{
22+
protected static string|BackedEnum|null $navigationIcon = 'tabler-adjustments-cog';
23+
24+
protected static string $settings = GeneralSettings::class;
25+
26+
protected static string|\UnitEnum|null $navigationGroup = 'Settings';
27+
28+
protected static ?int $navigationSort = 0;
29+
30+
public static function canAccess(): bool
31+
{
32+
return Auth::check() && Auth::user()->is_admin;
33+
}
34+
35+
public static function shouldRegisterNavigation(): bool
36+
{
37+
return Auth::check() && Auth::user()->is_admin;
38+
}
39+
40+
public function form(Schema $schema): Schema
41+
{
42+
return $schema
43+
->columns(1)
44+
->components([
45+
Tabs::make()
46+
->schema([
47+
Tab::make('Bandwidth')
48+
->icon('tabler-cloud-data-connection')
49+
->columns([
50+
'default' => 1,
51+
'md' => 3,
52+
])
53+
->schema([
54+
SimpleAlert::make('data_usage_note')
55+
->info()
56+
->description('Data usage is calculated based on the total downloaded and uploaded data from Ookla Speedtests only.')
57+
->columnSpanFull(),
58+
59+
Toggle::make('data_cap_enabled')
60+
->label('Enable bandwidth data cap')
61+
->reactive()
62+
->columnSpanFull(),
63+
64+
Grid::make([
65+
'default' => 1,
66+
'md' => 2,
67+
])
68+
->schema([
69+
TextInput::make('data_cap_data_limit')
70+
->label('Data limit')
71+
->placeholder('e.g., 500GB, 1TB')
72+
->required(fn (Get $get) => $get('data_cap_enabled'))
73+
->columnSpanFull(),
74+
75+
TextInput::make('data_cap_warning_threshold')
76+
->label('Warning threshold')
77+
->numeric()
78+
->integer()
79+
->minValue(1)
80+
->maxValue(100)
81+
->required()
82+
->suffix('%'),
83+
84+
Select::make('data_cap_action')
85+
->label('Action on limit reached')
86+
->options([
87+
'notify' => 'Notify admin(s)',
88+
'block' => 'Block and notify admin(s)',
89+
])
90+
->required(),
91+
])
92+
->columnSpan([
93+
'default' => 1,
94+
'md' => 2,
95+
]),
96+
97+
Grid::make([
98+
'default' => 1,
99+
])
100+
->schema([
101+
Fieldset::make('period_settings')
102+
->label('Period settings')
103+
->schema([
104+
Select::make('data_cap_period')
105+
->label('Period')
106+
->options([
107+
'day' => 'Day',
108+
'week' => 'Week',
109+
'month' => 'Month',
110+
])
111+
->required(),
112+
113+
TextInput::make('data_cap_reset_day')
114+
->label('Reset day')
115+
->numeric()
116+
->integer()
117+
->minValue(0)
118+
->maxValue(31)
119+
->required(),
120+
])
121+
->columns(1),
122+
])
123+
->columnSpan([
124+
'default' => 1,
125+
]),
126+
]),
127+
]),
128+
]);
129+
}
130+
}

app/Settings/GeneralSetting.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

app/Settings/GeneralSettings.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
class GeneralSettings extends Settings
88
{
9-
public string $data_cap_data_limit = ''; // Example: '500GB' or '1TB'
9+
public bool $data_cap_enabled = false; // Enable or disable data cap
10+
11+
public ?string $data_cap_data_limit = null; // Example: '500GB' or '1TB'
1012

1113
public string $data_cap_period = 'monthly'; // Options: 'daily', 'monthly', 'weekly'
1214

1315
public int $data_cap_reset_day = 1; // Day of the month to reset data cap
1416

15-
public int $data_cap_warning_percentage = 80; // Percentage to notify user
17+
public int $data_cap_warning_threshold = 80; // Percentage to notify user
1618

1719
public string $data_cap_action = 'notify'; // Options: 'notify', 'restrict'
1820

database/settings/2025_11_29_123344_create_general_settings.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
{
77
public function up(): void
88
{
9-
$this->migrator->add('general.data_cap_data_limit', ''); // Example: '500GB' or '1TB'
10-
$this->migrator->add('general.data_cap_period', 'monthly'); // Options: 'daily', 'monthly', 'weekly'
9+
$this->migrator->add('general.data_cap_enabled', false); // Enable or disable data cap
10+
$this->migrator->add('general.data_cap_data_limit', null); // Example: '500GB' or '1TB'
11+
$this->migrator->add('general.data_cap_period', 'month'); // Options: 'day', 'week', 'month'
1112
$this->migrator->add('general.data_cap_reset_day', 1); // Day of the month to reset data cap
12-
$this->migrator->add('general.data_cap_warning_percentage', 80); // Percentage to notify user
13+
$this->migrator->add('general.data_cap_warning_threshold', 80); // Percentage to notify user
1314
$this->migrator->add('general.data_cap_action', 'notify'); // Options: 'notify', 'block'
1415
}
1516
};

0 commit comments

Comments
 (0)