mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-11-04 17:06:52 +01:00 
			
		
		
		
	pint
This commit is contained in:
		
							parent
							
								
									a787af7a06
								
							
						
					
					
						commit
						8ed6bb4d8b
					
				@ -46,7 +46,7 @@ class AllocationsRelationManager extends RelationManager
 | 
				
			|||||||
            // ->checkIfRecordIsSelectableUsing(fn (Allocation $allocation) => $allocation->id !== $allocation->server?->allocation_id)
 | 
					            // ->checkIfRecordIsSelectableUsing(fn (Allocation $allocation) => $allocation->id !== $allocation->server?->allocation_id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // All assigned allocations
 | 
					            // All assigned allocations
 | 
				
			||||||
            ->checkIfRecordIsSelectableUsing(fn(Allocation $allocation) => $allocation->server_id === null)
 | 
					            ->checkIfRecordIsSelectableUsing(fn (Allocation $allocation) => $allocation->server_id === null)
 | 
				
			||||||
            ->searchable()
 | 
					            ->searchable()
 | 
				
			||||||
            ->selectCurrentPageOnly() //Prevent people from trying to nuke 30,000 ports at once.... -,-
 | 
					            ->selectCurrentPageOnly() //Prevent people from trying to nuke 30,000 ports at once.... -,-
 | 
				
			||||||
            ->columns([
 | 
					            ->columns([
 | 
				
			||||||
@ -58,7 +58,7 @@ class AllocationsRelationManager extends RelationManager
 | 
				
			|||||||
                    ->label('Server')
 | 
					                    ->label('Server')
 | 
				
			||||||
                    ->icon('tabler-brand-docker')
 | 
					                    ->icon('tabler-brand-docker')
 | 
				
			||||||
                    ->searchable()
 | 
					                    ->searchable()
 | 
				
			||||||
                    ->url(fn(Allocation $allocation): string => $allocation->server ? route('filament.admin.resources.servers.edit', ['record' => $allocation->server]) : ''),
 | 
					                    ->url(fn (Allocation $allocation): string => $allocation->server ? route('filament.admin.resources.servers.edit', ['record' => $allocation->server]) : ''),
 | 
				
			||||||
                TextInputColumn::make('ip_alias')
 | 
					                TextInputColumn::make('ip_alias')
 | 
				
			||||||
                    ->searchable()
 | 
					                    ->searchable()
 | 
				
			||||||
                    ->label('Alias'),
 | 
					                    ->label('Alias'),
 | 
				
			||||||
@ -68,7 +68,7 @@ class AllocationsRelationManager extends RelationManager
 | 
				
			|||||||
            ])
 | 
					            ])
 | 
				
			||||||
            ->headerActions([
 | 
					            ->headerActions([
 | 
				
			||||||
                Tables\Actions\Action::make('create new allocation')->label('Create Allocations')
 | 
					                Tables\Actions\Action::make('create new allocation')->label('Create Allocations')
 | 
				
			||||||
                    ->form(fn() => [
 | 
					                    ->form(fn () => [
 | 
				
			||||||
                        TextInput::make('allocation_ip')
 | 
					                        TextInput::make('allocation_ip')
 | 
				
			||||||
                            ->datalist($this->getOwnerRecord()->ipAddresses())
 | 
					                            ->datalist($this->getOwnerRecord()->ipAddresses())
 | 
				
			||||||
                            ->label('IP Address')
 | 
					                            ->label('IP Address')
 | 
				
			||||||
@ -98,7 +98,7 @@ class AllocationsRelationManager extends RelationManager
 | 
				
			|||||||
                                foreach ($state as $portEntry) {
 | 
					                                foreach ($state as $portEntry) {
 | 
				
			||||||
                                    if (!str_contains($portEntry, '-')) {
 | 
					                                    if (!str_contains($portEntry, '-')) {
 | 
				
			||||||
                                        if (is_numeric($portEntry)) {
 | 
					                                        if (is_numeric($portEntry)) {
 | 
				
			||||||
                                            $ports->push((int)$portEntry);
 | 
					                                            $ports->push((int) $portEntry);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                                            continue;
 | 
					                                            continue;
 | 
				
			||||||
                                        }
 | 
					                                        }
 | 
				
			||||||
@ -115,8 +115,8 @@ class AllocationsRelationManager extends RelationManager
 | 
				
			|||||||
                                        continue;
 | 
					                                        continue;
 | 
				
			||||||
                                    }
 | 
					                                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                                    $start = max((int)$start, 0);
 | 
					                                    $start = max((int) $start, 0);
 | 
				
			||||||
                                    $end = min((int)$end, 2 ** 16 - 1);
 | 
					                                    $end = min((int) $end, 2 ** 16 - 1);
 | 
				
			||||||
                                    foreach (range($start, $end) as $i) {
 | 
					                                    foreach (range($start, $end) as $i) {
 | 
				
			||||||
                                        $ports->push($i);
 | 
					                                        $ports->push($i);
 | 
				
			||||||
                                    }
 | 
					                                    }
 | 
				
			||||||
@ -134,7 +134,7 @@ class AllocationsRelationManager extends RelationManager
 | 
				
			|||||||
                                    $ports = $sortedPorts;
 | 
					                                    $ports = $sortedPorts;
 | 
				
			||||||
                                }
 | 
					                                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                                $ports = $ports->filter(fn($port) => $port > 1024 && $port < 65535)->values();
 | 
					                                $ports = $ports->filter(fn ($port) => $port > 1024 && $port < 65535)->values();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                                if ($update) {
 | 
					                                if ($update) {
 | 
				
			||||||
                                    $set('allocation_ports', $ports->all());
 | 
					                                    $set('allocation_ports', $ports->all());
 | 
				
			||||||
@ -143,12 +143,12 @@ class AllocationsRelationManager extends RelationManager
 | 
				
			|||||||
                            ->splitKeys(['Tab', ' ', ','])
 | 
					                            ->splitKeys(['Tab', ' ', ','])
 | 
				
			||||||
                            ->required(),
 | 
					                            ->required(),
 | 
				
			||||||
                    ])
 | 
					                    ])
 | 
				
			||||||
                    ->action(fn(array $data, AssignmentService $service) => $service->handle($this->getOwnerRecord(), $data)),
 | 
					                    ->action(fn (array $data, AssignmentService $service) => $service->handle($this->getOwnerRecord(), $data)),
 | 
				
			||||||
            ])
 | 
					            ])
 | 
				
			||||||
            ->bulkActions([
 | 
					            ->bulkActions([
 | 
				
			||||||
                BulkActionGroup::make([
 | 
					                BulkActionGroup::make([
 | 
				
			||||||
                    DeleteBulkAction::make()
 | 
					                    DeleteBulkAction::make()
 | 
				
			||||||
                        ->authorize(fn() => auth()->user()->can('delete allocation')),
 | 
					                        ->authorize(fn () => auth()->user()->can('delete allocation')),
 | 
				
			||||||
                ]),
 | 
					                ]),
 | 
				
			||||||
            ]);
 | 
					            ]);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -42,35 +42,35 @@ class AllocationsRelationManager extends RelationManager
 | 
				
			|||||||
        return $table
 | 
					        return $table
 | 
				
			||||||
            ->selectCurrentPageOnly()
 | 
					            ->selectCurrentPageOnly()
 | 
				
			||||||
            ->recordTitleAttribute('ip')
 | 
					            ->recordTitleAttribute('ip')
 | 
				
			||||||
            ->recordTitle(fn(Allocation $allocation) => "$allocation->ip:$allocation->port")
 | 
					            ->recordTitle(fn (Allocation $allocation) => "$allocation->ip:$allocation->port")
 | 
				
			||||||
            ->checkIfRecordIsSelectableUsing(fn(Allocation $record) => $record->id !== $this->getOwnerRecord()->allocation_id)
 | 
					            ->checkIfRecordIsSelectableUsing(fn (Allocation $record) => $record->id !== $this->getOwnerRecord()->allocation_id)
 | 
				
			||||||
            ->inverseRelationship('server')
 | 
					            ->inverseRelationship('server')
 | 
				
			||||||
            ->columns([
 | 
					            ->columns([
 | 
				
			||||||
                TextColumn::make('ip')->label('IP'),
 | 
					                TextColumn::make('ip')->label('IP'),
 | 
				
			||||||
                TextColumn::make('port')->label('Port'),
 | 
					                TextColumn::make('port')->label('Port'),
 | 
				
			||||||
                TextInputColumn::make('ip_alias')->label('Alias'),
 | 
					                TextInputColumn::make('ip_alias')->label('Alias'),
 | 
				
			||||||
                IconColumn::make('primary')
 | 
					                IconColumn::make('primary')
 | 
				
			||||||
                    ->icon(fn($state) => match ($state) {
 | 
					                    ->icon(fn ($state) => match ($state) {
 | 
				
			||||||
                        true => 'tabler-star-filled',
 | 
					                        true => 'tabler-star-filled',
 | 
				
			||||||
                        default => 'tabler-star',
 | 
					                        default => 'tabler-star',
 | 
				
			||||||
                    })
 | 
					                    })
 | 
				
			||||||
                    ->color(fn($state) => match ($state) {
 | 
					                    ->color(fn ($state) => match ($state) {
 | 
				
			||||||
                        true => 'warning',
 | 
					                        true => 'warning',
 | 
				
			||||||
                        default => 'gray',
 | 
					                        default => 'gray',
 | 
				
			||||||
                    })
 | 
					                    })
 | 
				
			||||||
                    ->action(fn(Allocation $allocation) => $this->getOwnerRecord()->update(['allocation_id' => $allocation->id]) && $this->deselectAllTableRecords())
 | 
					                    ->action(fn (Allocation $allocation) => $this->getOwnerRecord()->update(['allocation_id' => $allocation->id]) && $this->deselectAllTableRecords())
 | 
				
			||||||
                    ->default(fn(Allocation $allocation) => $allocation->id === $this->getOwnerRecord()->allocation_id)
 | 
					                    ->default(fn (Allocation $allocation) => $allocation->id === $this->getOwnerRecord()->allocation_id)
 | 
				
			||||||
                    ->label('Primary'),
 | 
					                    ->label('Primary'),
 | 
				
			||||||
            ])
 | 
					            ])
 | 
				
			||||||
            ->actions([
 | 
					            ->actions([
 | 
				
			||||||
                Action::make('make-primary')
 | 
					                Action::make('make-primary')
 | 
				
			||||||
                    ->action(fn(Allocation $allocation) => $this->getOwnerRecord()->update(['allocation_id' => $allocation->id]) && $this->deselectAllTableRecords())
 | 
					                    ->action(fn (Allocation $allocation) => $this->getOwnerRecord()->update(['allocation_id' => $allocation->id]) && $this->deselectAllTableRecords())
 | 
				
			||||||
                    ->label(fn(Allocation $allocation) => $allocation->id === $this->getOwnerRecord()->allocation_id ? '' : 'Make Primary'),
 | 
					                    ->label(fn (Allocation $allocation) => $allocation->id === $this->getOwnerRecord()->allocation_id ? '' : 'Make Primary'),
 | 
				
			||||||
            ])
 | 
					            ])
 | 
				
			||||||
            ->headerActions([
 | 
					            ->headerActions([
 | 
				
			||||||
                CreateAction::make()->label('Create Allocation')
 | 
					                CreateAction::make()->label('Create Allocation')
 | 
				
			||||||
                    ->createAnother(false)
 | 
					                    ->createAnother(false)
 | 
				
			||||||
                    ->form(fn() => [
 | 
					                    ->form(fn () => [
 | 
				
			||||||
                        TextInput::make('allocation_ip')
 | 
					                        TextInput::make('allocation_ip')
 | 
				
			||||||
                            ->datalist($this->getOwnerRecord()->node->ipAddresses())
 | 
					                            ->datalist($this->getOwnerRecord()->node->ipAddresses())
 | 
				
			||||||
                            ->label('IP Address')
 | 
					                            ->label('IP Address')
 | 
				
			||||||
@ -100,7 +100,7 @@ class AllocationsRelationManager extends RelationManager
 | 
				
			|||||||
                                foreach ($state as $portEntry) {
 | 
					                                foreach ($state as $portEntry) {
 | 
				
			||||||
                                    if (!str_contains($portEntry, '-')) {
 | 
					                                    if (!str_contains($portEntry, '-')) {
 | 
				
			||||||
                                        if (is_numeric($portEntry)) {
 | 
					                                        if (is_numeric($portEntry)) {
 | 
				
			||||||
                                            $ports->push((int)$portEntry);
 | 
					                                            $ports->push((int) $portEntry);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                                            continue;
 | 
					                                            continue;
 | 
				
			||||||
                                        }
 | 
					                                        }
 | 
				
			||||||
@ -117,8 +117,8 @@ class AllocationsRelationManager extends RelationManager
 | 
				
			|||||||
                                        continue;
 | 
					                                        continue;
 | 
				
			||||||
                                    }
 | 
					                                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                                    $start = max((int)$start, 0);
 | 
					                                    $start = max((int) $start, 0);
 | 
				
			||||||
                                    $end = min((int)$end, 2 ** 16 - 1);
 | 
					                                    $end = min((int) $end, 2 ** 16 - 1);
 | 
				
			||||||
                                    foreach (range($start, $end) as $i) {
 | 
					                                    foreach (range($start, $end) as $i) {
 | 
				
			||||||
                                        $ports->push($i);
 | 
					                                        $ports->push($i);
 | 
				
			||||||
                                    }
 | 
					                                    }
 | 
				
			||||||
@ -136,7 +136,7 @@ class AllocationsRelationManager extends RelationManager
 | 
				
			|||||||
                                    $ports = $sortedPorts;
 | 
					                                    $ports = $sortedPorts;
 | 
				
			||||||
                                }
 | 
					                                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                                $ports = $ports->filter(fn($port) => $port > 1024 && $port < 65535)->values();
 | 
					                                $ports = $ports->filter(fn ($port) => $port > 1024 && $port < 65535)->values();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                                if ($update) {
 | 
					                                if ($update) {
 | 
				
			||||||
                                    $set('allocation_ports', $ports->all());
 | 
					                                    $set('allocation_ports', $ports->all());
 | 
				
			||||||
@ -145,12 +145,12 @@ class AllocationsRelationManager extends RelationManager
 | 
				
			|||||||
                            ->splitKeys(['Tab', ' ', ','])
 | 
					                            ->splitKeys(['Tab', ' ', ','])
 | 
				
			||||||
                            ->required(),
 | 
					                            ->required(),
 | 
				
			||||||
                    ])
 | 
					                    ])
 | 
				
			||||||
                    ->action(fn(array $data, AssignmentService $service) => $service->handle($this->getOwnerRecord()->node, $data, $this->getOwnerRecord())),
 | 
					                    ->action(fn (array $data, AssignmentService $service) => $service->handle($this->getOwnerRecord()->node, $data, $this->getOwnerRecord())),
 | 
				
			||||||
                AssociateAction::make()
 | 
					                AssociateAction::make()
 | 
				
			||||||
                    ->multiple()
 | 
					                    ->multiple()
 | 
				
			||||||
                    ->associateAnother(false)
 | 
					                    ->associateAnother(false)
 | 
				
			||||||
                    ->preloadRecordSelect()
 | 
					                    ->preloadRecordSelect()
 | 
				
			||||||
                    ->recordSelectOptionsQuery(fn($query) => $query->whereBelongsTo($this->getOwnerRecord()->node)->whereNull('server_id'))
 | 
					                    ->recordSelectOptionsQuery(fn ($query) => $query->whereBelongsTo($this->getOwnerRecord()->node)->whereNull('server_id'))
 | 
				
			||||||
                    ->label('Add Allocation'),
 | 
					                    ->label('Add Allocation'),
 | 
				
			||||||
            ])
 | 
					            ])
 | 
				
			||||||
            ->bulkActions([
 | 
					            ->bulkActions([
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user