Skip to content

Commit d5158ac

Browse files
committed
Implement data usage settings and update related components
1 parent c53d121 commit d5158ac

File tree

3 files changed

+45
-53
lines changed

3 files changed

+45
-53
lines changed

app/Filament/Pages/Settings/General.php

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
use App\Settings\GeneralSettings;
66
use BackedEnum;
77
use CodeWithDennis\SimpleAlert\Components\SimpleAlert;
8+
use Filament\Forms\Components\Radio;
89
use Filament\Forms\Components\Select;
910
use Filament\Forms\Components\TextInput;
1011
use Filament\Forms\Components\Toggle;
1112
use Filament\Pages\SettingsPage;
12-
use Filament\Schemas\Components\Fieldset;
1313
use Filament\Schemas\Components\Grid;
1414
use Filament\Schemas\Components\Tabs;
1515
use Filament\Schemas\Components\Tabs\Tab;
1616
use Filament\Schemas\Components\Utilities\Get;
1717
use Filament\Schemas\Schema;
1818
use Illuminate\Support\Facades\Auth;
19+
use Illuminate\Support\HtmlString;
1920

2021
class General extends SettingsPage
2122
{
@@ -44,7 +45,7 @@ public function form(Schema $schema): Schema
4445
->components([
4546
Tabs::make()
4647
->schema([
47-
Tab::make('Bandwidth')
48+
Tab::make('Data Usage')
4849
->icon('tabler-cloud-data-connection')
4950
->columns([
5051
'default' => 1,
@@ -53,11 +54,11 @@ public function form(Schema $schema): Schema
5354
->schema([
5455
SimpleAlert::make('data_usage_note')
5556
->info()
56-
->description('Data usage is calculated based on the total downloaded and uploaded data from Ookla Speedtests only.')
57+
->description(new HtmlString('Data usage is calculated on the total downloaded and uploaded data from Ookla Speedtests <u>only</u>.'))
5758
->columnSpanFull(),
5859

59-
Toggle::make('data_cap_enabled')
60-
->label('Enable bandwidth data cap')
60+
Toggle::make('data_usage_enabled')
61+
->label('Enable data usage limit')
6162
->reactive()
6263
->columnSpanFull(),
6364

@@ -66,28 +67,30 @@ public function form(Schema $schema): Schema
6667
'md' => 2,
6768
])
6869
->schema([
69-
TextInput::make('data_cap_data_limit')
70-
->label('Data limit')
70+
TextInput::make('data_usage_limit')
71+
->label('Usage limit')
7172
->placeholder('e.g., 500GB, 1TB')
72-
->required(fn (Get $get) => $get('data_cap_enabled'))
73+
->required(fn (Get $get) => $get('data_usage_enabled'))
7374
->columnSpanFull(),
7475

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')
76+
Select::make('data_usage_period')
77+
->label('Period')
8678
->options([
87-
'notify' => 'Notify admin(s)',
88-
'block' => 'Block and notify admin(s)',
79+
'day' => 'Day',
80+
'week' => 'Week',
81+
'month' => 'Month',
8982
])
9083
->required(),
84+
85+
TextInput::make('data_usage_reset_day')
86+
->label('Reset day')
87+
->helperText('Which day of the month or week (Sunday=0, Monday=1 etc.) should the data usage reset?')
88+
->numeric()
89+
->integer()
90+
->step(1)
91+
->minValue(0)
92+
->maxValue(31)
93+
->required(),
9194
])
9295
->columnSpan([
9396
'default' => 1,
@@ -98,27 +101,16 @@ public function form(Schema $schema): Schema
98101
'default' => 1,
99102
])
100103
->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(),
104+
Radio::make('data_usage_action')
105+
->label('Action on limit reached')
106+
->options([
107+
'notify' => 'Notify',
108+
'block' => 'Block and notify',
120109
])
121-
->columns(1),
110+
->descriptions([
111+
'notify' => 'Allow speed tests but notify the admin user(s) when the limit is reached.',
112+
'block' => 'Block further speed tests and notify the admin user(s) when the limit is reached.',
113+
]),
122114
])
123115
->columnSpan([
124116
'default' => 1,

app/Settings/GeneralSettings.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66

77
class GeneralSettings extends Settings
88
{
9-
public bool $data_cap_enabled = false; // Enable or disable data cap
9+
public bool $data_usage_enabled = false; // Enable or disable data cap
1010

11-
public ?string $data_cap_data_limit = null; // Example: '500GB' or '1TB'
11+
public string $data_usage_limit = ''; // Example: '500GB' or '1TB'
1212

13-
public string $data_cap_period = 'monthly'; // Options: 'daily', 'monthly', 'weekly'
13+
public string $data_usage_period = 'month'; // Options: 'day', 'week', 'month' or 'manual'
1414

15-
public int $data_cap_reset_day = 1; // Day of the month to reset data cap
15+
public int $data_usage_reset_day = 1; // Day of the period to reset data usage
1616

17-
public int $data_cap_warning_threshold = 80; // Percentage to notify user
17+
public string $data_usage_action = 'notify'; // Options: 'notify', 'restrict'
1818

19-
public string $data_cap_action = 'notify'; // Options: 'notify', 'restrict'
19+
public int $data_usage_used = 0; // Example: amount of data used in bytes
2020

2121
public static function group(): string
2222
{

database/settings/2025_11_29_123344_create_general_settings.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
{
77
public function up(): void
88
{
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'
12-
$this->migrator->add('general.data_cap_reset_day', 1); // Day of the month to reset data cap
13-
$this->migrator->add('general.data_cap_warning_threshold', 80); // Percentage to notify user
14-
$this->migrator->add('general.data_cap_action', 'notify'); // Options: 'notify', 'block'
9+
$this->migrator->add('general.data_usage_enabled', false); // Enable or disable data cap
10+
$this->migrator->add('general.data_usage_limit', ''); // Example: '500GB' or '1TB'
11+
$this->migrator->add('general.data_usage_period', 'month'); // Options: 'day', 'week', 'month' or 'manual'
12+
$this->migrator->add('general.data_usage_reset_day', 1); // Day of the period to reset data usage
13+
$this->migrator->add('general.data_usage_action', 'notify'); // Options: 'notify', 'restrict'
14+
$this->migrator->add('general.data_usage_used', 0); // Example: amount of data used in bytes
1515
}
1616
};

0 commit comments

Comments
 (0)