
* add spatie/permissions * add policies * add role resource * add root admin role handling * replace some "root_admin" with function * add model specific permissions * make permission selection nicer * fix user creation * fix tests * add back subuser checks in server policy * add custom model for role * assign new users to role if root_admin is set * add api for roles * fix phpstan * add permissions for settings page * remove "restore" and "forceDelete" permissions * add user count to list * prevent deletion if role has users * update user list * fix server policy * remove old `root_admin` column * small refactor * fix tests * forgot can checks here * forgot use * disable editing own roles & disable assigning root admin * don't allow to rename root admin role * remove php bombing exception handler * fix role assignment when creating a user * fix disableOptionWhen * fix missing `root_admin` attribute on react frontend * add permission check for bulk delete * rename viewAny to viewList * improve canAccessPanel check * fix admin not displaying for non-root admins * make sure non root admins can't edit root admins * fix import * fix settings page permission check * fix server permissions for non-subusers * fix settings page permission check v2 * small cleanup * cleanup config file * move consts from resouce into enum & model * Update database/migrations/2024_08_01_114538_remove_root_admin_column.php Co-authored-by: Lance Pioch <lancepioch@gmail.com> * fix config * fix phpstan * fix phpstan 2.0 --------- Co-authored-by: Lance Pioch <lancepioch@gmail.com>
110 lines
4.1 KiB
PHP
110 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\NodeResource\Pages;
|
|
|
|
use App\Filament\Resources\NodeResource;
|
|
use App\Models\Node;
|
|
use Filament\Actions;
|
|
use Filament\Resources\Pages\ListRecords;
|
|
use Filament\Tables\Actions\BulkActionGroup;
|
|
use Filament\Tables\Actions\CreateAction;
|
|
use Filament\Tables\Actions\DeleteBulkAction;
|
|
use Filament\Tables\Actions\EditAction;
|
|
use Filament\Tables\Columns\IconColumn;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Table;
|
|
|
|
class ListNodes extends ListRecords
|
|
{
|
|
protected static string $resource = NodeResource::class;
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->searchable(false)
|
|
->checkIfRecordIsSelectableUsing(fn (Node $node) => $node->servers_count <= 0)
|
|
->columns([
|
|
TextColumn::make('uuid')
|
|
->label('UUID')
|
|
->searchable()
|
|
->hidden(),
|
|
IconColumn::make('health')
|
|
->alignCenter()
|
|
->state(fn (Node $node) => $node)
|
|
->view('livewire.columns.version-column'),
|
|
TextColumn::make('name')
|
|
->icon('tabler-server-2')
|
|
->sortable()
|
|
->searchable(),
|
|
TextColumn::make('fqdn')
|
|
->visibleFrom('md')
|
|
->label('Address')
|
|
->icon('tabler-network')
|
|
->sortable()
|
|
->searchable(),
|
|
TextColumn::make('memory')
|
|
->visibleFrom('sm')
|
|
->icon('tabler-device-desktop-analytics')
|
|
->numeric()
|
|
->suffix(config('panel.use_binary_prefix') ? ' GiB' : ' GB')
|
|
->formatStateUsing(fn ($state) => number_format($state / (config('panel.use_binary_prefix') ? 1024 : 1000), 2))
|
|
->sortable(),
|
|
TextColumn::make('disk')
|
|
->visibleFrom('sm')
|
|
->icon('tabler-file')
|
|
->numeric()
|
|
->suffix(config('panel.use_binary_prefix') ? ' GiB' : ' GB')
|
|
->formatStateUsing(fn ($state) => number_format($state / (config('panel.use_binary_prefix') ? 1024 : 1000), 2))
|
|
->sortable(),
|
|
TextColumn::make('cpu')
|
|
->visibleFrom('sm')
|
|
->icon('tabler-file')
|
|
->numeric()
|
|
->suffix(' %')
|
|
->sortable(),
|
|
IconColumn::make('scheme')
|
|
->visibleFrom('xl')
|
|
->label('SSL')
|
|
->trueIcon('tabler-lock')
|
|
->falseIcon('tabler-lock-open-off')
|
|
->state(fn (Node $node) => $node->scheme === 'https'),
|
|
IconColumn::make('public')
|
|
->visibleFrom('lg')
|
|
->trueIcon('tabler-eye-check')
|
|
->falseIcon('tabler-eye-cancel'),
|
|
TextColumn::make('servers_count')
|
|
->visibleFrom('sm')
|
|
->counts('servers')
|
|
->label('Servers')
|
|
->sortable()
|
|
->icon('tabler-brand-docker'),
|
|
])
|
|
->actions([
|
|
EditAction::make(),
|
|
])
|
|
->bulkActions([
|
|
BulkActionGroup::make([
|
|
DeleteBulkAction::make()
|
|
->authorize(fn () => auth()->user()->can('delete node')),
|
|
]),
|
|
])
|
|
->emptyStateIcon('tabler-server-2')
|
|
->emptyStateDescription('')
|
|
->emptyStateHeading('No Nodes')
|
|
->emptyStateActions([
|
|
CreateAction::make('create')
|
|
->label('Create Node')
|
|
->button(),
|
|
]);
|
|
}
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
Actions\CreateAction::make()
|
|
->label('Create Node')
|
|
->hidden(fn () => Node::count() <= 0),
|
|
];
|
|
}
|
|
}
|