From 0895bd2be5cea87bd1474b7329ae2c51185e7144 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 10 Jun 2024 20:35:36 -0400 Subject: [PATCH] Remove relation managers --- app/Filament/Resources/NodeResource.php | 1 - .../AllocationsRelationManager.php | 151 ------------------ .../ServerResource/Pages/EditServer.php | 7 - .../AllocationsRelationManager.php | 75 --------- 4 files changed, 234 deletions(-) delete mode 100644 app/Filament/Resources/NodeResource/RelationManagers/AllocationsRelationManager.php delete mode 100644 app/Filament/Resources/ServerResource/RelationManagers/AllocationsRelationManager.php diff --git a/app/Filament/Resources/NodeResource.php b/app/Filament/Resources/NodeResource.php index bff1e0a40..14b3d1bce 100644 --- a/app/Filament/Resources/NodeResource.php +++ b/app/Filament/Resources/NodeResource.php @@ -23,7 +23,6 @@ class NodeResource extends Resource public static function getRelations(): array { return [ - RelationManagers\AllocationsRelationManager::class, RelationManagers\NodesRelationManager::class, ]; } diff --git a/app/Filament/Resources/NodeResource/RelationManagers/AllocationsRelationManager.php b/app/Filament/Resources/NodeResource/RelationManagers/AllocationsRelationManager.php deleted file mode 100644 index f74cf1fca..000000000 --- a/app/Filament/Resources/NodeResource/RelationManagers/AllocationsRelationManager.php +++ /dev/null @@ -1,151 +0,0 @@ -schema([ - Forms\Components\TextInput::make('ip') - ->required() - ->maxLength(255), - ]); - } - - public function table(Table $table): Table - { - return $table - ->recordTitleAttribute('ip') - - // Non Primary Allocations - // ->checkIfRecordIsSelectableUsing(fn (Allocation $allocation) => $allocation->id !== $allocation->server?->allocation_id) - - // All assigned allocations - ->checkIfRecordIsSelectableUsing(fn (Allocation $allocation) => $allocation->server_id === null) - ->searchable() - ->columns([ - Tables\Columns\TextColumn::make('id'), - Tables\Columns\TextColumn::make('port') - ->searchable() - ->label('Port'), - Tables\Columns\TextColumn::make('server.name') - ->label('Server') - ->icon('tabler-brand-docker') - ->searchable() - ->url(fn (Allocation $allocation): string => $allocation->server ? route('filament.admin.resources.servers.edit', ['record' => $allocation->server]) : ''), - Tables\Columns\TextInputColumn::make('ip_alias') - ->searchable() - ->label('Alias'), - Tables\Columns\TextInputColumn::make('ip') - ->searchable() - ->label('IP'), - ]) - ->filters([ - // - ]) - ->actions([ - // - ]) - ->headerActions([ - Tables\Actions\Action::make('create new allocation')->label('Create Allocations') - ->form(fn () => [ - Forms\Components\TextInput::make('allocation_ip') - ->datalist($this->getOwnerRecord()->ipAddresses() ?? []) - ->label('IP Address') - ->inlineLabel() - ->ipv4() - ->helperText("Usually your machine's public IP unless you are port forwarding.") - ->required(), - Forms\Components\TextInput::make('allocation_alias') - ->label('Alias') - ->inlineLabel() - ->default(null) - ->helperText('Optional display name to help you remember what these are.') - ->required(false), - Forms\Components\TagsInput::make('allocation_ports') - ->placeholder('Examples: 27015, 27017-27019') - ->helperText(new HtmlString(' - These are the ports that users can connect to this Server through. -
- You would have to port forward these on your home network. - ')) - ->label('Ports') - ->inlineLabel() - ->live() - ->afterStateUpdated(function ($state, Forms\Set $set) { - $ports = collect(); - $update = false; - foreach ($state as $portEntry) { - if (!str_contains($portEntry, '-')) { - if (is_numeric($portEntry)) { - $ports->push((int) $portEntry); - - continue; - } - - // Do not add non numerical ports - $update = true; - - continue; - } - - $update = true; - [$start, $end] = explode('-', $portEntry); - if (!is_numeric($start) || !is_numeric($end)) { - continue; - } - - $start = max((int) $start, 0); - $end = min((int) $end, 2 ** 16 - 1); - foreach (range($start, $end) as $i) { - $ports->push($i); - } - } - - $uniquePorts = $ports->unique()->values(); - if ($ports->count() > $uniquePorts->count()) { - $update = true; - $ports = $uniquePorts; - } - - $sortedPorts = $ports->sort()->values(); - if ($sortedPorts->all() !== $ports->all()) { - $update = true; - $ports = $sortedPorts; - } - - $ports = $ports->filter(fn ($port) => $port > 1024 && $port < 65535)->values(); - - if ($update) { - $set('allocation_ports', $ports->all()); - } - }) - ->splitKeys(['Tab', ' ', ',']) - ->required(), - ]) - ->action(fn (array $data) => resolve(AssignmentService::class)->handle($this->getOwnerRecord(), $data)), - ]) - ->bulkActions([ - Tables\Actions\BulkActionGroup::make([ - // Tables\Actions\DissociateBulkAction::make(), - Tables\Actions\DeleteBulkAction::make(), - ]), - ]); - } -} diff --git a/app/Filament/Resources/ServerResource/Pages/EditServer.php b/app/Filament/Resources/ServerResource/Pages/EditServer.php index e425a0331..ee6dec068 100644 --- a/app/Filament/Resources/ServerResource/Pages/EditServer.php +++ b/app/Filament/Resources/ServerResource/Pages/EditServer.php @@ -745,13 +745,6 @@ class EditServer extends EditRecord return $data; } - public function getRelationManagers(): array - { - return [ - ServerResource\RelationManagers\AllocationsRelationManager::class, - ]; - } - private function shouldHideComponent(Forms\Get $get, Forms\Components\Component $component): bool { $containsRuleIn = str($get('rules'))->explode('|')->reduce( diff --git a/app/Filament/Resources/ServerResource/RelationManagers/AllocationsRelationManager.php b/app/Filament/Resources/ServerResource/RelationManagers/AllocationsRelationManager.php deleted file mode 100644 index ef200f841..000000000 --- a/app/Filament/Resources/ServerResource/RelationManagers/AllocationsRelationManager.php +++ /dev/null @@ -1,75 +0,0 @@ -schema([ - Forms\Components\TextInput::make('ip') - ->required() - ->maxLength(255), - ]); - } - - public function table(Table $table): Table - { - return $table - ->recordTitleAttribute('ip') - ->recordTitle(fn (Allocation $allocation) => "$allocation->ip:$allocation->port") - ->checkIfRecordIsSelectableUsing(fn (Allocation $record) => $record->id !== $this->getOwnerRecord()->allocation_id) - // ->actions - // ->groups - ->inverseRelationship('server') - ->columns([ - Tables\Columns\TextColumn::make('ip')->label('IP'), - Tables\Columns\TextColumn::make('port')->label('Port'), - Tables\Columns\TextInputColumn::make('ip_alias')->label('Alias'), - Tables\Columns\IconColumn::make('primary') - ->icon(fn ($state) => match ($state) { - false => 'tabler-star', - true => 'tabler-star-filled', - }) - ->color(fn ($state) => match ($state) { - false => 'gray', - true => 'warning', - }) - ->action(fn (Allocation $allocation) => $this->getOwnerRecord()->update(['allocation_id' => $allocation->id])) - ->default(fn (Allocation $allocation) => $allocation->id === $this->getOwnerRecord()->allocation_id) - ->label('Primary'), - ]) - ->filters([ - // - ]) - ->actions([ - Tables\Actions\Action::make('make-primary') - ->action(fn (Allocation $allocation) => $this->getOwnerRecord()->update(['allocation_id' => $allocation->id])) - ->label(fn (Allocation $allocation) => $allocation->id === $this->getOwnerRecord()->allocation_id ? '' : 'Make Primary'), - ]) - ->headerActions([ - //TODO Tables\Actions\CreateAction::make()->label('Create Allocation'), - Tables\Actions\AssociateAction::make() - ->multiple() - ->preloadRecordSelect() - ->recordSelectOptionsQuery(fn ($query) => $query->whereBelongsTo($this->getOwnerRecord()->node)) - ->label('Add Allocation'), - ]) - ->bulkActions([ - Tables\Actions\BulkActionGroup::make([ - Tables\Actions\DissociateBulkAction::make(), - Tables\Actions\DeleteBulkAction::make(), - ]), - ]); - } -}