mirror of
https://github.com/pelican-dev/panel.git
synced 2025-11-12 16:44:54 +01:00
Thank you merge conflict
This commit is contained in:
parent
50ffaf4d01
commit
a42cb193a3
@ -1,160 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Filament\Resources\NodeResource\RelationManagers;
|
|
||||||
|
|
||||||
use App\Models\Allocation;
|
|
||||||
use App\Models\Node;
|
|
||||||
use App\Services\Allocations\AssignmentService;
|
|
||||||
use Filament\Forms\Components\TagsInput;
|
|
||||||
use Filament\Forms\Components\TextInput;
|
|
||||||
use Filament\Forms\Form;
|
|
||||||
use Filament\Forms\Set;
|
|
||||||
use Filament\Resources\RelationManagers\RelationManager;
|
|
||||||
use Filament\Tables;
|
|
||||||
use Filament\Tables\Actions\BulkActionGroup;
|
|
||||||
use Filament\Tables\Actions\DeleteBulkAction;
|
|
||||||
use Filament\Tables\Columns\TextColumn;
|
|
||||||
use Filament\Tables\Columns\TextInputColumn;
|
|
||||||
use Filament\Tables\Table;
|
|
||||||
use Illuminate\Support\HtmlString;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @method Node getOwnerRecord()
|
|
||||||
*/
|
|
||||||
class AllocationsRelationManager extends RelationManager
|
|
||||||
{
|
|
||||||
protected static string $relationship = 'allocations';
|
|
||||||
|
|
||||||
protected static ?string $icon = 'tabler-plug-connected';
|
|
||||||
|
|
||||||
public function form(Form $form): Form
|
|
||||||
{
|
|
||||||
return $form
|
|
||||||
->schema([
|
|
||||||
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([
|
|
||||||
TextColumn::make('id'),
|
|
||||||
TextColumn::make('port')
|
|
||||||
->searchable()
|
|
||||||
->label('Port'),
|
|
||||||
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]) : ''),
|
|
||||||
TextInputColumn::make('ip_alias')
|
|
||||||
->searchable()
|
|
||||||
->label('Alias'),
|
|
||||||
TextInputColumn::make('ip')
|
|
||||||
->searchable()
|
|
||||||
->label('IP'),
|
|
||||||
])
|
|
||||||
->filters([
|
|
||||||
//
|
|
||||||
])
|
|
||||||
->actions([
|
|
||||||
//
|
|
||||||
])
|
|
||||||
->headerActions([
|
|
||||||
Tables\Actions\Action::make('create new allocation')->label('Create Allocations')
|
|
||||||
->form(fn () => [
|
|
||||||
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(),
|
|
||||||
TextInput::make('allocation_alias')
|
|
||||||
->label('Alias')
|
|
||||||
->inlineLabel()
|
|
||||||
->default(null)
|
|
||||||
->helperText('Optional display name to help you remember what these are.')
|
|
||||||
->required(false),
|
|
||||||
TagsInput::make('allocation_ports')
|
|
||||||
->placeholder('Examples: 27015, 27017-27019')
|
|
||||||
->helperText(new HtmlString('
|
|
||||||
These are the ports that users can connect to this Server through.
|
|
||||||
<br />
|
|
||||||
You would have to port forward these on your home network.
|
|
||||||
'))
|
|
||||||
->label('Ports')
|
|
||||||
->inlineLabel()
|
|
||||||
->live()
|
|
||||||
->afterStateUpdated(function ($state, 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([
|
|
||||||
BulkActionGroup::make([
|
|
||||||
DeleteBulkAction::make()
|
|
||||||
->authorize(fn () => auth()->user()->can('delete allocation')),
|
|
||||||
]),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,161 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Filament\Resources\ServerResource\RelationManagers;
|
|
||||||
|
|
||||||
use App\Models\Allocation;
|
|
||||||
use App\Models\Server;
|
|
||||||
use App\Services\Allocations\AssignmentService;
|
|
||||||
use Filament\Forms\Components\TagsInput;
|
|
||||||
use Filament\Forms\Components\TextInput;
|
|
||||||
use Filament\Forms\Form;
|
|
||||||
use Filament\Forms\Set;
|
|
||||||
use Filament\Resources\RelationManagers\RelationManager;
|
|
||||||
use Filament\Tables;
|
|
||||||
use Filament\Tables\Actions\Action;
|
|
||||||
use Filament\Tables\Actions\AssociateAction;
|
|
||||||
use Filament\Tables\Actions\CreateAction;
|
|
||||||
use Filament\Tables\Columns\IconColumn;
|
|
||||||
use Filament\Tables\Columns\TextColumn;
|
|
||||||
use Filament\Tables\Columns\TextInputColumn;
|
|
||||||
use Filament\Tables\Table;
|
|
||||||
use Illuminate\Support\HtmlString;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @method Server getOwnerRecord()
|
|
||||||
*/
|
|
||||||
class AllocationsRelationManager extends RelationManager
|
|
||||||
{
|
|
||||||
protected static string $relationship = 'allocations';
|
|
||||||
|
|
||||||
public function form(Form $form): Form
|
|
||||||
{
|
|
||||||
return $form
|
|
||||||
->schema([
|
|
||||||
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)
|
|
||||||
->inverseRelationship('server')
|
|
||||||
->columns([
|
|
||||||
TextColumn::make('ip')->label('IP'),
|
|
||||||
TextColumn::make('port')->label('Port'),
|
|
||||||
TextInputColumn::make('ip_alias')->label('Alias'),
|
|
||||||
IconColumn::make('primary')
|
|
||||||
->icon(fn ($state) => match ($state) {
|
|
||||||
true => 'tabler-star-filled',
|
|
||||||
default => 'tabler-star',
|
|
||||||
})
|
|
||||||
->color(fn ($state) => match ($state) {
|
|
||||||
true => 'warning',
|
|
||||||
default => 'gray',
|
|
||||||
})
|
|
||||||
->action(fn (Allocation $allocation) => $this->getOwnerRecord()->update(['allocation_id' => $allocation->id]))
|
|
||||||
->default(fn (Allocation $allocation) => $allocation->id === $this->getOwnerRecord()->allocation_id)
|
|
||||||
->label('Primary'),
|
|
||||||
])
|
|
||||||
->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([
|
|
||||||
CreateAction::make()->label('Create Allocation')
|
|
||||||
->createAnother(false)
|
|
||||||
->form(fn () => [
|
|
||||||
TextInput::make('allocation_ip')
|
|
||||||
->datalist($this->getOwnerRecord()->node->ipAddresses())
|
|
||||||
->label('IP Address')
|
|
||||||
->inlineLabel()
|
|
||||||
->ipv4()
|
|
||||||
->helperText("Usually your machine's public IP unless you are port forwarding.")
|
|
||||||
->required(),
|
|
||||||
TextInput::make('allocation_alias')
|
|
||||||
->label('Alias')
|
|
||||||
->inlineLabel()
|
|
||||||
->default(null)
|
|
||||||
->helperText('Optional display name to help you remember what these are.')
|
|
||||||
->required(false),
|
|
||||||
TagsInput::make('allocation_ports')
|
|
||||||
->placeholder('Examples: 27015, 27017-27019')
|
|
||||||
->helperText(new HtmlString('
|
|
||||||
These are the ports that users can connect to this Server through.
|
|
||||||
<br />
|
|
||||||
You would have to port forward these on your home network.
|
|
||||||
'))
|
|
||||||
->label('Ports')
|
|
||||||
->inlineLabel()
|
|
||||||
->live()
|
|
||||||
->afterStateUpdated(function ($state, 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()->node, $data, $this->getOwnerRecord())),
|
|
||||||
AssociateAction::make()
|
|
||||||
->multiple()
|
|
||||||
->associateAnother(false)
|
|
||||||
->preloadRecordSelect()
|
|
||||||
->recordSelectOptionsQuery(fn ($query) => $query->whereBelongsTo($this->getOwnerRecord()->node))
|
|
||||||
->label('Add Allocation'),
|
|
||||||
])
|
|
||||||
->bulkActions([
|
|
||||||
Tables\Actions\BulkActionGroup::make([
|
|
||||||
Tables\Actions\DissociateBulkAction::make(),
|
|
||||||
]),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user