Skip to content

Commit 22511c8

Browse files
committed
Fix allocation behavior, closes pterodactyl#712
1 parent 036bea2 commit 22511c8

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
1111
* `[beta.3]` — Fixes error handling of the settings service provider when no migrations have been run.
1212
* `[beta.3]` — Fixes validation error when trying to use 'None' as the 'Copy Script From' option for an egg script.
1313
* Fixes a design bug in the database that prevented the storage of negative numbers, thus preventing a server from being assigned unlimited swap.
14+
* Fixes a bug where the 'Assign New Allocations' box would only show IPs that were present in the current pagination block.
1415

1516
### Added
1617
* Nest and Egg listings now show the associated ID in order to make API requests easier.
1718

19+
### Changed
20+
* Changed behavior of allocation IP Address/Ports box to automatically store the value entered if a user unfocuses the field without hitting space.
21+
1822
## v0.7.0-beta.3 (Derelict Dermodactylus)
1923
### Fixed
2024
* `[beta.2]` — Fixes a bug that would cause an endless exception message stream in the console when attemping to setup environment settings in certain instances.

app/Contracts/Repository/AllocationRepositoryInterface.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,12 @@ public function assignAllocationsToServer(int $server = null, array $ids): int;
2222
* @return \Illuminate\Support\Collection
2323
*/
2424
public function getAllocationsForNode(int $node): Collection;
25+
26+
/**
27+
* Return all of the unique IPs that exist for a given node.
28+
*
29+
* @param int $node
30+
* @return \Illuminate\Support\Collection
31+
*/
32+
public function getUniqueAllocationIpsForNode(int $node): Collection;
2533
}

app/Http/Controllers/Admin/NodesController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,16 @@ public function viewConfiguration(Node $node)
210210
*
211211
* @param \Pterodactyl\Models\Node $node
212212
* @return \Illuminate\View\View
213-
*
214-
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
215213
*/
216214
public function viewAllocation(Node $node)
217215
{
218216
$this->repository->loadNodeAllocations($node);
219217
Javascript::put(['node' => collect($node)->only(['id'])]);
220218

221-
return view('admin.nodes.view.allocation', ['node' => $node]);
219+
return view('admin.nodes.view.allocation', [
220+
'allocations' => $this->allocationRepository->setColumns(['ip'])->getUniqueAllocationIpsForNode($node->id),
221+
'node' => $node,
222+
]);
222223
}
223224

224225
/**

app/Repositories/Eloquent/AllocationRepository.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,18 @@ public function getAllocationsForNode(int $node): Collection
4040
{
4141
return $this->getBuilder()->where('node_id', $node)->get($this->getColumns());
4242
}
43+
44+
/**
45+
* Return all of the unique IPs that exist for a given node.
46+
*
47+
* @param int $node
48+
* @return \Illuminate\Support\Collection
49+
*/
50+
public function getUniqueAllocationIpsForNode(int $node): Collection
51+
{
52+
return $this->getBuilder()->where('node_id', $node)
53+
->groupBy('ip')
54+
->orderByRaw('INET_ATON(ip) ASC')
55+
->get($this->getColumns());
56+
}
4357
}

resources/themes/pterodactyl/admin/nodes/view/allocation.blade.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
<label for="pAllocationIP" class="control-label">IP Address</label>
9191
<div>
9292
<select class="form-control" name="allocation_ip" id="pAllocationIP" multiple>
93-
@foreach($node->allocations->unique('ip')->values()->all() as $allocation)
93+
@foreach($allocations as $allocation)
9494
<option value="{{ $allocation->ip }}">{{ $allocation->ip }}</option>
9595
@endforeach
9696
</select>
@@ -132,7 +132,7 @@
132132
<div class="row">
133133
<div class="col-md-12">
134134
<select class="form-control" name="ip">
135-
@foreach($node->allocations->unique('ip')->values()->all() as $allocation)
135+
@foreach($allocations as $allocation)
136136
<option value="{{ $allocation->ip }}">{{ $allocation->ip }}</option>
137137
@endforeach
138138
</select>
@@ -156,10 +156,12 @@
156156
$('#pAllocationIP').select2({
157157
tags: true,
158158
maximumSelectionLength: 1,
159+
selectOnClose: true,
159160
tokenSeparators: [',', ' '],
160161
});
161162
$('#pAllocationPorts').select2({
162163
tags: true,
164+
selectOnClose: true,
163165
tokenSeparators: [',', ' '],
164166
});
165167
$('button[data-action="deallocate"]').click(function (event) {

0 commit comments

Comments
 (0)