This commit is contained in:
notCharles 2024-11-13 16:22:12 -05:00
parent a787af7a06
commit 8ed6bb4d8b
2 changed files with 24 additions and 24 deletions

View File

@ -46,7 +46,7 @@ class AllocationsRelationManager extends RelationManager
// ->checkIfRecordIsSelectableUsing(fn (Allocation $allocation) => $allocation->id !== $allocation->server?->allocation_id)
// All assigned allocations
->checkIfRecordIsSelectableUsing(fn(Allocation $allocation) => $allocation->server_id === null)
->checkIfRecordIsSelectableUsing(fn (Allocation $allocation) => $allocation->server_id === null)
->searchable()
->selectCurrentPageOnly() //Prevent people from trying to nuke 30,000 ports at once.... -,-
->columns([
@ -58,7 +58,7 @@ class AllocationsRelationManager extends RelationManager
->label('Server')
->icon('tabler-brand-docker')
->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')
->searchable()
->label('Alias'),
@ -68,7 +68,7 @@ class AllocationsRelationManager extends RelationManager
])
->headerActions([
Tables\Actions\Action::make('create new allocation')->label('Create Allocations')
->form(fn() => [
->form(fn () => [
TextInput::make('allocation_ip')
->datalist($this->getOwnerRecord()->ipAddresses())
->label('IP Address')
@ -98,7 +98,7 @@ class AllocationsRelationManager extends RelationManager
foreach ($state as $portEntry) {
if (!str_contains($portEntry, '-')) {
if (is_numeric($portEntry)) {
$ports->push((int)$portEntry);
$ports->push((int) $portEntry);
continue;
}
@ -115,8 +115,8 @@ class AllocationsRelationManager extends RelationManager
continue;
}
$start = max((int)$start, 0);
$end = min((int)$end, 2 ** 16 - 1);
$start = max((int) $start, 0);
$end = min((int) $end, 2 ** 16 - 1);
foreach (range($start, $end) as $i) {
$ports->push($i);
}
@ -134,7 +134,7 @@ class AllocationsRelationManager extends RelationManager
$ports = $sortedPorts;
}
$ports = $ports->filter(fn($port) => $port > 1024 && $port < 65535)->values();
$ports = $ports->filter(fn ($port) => $port > 1024 && $port < 65535)->values();
if ($update) {
$set('allocation_ports', $ports->all());
@ -143,12 +143,12 @@ class AllocationsRelationManager extends RelationManager
->splitKeys(['Tab', ' ', ','])
->required(),
])
->action(fn(array $data, AssignmentService $service) => $service->handle($this->getOwnerRecord(), $data)),
->action(fn (array $data, AssignmentService $service) => $service->handle($this->getOwnerRecord(), $data)),
])
->bulkActions([
BulkActionGroup::make([
DeleteBulkAction::make()
->authorize(fn() => auth()->user()->can('delete allocation')),
->authorize(fn () => auth()->user()->can('delete allocation')),
]),
]);
}

View File

@ -42,35 +42,35 @@ class AllocationsRelationManager extends RelationManager
return $table
->selectCurrentPageOnly()
->recordTitleAttribute('ip')
->recordTitle(fn(Allocation $allocation) => "$allocation->ip:$allocation->port")
->checkIfRecordIsSelectableUsing(fn(Allocation $record) => $record->id !== $this->getOwnerRecord()->allocation_id)
->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) {
->icon(fn ($state) => match ($state) {
true => 'tabler-star-filled',
default => 'tabler-star',
})
->color(fn($state) => match ($state) {
->color(fn ($state) => match ($state) {
true => 'warning',
default => 'gray',
})
->action(fn(Allocation $allocation) => $this->getOwnerRecord()->update(['allocation_id' => $allocation->id]) && $this->deselectAllTableRecords())
->default(fn(Allocation $allocation) => $allocation->id === $this->getOwnerRecord()->allocation_id)
->action(fn (Allocation $allocation) => $this->getOwnerRecord()->update(['allocation_id' => $allocation->id]) && $this->deselectAllTableRecords())
->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]) && $this->deselectAllTableRecords())
->label(fn(Allocation $allocation) => $allocation->id === $this->getOwnerRecord()->allocation_id ? '' : 'Make Primary'),
->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'),
])
->headerActions([
CreateAction::make()->label('Create Allocation')
->createAnother(false)
->form(fn() => [
->form(fn () => [
TextInput::make('allocation_ip')
->datalist($this->getOwnerRecord()->node->ipAddresses())
->label('IP Address')
@ -100,7 +100,7 @@ class AllocationsRelationManager extends RelationManager
foreach ($state as $portEntry) {
if (!str_contains($portEntry, '-')) {
if (is_numeric($portEntry)) {
$ports->push((int)$portEntry);
$ports->push((int) $portEntry);
continue;
}
@ -117,8 +117,8 @@ class AllocationsRelationManager extends RelationManager
continue;
}
$start = max((int)$start, 0);
$end = min((int)$end, 2 ** 16 - 1);
$start = max((int) $start, 0);
$end = min((int) $end, 2 ** 16 - 1);
foreach (range($start, $end) as $i) {
$ports->push($i);
}
@ -136,7 +136,7 @@ class AllocationsRelationManager extends RelationManager
$ports = $sortedPorts;
}
$ports = $ports->filter(fn($port) => $port > 1024 && $port < 65535)->values();
$ports = $ports->filter(fn ($port) => $port > 1024 && $port < 65535)->values();
if ($update) {
$set('allocation_ports', $ports->all());
@ -145,12 +145,12 @@ class AllocationsRelationManager extends RelationManager
->splitKeys(['Tab', ' ', ','])
->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()
->multiple()
->associateAnother(false)
->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'),
])
->bulkActions([