mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 05:14:46 +02:00
Better IP addresses (#800)
* Unique ip addresses * Only ipv4 addresses for now * Switch to selects
This commit is contained in:
parent
c953b97009
commit
5d2b892eab
@ -5,6 +5,7 @@ namespace App\Filament\Admin\Resources\NodeResource\RelationManagers;
|
|||||||
use App\Models\Allocation;
|
use App\Models\Allocation;
|
||||||
use App\Models\Node;
|
use App\Models\Node;
|
||||||
use App\Services\Allocations\AssignmentService;
|
use App\Services\Allocations\AssignmentService;
|
||||||
|
use Filament\Forms\Components\Select;
|
||||||
use Filament\Forms\Components\TagsInput;
|
use Filament\Forms\Components\TagsInput;
|
||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
@ -73,8 +74,8 @@ 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')
|
Select::make('allocation_ip')
|
||||||
->datalist($this->getOwnerRecord()->ipAddresses())
|
->options(collect($this->getOwnerRecord()->ipAddresses())->mapWithKeys(fn (string $ip) => [$ip => $ip]))
|
||||||
->label('IP Address')
|
->label('IP Address')
|
||||||
->inlineLabel()
|
->inlineLabel()
|
||||||
->ipv4()
|
->ipv4()
|
||||||
|
@ -192,13 +192,12 @@ class CreateServer extends CreateRecord
|
|||||||
->whereNull('server_id'),
|
->whereNull('server_id'),
|
||||||
)
|
)
|
||||||
->createOptionForm(fn (Get $get) => [
|
->createOptionForm(fn (Get $get) => [
|
||||||
TextInput::make('allocation_ip')
|
Select::make('allocation_ip')
|
||||||
->datalist(Node::find($get('node_id'))?->ipAddresses() ?? [])
|
->options(collect(Node::find($get('node_id'))?->ipAddresses())->mapWithKeys(fn (string $ip) => [$ip => $ip]))
|
||||||
->label('IP Address')
|
->label('IP Address')
|
||||||
->inlineLabel()
|
->inlineLabel()
|
||||||
->ipv4()
|
->ipv4()
|
||||||
->helperText("Usually your machine's public IP unless you are port forwarding.")
|
->helperText("Usually your machine's public IP unless you are port forwarding.")
|
||||||
// ->selectablePlaceholder(false)
|
|
||||||
->required(),
|
->required(),
|
||||||
TextInput::make('allocation_alias')
|
TextInput::make('allocation_alias')
|
||||||
->label('Alias')
|
->label('Alias')
|
||||||
|
@ -5,6 +5,7 @@ namespace App\Filament\Admin\Resources\ServerResource\RelationManagers;
|
|||||||
use App\Models\Allocation;
|
use App\Models\Allocation;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Services\Allocations\AssignmentService;
|
use App\Services\Allocations\AssignmentService;
|
||||||
|
use Filament\Forms\Components\Select;
|
||||||
use Filament\Forms\Components\TagsInput;
|
use Filament\Forms\Components\TagsInput;
|
||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
@ -71,8 +72,8 @@ class AllocationsRelationManager extends RelationManager
|
|||||||
CreateAction::make()->label('Create Allocation')
|
CreateAction::make()->label('Create Allocation')
|
||||||
->createAnother(false)
|
->createAnother(false)
|
||||||
->form(fn () => [
|
->form(fn () => [
|
||||||
TextInput::make('allocation_ip')
|
Select::make('allocation_ip')
|
||||||
->datalist($this->getOwnerRecord()->node->ipAddresses())
|
->options(collect($this->getOwnerRecord()->node->ipAddresses())->mapWithKeys(fn (string $ip) => [$ip => $ip]))
|
||||||
->label('IP Address')
|
->label('IP Address')
|
||||||
->inlineLabel()
|
->inlineLabel()
|
||||||
->ipv4()
|
->ipv4()
|
||||||
|
@ -384,7 +384,10 @@ class Node extends Model
|
|||||||
// pass
|
// pass
|
||||||
}
|
}
|
||||||
|
|
||||||
return $ips->all();
|
// Only IPV4
|
||||||
|
$ips = $ips->filter(fn (string $ip) => filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false);
|
||||||
|
|
||||||
|
return $ips->unique()->all();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user