Skip to content

Commit

Permalink
Merge pull request #225 from Boy132/update/gb-to-gib
Browse files Browse the repository at this point in the history
Update GB to GiB + minValues for resources + other stuff
  • Loading branch information
notAreYouScared authored May 14, 2024
2 parents 2b4625e + af797b3 commit 2d643ec
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 25 deletions.
14 changes: 9 additions & 5 deletions app/Filament/Resources/NodeResource/Pages/EditNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function form(Forms\Form $form): Forms\Form
Forms\Components\ToggleButtons::make('unlimited_mem')
->label('Memory')->inlineLabel()->inline()
->afterStateUpdated(fn (Forms\Set $set) => $set('memory', 0))
->afterStateUpdated(fn (Forms\Set $set) => $set('memory_overallocate', -1))
->afterStateUpdated(fn (Forms\Set $set) => $set('memory_overallocate', 0))
->formatStateUsing(fn (Forms\Get $get) => $get('memory') == 0)
->live()
->options([
Expand All @@ -110,7 +110,8 @@ public function form(Forms\Form $form): Forms\Form
->suffix('MiB')
->required()
->columnSpan(2)
->numeric(),
->numeric()
->minValue(0),
Forms\Components\TextInput::make('memory_overallocate')
->dehydratedWhenHidden()
->label('Overallocate')->inlineLabel()
Expand All @@ -120,6 +121,7 @@ public function form(Forms\Form $form): Forms\Form
->hintIconTooltip('The % allowable to go over the set limit.')
->columnSpan(2)
->numeric()
->minValue(-1)
->maxValue(100)
->suffix('%'),
]),
Expand All @@ -131,7 +133,7 @@ public function form(Forms\Form $form): Forms\Form
->label('Disk')->inlineLabel()->inline()
->live()
->afterStateUpdated(fn (Forms\Set $set) => $set('disk', 0))
->afterStateUpdated(fn (Forms\Set $set) => $set('disk_overallocate', -1))
->afterStateUpdated(fn (Forms\Set $set) => $set('disk_overallocate', 0))
->formatStateUsing(fn (Forms\Get $get) => $get('disk') == 0)
->options([
true => 'Unlimited',
Expand All @@ -146,10 +148,11 @@ public function form(Forms\Form $form): Forms\Form
->dehydratedWhenHidden()
->hidden(fn (Forms\Get $get) => $get('unlimited_disk'))
->label('Disk Limit')->inlineLabel()
->suffix('MB')
->suffix('MiB')
->required()
->columnSpan(2)
->numeric(),
->numeric()
->minValue(0),
Forms\Components\TextInput::make('disk_overallocate')
->dehydratedWhenHidden()
->hidden(fn (Forms\Get $get) => $get('unlimited_disk'))
Expand All @@ -159,6 +162,7 @@ public function form(Forms\Form $form): Forms\Form
->columnSpan(2)
->required()
->numeric()
->minValue(-1)
->maxValue(100)
->suffix('%'),
]),
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(' GB')
->formatStateUsing(fn ($state) => number_format($state / 1000, 2))
->suffix(' GiB')
->formatStateUsing(fn ($state) => number_format($state / 1024, 2))
->sortable(),
Tables\Columns\TextColumn::make('disk')
->visibleFrom('sm')
->icon('tabler-file')
->numeric()
->suffix(' GB')
->formatStateUsing(fn ($state) => number_format($state / 1000, 2))
->suffix(' GiB')
->formatStateUsing(fn ($state) => number_format($state / 1024, 2))
->sortable(),
Tables\Columns\IconColumn::make('scheme')
->visibleFrom('xl')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ protected function getData(): array
/** @var Node $node */
$node = $this->record;

$total = $node->statistics()['memory_total'] ?? 0;
$used = $node->statistics()['memory_used'] ?? 0;
$total = ($node->statistics()['memory_total'] ?? 0) / 1024 / 1024 / 1024;
$used = ($node->statistics()['memory_used'] ?? 0) / 1024 / 1024 / 1024;
$unused = $total - $used;

return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ protected function getData(): array
/** @var Node $node */
$node = $this->record;

$total = $node->statistics()['disk_total'] ?? 0;
$used = $node->statistics()['disk_used'] ?? 0;
$total = ($node->statistics()['disk_total'] ?? 0) / 1024 / 1024 / 1024;
$used = ($node->statistics()['disk_used'] ?? 0) / 1024 / 1024 / 1024;
$unused = $total - $used;

return [
Expand Down
16 changes: 10 additions & 6 deletions app/Filament/Resources/ServerResource/Pages/CreateServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,12 @@ public function form(Form $form): Form
->dehydratedWhenHidden()
->hidden(fn (Forms\Get $get) => $get('unlimited_mem'))
->label('Memory Limit')->inlineLabel()
->suffix('MB')
->suffix('MiB')
->default(0)
->required()
->columnSpan(2)
->numeric(),
->numeric()
->minValue(0),
]),

Forms\Components\Grid::make()
Expand All @@ -517,11 +518,12 @@ public function form(Form $form): Form
->dehydratedWhenHidden()
->hidden(fn (Forms\Get $get) => $get('unlimited_disk'))
->label('Disk Space Limit')->inlineLabel()
->suffix('MB')
->suffix('MiB')
->default(0)
->required()
->columnSpan(2)
->numeric(),
->numeric()
->minValue(0),
]),

Forms\Components\Grid::make()
Expand Down Expand Up @@ -551,7 +553,9 @@ public function form(Form $form): Form
->default(0)
->required()
->columnSpan(2)
->numeric(),
->numeric()
->minValue(0)
->helperText('100% equals one logical thread'),
]),

Forms\Components\Grid::make()
Expand Down Expand Up @@ -593,7 +597,7 @@ public function form(Form $form): Form
})
->label('Swap Memory')
->default(0)
->suffix('MB')
->suffix('MiB')
->minValue(-1)
->columnSpan(2)
->inlineLabel()
Expand Down
15 changes: 9 additions & 6 deletions app/Filament/Resources/ServerResource/Pages/EditServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,11 @@ public function form(Form $form): Form
->dehydratedWhenHidden()
->hidden(fn (Forms\Get $get) => $get('unlimited_mem'))
->label('Memory Limit')->inlineLabel()
->suffix('MB')
->suffix('MiB')
->required()
->columnSpan(2)
->numeric(),
->numeric()
->minValue(0),
]),

Forms\Components\Grid::make()
Expand All @@ -362,10 +363,11 @@ public function form(Form $form): Form
->dehydratedWhenHidden()
->hidden(fn (Forms\Get $get) => $get('unlimited_disk'))
->label('Disk Space Limit')->inlineLabel()
->suffix('MB')
->suffix('MiB')
->required()
->columnSpan(2)
->numeric(),
->numeric()
->minValue(0),
]),

Forms\Components\Grid::make()
Expand Down Expand Up @@ -394,7 +396,8 @@ public function form(Form $form): Form
->suffix('%')
->required()
->columnSpan(2)
->numeric(),
->numeric()
->minValue(0),
]),

Forms\Components\Grid::make()
Expand Down Expand Up @@ -439,7 +442,7 @@ public function form(Form $form): Form
'limited', false => false,
})
->label('Swap Memory')->inlineLabel()
->suffix('MB')
->suffix('MiB')
->minValue(-1)
->columnSpan(2)
->required()
Expand Down

0 comments on commit 2d643ec

Please sign in to comment.