Skip to content

Commit

Permalink
add config variable for binary prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy132 committed Jun 11, 2024
1 parent 9184441 commit 0e5ddee
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 19 deletions.
6 changes: 3 additions & 3 deletions app/Filament/Resources/NodeResource/Pages/CreateNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public function form(Forms\Form $form): Forms\Form
->default(256)
->minValue(1)
->maxValue(1024)
->suffix('MiB'),
->suffix(config('panel.use_binary_prefix') ? 'MiB' : 'MB'),
Forms\Components\TextInput::make('daemon_sftp')
->columnSpan(1)
->label('SFTP Port')
Expand Down Expand Up @@ -274,7 +274,7 @@ public function form(Forms\Form $form): Forms\Form
->dehydratedWhenHidden()
->hidden(fn (Forms\Get $get) => $get('unlimited_mem'))
->label('Memory Limit')->inlineLabel()
->suffix('MiB')
->suffix(config('panel.use_binary_prefix') ? 'MiB' : 'MB')
->columnSpan(2)
->numeric()
->minValue(0)
Expand Down Expand Up @@ -315,7 +315,7 @@ public function form(Forms\Form $form): Forms\Form
->dehydratedWhenHidden()
->hidden(fn (Forms\Get $get) => $get('unlimited_disk'))
->label('Disk Limit')->inlineLabel()
->suffix('MiB')
->suffix(config('panel.use_binary_prefix') ? 'MiB' : 'MB')
->columnSpan(2)
->numeric()
->minValue(0)
Expand Down
6 changes: 3 additions & 3 deletions app/Filament/Resources/NodeResource/Pages/EditNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public function form(Forms\Form $form): Forms\Form
->numeric()->required()
->minValue(1)
->maxValue(1024)
->suffix('MiB'),
->suffix(config('panel.use_binary_prefix') ? 'MiB' : 'MB'),
Forms\Components\TextInput::make('daemon_sftp')
->columnSpan(['default' => 1, 'sm' => 1, 'md' => 1, 'lg' => 3])
->label('SFTP Port')
Expand Down Expand Up @@ -274,7 +274,7 @@ public function form(Forms\Form $form): Forms\Form
->dehydratedWhenHidden()
->hidden(fn (Forms\Get $get) => $get('unlimited_mem'))
->label('Memory Limit')->inlineLabel()
->suffix('MiB')
->suffix(config('panel.use_binary_prefix') ? 'MiB' : 'MB')
->required()
->columnSpan(['default' => 1, 'sm' => 1, 'md' => 1, 'lg' => 2])
->numeric()
Expand Down Expand Up @@ -314,7 +314,7 @@ public function form(Forms\Form $form): Forms\Form
->dehydratedWhenHidden()
->hidden(fn (Forms\Get $get) => $get('unlimited_disk'))
->label('Disk Limit')->inlineLabel()
->suffix('MiB')
->suffix(config('panel.use_binary_prefix') ? 'MiB' : 'MB')
->required()
->columnSpan(['default' => 1, 'sm' => 1, 'md' => 1, 'lg' => 2])
->numeric()
Expand Down
8 changes: 4 additions & 4 deletions app/Filament/Resources/NodeResource/Pages/ListNodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ public function table(Table $table): Table
->visibleFrom('sm')
->icon('tabler-device-desktop-analytics')
->numeric()
->suffix(' GiB')
->formatStateUsing(fn ($state) => number_format($state / 1024, 2))
->suffix(config('panel.use_binary_prefix') ? ' GiB' : ' GB')
->formatStateUsing(fn ($state) => number_format($state / (config('panel.use_binary_prefix') ? 1024 : 1000), 2))
->sortable(),
Tables\Columns\TextColumn::make('disk')
->visibleFrom('sm')
->icon('tabler-file')
->numeric()
->suffix(' GiB')
->formatStateUsing(fn ($state) => number_format($state / 1024, 2))
->suffix(config('panel.use_binary_prefix') ? ' GiB' : ' GB')
->formatStateUsing(fn ($state) => number_format($state / (config('panel.use_binary_prefix') ? 1024 : 1000), 2))
->sortable(),
Tables\Columns\TextColumn::make('cpu')
->visibleFrom('sm')
Expand Down
6 changes: 3 additions & 3 deletions app/Filament/Resources/ServerResource/Pages/CreateServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ public function form(Form $form): Form
->dehydratedWhenHidden()
->hidden(fn (Forms\Get $get) => $get('unlimited_mem'))
->label('Memory Limit')->inlineLabel()
->suffix('MiB')
->suffix(config('panel.use_binary_prefix') ? 'MiB' : 'MB')
->default(0)
->required()
->columnSpan(2)
Expand Down Expand Up @@ -519,7 +519,7 @@ public function form(Form $form): Form
->dehydratedWhenHidden()
->hidden(fn (Forms\Get $get) => $get('unlimited_disk'))
->label('Disk Space Limit')->inlineLabel()
->suffix('MiB')
->suffix(config('panel.use_binary_prefix') ? 'MiB' : 'MB')
->default(0)
->required()
->columnSpan(2)
Expand Down Expand Up @@ -598,7 +598,7 @@ public function form(Form $form): Form
})
->label('Swap Memory')
->default(0)
->suffix('MiB')
->suffix(config('panel.use_binary_prefix') ? 'MiB' : 'MB')
->minValue(-1)
->columnSpan(2)
->inlineLabel()
Expand Down
6 changes: 3 additions & 3 deletions app/Filament/Resources/ServerResource/Pages/EditServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function form(Form $form): Form
->dehydratedWhenHidden()
->hidden(fn (Forms\Get $get) => $get('unlimited_mem'))
->label('Memory Limit')->inlineLabel()
->suffix('MiB')
->suffix(config('panel.use_binary_prefix') ? 'MiB' : 'MB')
->required()
->columnSpan(2)
->numeric()
Expand Down Expand Up @@ -249,7 +249,7 @@ public function form(Form $form): Form
->dehydratedWhenHidden()
->hidden(fn (Forms\Get $get) => $get('unlimited_disk'))
->label('Disk Space Limit')->inlineLabel()
->suffix('MiB')
->suffix(config('panel.use_binary_prefix') ? 'MiB' : 'MB')
->required()
->columnSpan(2)
->numeric()
Expand Down Expand Up @@ -328,7 +328,7 @@ public function form(Form $form): Form
'limited', false => false,
})
->label('Swap Memory')->inlineLabel()
->suffix('MiB')
->suffix(config('panel.use_binary_prefix') ? 'MiB' : 'MB')
->minValue(-1)
->columnSpan(2)
->required()
Expand Down
6 changes: 3 additions & 3 deletions app/Services/Servers/ServerConfigurationStructureService.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ protected function returnFormat(Server $server): array
'invocation' => $server->startup,
'skip_egg_scripts' => $server->skip_scripts,
'build' => [
'memory_limit' => $server->memory,
'swap' => $server->swap,
'memory_limit' => config('panel.use_binary_prefix') ? $server->memory : $server->memory / 1.048576,
'swap' => config('panel.use_binary_prefix') ? $server->swap : $server->swap / 1.048576,
'io_weight' => $server->io,
'cpu_limit' => $server->cpu,
'threads' => $server->threads,
'disk_space' => $server->disk,
'disk_space' => config('panel.use_binary_prefix') ? $server->disk : $server->disk / 1.048576,
'oom_killer' => $server->oom_killer,
],
'container' => [
Expand Down
2 changes: 2 additions & 0 deletions config/panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,6 @@
'filament' => [
'top-navigation' => env('FILAMENT_TOP_NAVIGATION', false),
],

'use_binary_prefix' => env('PANEL_USE_BINARY_PREFIX', true),
];

0 comments on commit 0e5ddee

Please sign in to comment.