Skip to content

Commit

Permalink
Settings page followup (pelican-dev#514)
Browse files Browse the repository at this point in the history
* remove group for toggle buttons

* fix default for APP_DEBUG

* correctly handle bool values

* fix pint

* small cleanup for example .env
  • Loading branch information
Boy132 authored Jul 30, 2024
1 parent a58e159 commit 3f40256
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
6 changes: 1 addition & 5 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ [email protected]
MAIL_FROM_NAME="Pelican Admin"
# Set this to your domain to prevent it defaulting to 'localhost', causing mail servers such as Gmail to reject your mail
# MAIL_EHLO_DOMAIN=panel.example.com

SESSION_ENCRYPT=false
SESSION_PATH=/
SESSION_DOMAIN=null

# Set this to true, and set start & end ports to auto create allocations.
PANEL_CLIENT_ALLOCATIONS_ENABLED=false
PANEL_CLIENT_ALLOCATIONS_RANGE_START=
PANEL_CLIENT_ALLOCATIONS_RANGE_END=
17 changes: 10 additions & 7 deletions app/Filament/Pages/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ private function generalSettings(): array
->offColor('danger')
->formatStateUsing(fn ($state): bool => (bool) $state)
->afterStateUpdated(fn ($state, Set $set) => $set('APP_DEBUG', (bool) $state))
->default(env('RECAPTCHA_ENABLED', config('recaptcha.enabled'))),
->default(env('APP_DEBUG', config('app.debug'))),
ToggleButtons::make('FILAMENT_TOP_NAVIGATION')
->label('Navigation')
->grouped()
->inline()
->options([
false => 'Sidebar',
true => 'Topbar',
Expand All @@ -115,7 +115,7 @@ private function generalSettings(): array
->default(env('FILAMENT_TOP_NAVIGATION', config('panel.filament.top-navigation'))),
ToggleButtons::make('PANEL_USE_BINARY_PREFIX')
->label('Unit prefix')
->grouped()
->inline()
->options([
false => 'Decimal Prefix (MB/ GB)',
true => 'Binary Prefix (MiB/ GiB)',
Expand All @@ -125,7 +125,7 @@ private function generalSettings(): array
->default(env('PANEL_USE_BINARY_PREFIX', config('panel.use_binary_prefix'))),
ToggleButtons::make('APP_2FA_REQUIRED')
->label('2FA Requirement')
->grouped()
->inline()
->options([
0 => 'Not required',
1 => 'Required for only Admins',
Expand Down Expand Up @@ -209,7 +209,7 @@ private function mailSettings(): array
ToggleButtons::make('MAIL_MAILER')
->label('Mail Driver')
->columnSpanFull()
->grouped()
->inline()
->options([
'log' => 'Print mails to Log',
'smtp' => 'SMTP Server',
Expand Down Expand Up @@ -284,7 +284,7 @@ private function mailSettings(): array
ToggleButtons::make('MAIL_ENCRYPTION')
->label('SMTP encryption')
->required()
->grouped()
->inline()
->options(['tls' => 'TLS', 'ssl' => 'SSL', '' => 'None'])
->default(env('MAIL_ENCRYPTION', config('mail.mailers.smtp.encryption', 'tls'))),
]),
Expand Down Expand Up @@ -314,7 +314,7 @@ private function backupSettings(): array
ToggleButtons::make('APP_BACKUP_DRIVER')
->label('Backup Driver')
->columnSpanFull()
->grouped()
->inline()
->options([
Backup::ADAPTER_DAEMON => 'Wings',
Backup::ADAPTER_AWS_S3 => 'S3',
Expand Down Expand Up @@ -532,6 +532,9 @@ public function save(): void
try {
$data = $this->form->getState();

// Convert bools to a string, so they are correctly written to the .env file
$data = array_map(fn ($value) => is_bool($value) ? ($value ? 'true' : 'false') : $value, $data);

$this->writeToEnvironment($data);

Artisan::call('config:clear');
Expand Down

0 comments on commit 3f40256

Please sign in to comment.