diff --git a/app/Http/Controllers/Admin/NodesController.php b/app/Http/Controllers/Admin/NodesController.php index 402cd6659..8b97e7f92 100644 --- a/app/Http/Controllers/Admin/NodesController.php +++ b/app/Http/Controllers/Admin/NodesController.php @@ -67,6 +67,23 @@ class NodesController extends Controller public function getView(Request $request, $id) { $node = Models\Node::findOrFail($id); + $allocations = []; + $alloc = Models\Allocation::select('ip', 'port', 'assigned_to')->where('node', $node->id)->get(); + if ($alloc) { + foreach($alloc as &$alloc) { + if (!array_key_exists($alloc->ip, $allocations)) { + $allocations[$alloc->ip] = [[ + 'port' => $alloc->port, + 'assigned_to' => $alloc->assigned_to + ]]; + } else { + array_push($allocations[$alloc->ip], [ + 'port' => $alloc->port, + 'assigned_to' => $alloc->assigned_to + ]); + } + } + } return view('admin.nodes.view', [ 'node' => $node, 'servers' => Models\Server::select('servers.*', 'users.email as a_ownerEmail', 'services.name as a_serviceName') @@ -75,6 +92,7 @@ class NodesController extends Controller ->where('node', $id)->paginate(10), 'stats' => Models\Server::select(DB::raw('SUM(memory) as memory, SUM(disk) as disk'))->where('node', $node->id)->first(), 'locations' => Models\Location::all(), + 'allocations' => json_decode(json_encode($allocations), false), ]); } @@ -104,4 +122,16 @@ class NodesController extends Controller ])->withInput(); } + public function deletePortAllocation(Request $request, $id, $ip, $port) + { + $allocation = Models\Allocation::where('node', $id)->whereNull('assigned_to')->where('ip', $ip)->where('port', $port)->first(); + if (!$allocation) { + return response()->json([ + 'error' => 'Unable to find an allocation matching those details to delete.' + ], 400); + } + $allocation->delete(); + return response('', 204); + } + } diff --git a/app/Http/Routes/AdminRoutes.php b/app/Http/Routes/AdminRoutes.php index bf4131a1e..ffc21220c 100644 --- a/app/Http/Routes/AdminRoutes.php +++ b/app/Http/Routes/AdminRoutes.php @@ -172,6 +172,10 @@ class AdminRoutes { 'uses' => 'Admin\NodesController@postView' ]); + $router->delete('/view/{id}/allocation/{ip}/{port}', [ + 'uses' => 'Admin\NodesController@deletePortAllocation' + ]); + }); } diff --git a/resources/views/admin/nodes/view.blade.php b/resources/views/admin/nodes/view.blade.php index fd6357c73..8880ee6dc 100644 --- a/resources/views/admin/nodes/view.blade.php +++ b/resources/views/admin/nodes/view.blade.php @@ -285,7 +285,42 @@
IP Address | +Ports | ++ + + @foreach($allocations as $ip => $ports) + |
{{ $ip }} | +
+ @foreach($ports as $id => $allocation)
+ @if (($id % 2) === 0)
+ @if($allocation->assigned_to === null)
+ {{ $allocation->port }} + @else + {{ $allocation->port }} + @endif + @endif + @endforeach + |
+
+ @foreach($ports as $id => $allocation)
+ @if (($id % 2) === 1)
+ @if($allocation->assigned_to === null)
+ {{ $allocation->port }} + @else + {{ $allocation->port }} + @endif + @endif + @endforeach + |
+