|
| 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 | +} |
0 commit comments