From ac2abd89e6b0dc441417fda243c541ec7ff195ef Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 5 Nov 2017 14:12:53 -0600 Subject: [PATCH] Fix bug listing allocations when making a new server. closes #730 --- CHANGELOG.md | 1 + .../Repository/NodeRepositoryInterface.php | 5 ++--- .../Controllers/Admin/ServersController.php | 12 +----------- app/Repositories/Eloquent/NodeRepository.php | 4 ++-- .../themes/pterodactyl/js/admin/new-server.js | 17 +++-------------- routes/admin.php | 1 - 6 files changed, 9 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 598a258b2..9a6603ab9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. * `[beta.1]` — Fixes bug that would prevent root admins from accessing servers they were not set as the owner of. * `[beta.1]` — Fixes wrong URL redirect being provided when creating a subuser. * `[beta.1]` — Fixes missing check in environment setup that would leave the Hashids salt empty. +* `[beta.1]` — Fixes bug preventing loading of allocations when trying to create a new server. ## v0.7.0-beta.1 (Derelict Dermodactylus) ### Added diff --git a/app/Contracts/Repository/NodeRepositoryInterface.php b/app/Contracts/Repository/NodeRepositoryInterface.php index 5321db084..078a274db 100644 --- a/app/Contracts/Repository/NodeRepositoryInterface.php +++ b/app/Contracts/Repository/NodeRepositoryInterface.php @@ -60,10 +60,9 @@ interface NodeRepositoryInterface extends RepositoryInterface, SearchableInterfa public function getNodeServers($id); /** - * Return a collection of nodes beloning to a specific location for use on frontend display. + * Return a collection of nodes for all locations to use in server creation UI. * - * @param int $location * @return mixed */ - public function getNodesForLocation($location); + public function getNodesForServerCreation(); } diff --git a/app/Http/Controllers/Admin/ServersController.php b/app/Http/Controllers/Admin/ServersController.php index f79d257a4..203e7058c 100644 --- a/app/Http/Controllers/Admin/ServersController.php +++ b/app/Http/Controllers/Admin/ServersController.php @@ -231,6 +231,7 @@ class ServersController extends Controller $nests = $this->nestRepository->getWithEggs(); Javascript::put([ + 'nodeData' => $this->nodeRepository->getNodesForServerCreation(), 'nests' => $nests->map(function ($item) { return array_merge($item->toArray(), [ 'eggs' => $item->eggs->keyBy('id')->toArray(), @@ -262,17 +263,6 @@ class ServersController extends Controller return redirect()->route('admin.servers.view', $server->id); } - /** - * Returns a tree of all avaliable nodes in a given location. - * - * @param \Illuminate\Http\Request $request - * @return \Illuminate\Support\Collection - */ - public function nodes(Request $request) - { - return $this->nodeRepository->getNodesForLocation($request->input('location')); - } - /** * Display the index when viewing a specific server. * diff --git a/app/Repositories/Eloquent/NodeRepository.php b/app/Repositories/Eloquent/NodeRepository.php index b6a94ec46..9a7067266 100644 --- a/app/Repositories/Eloquent/NodeRepository.php +++ b/app/Repositories/Eloquent/NodeRepository.php @@ -129,9 +129,9 @@ class NodeRepository extends EloquentRepository implements NodeRepositoryInterfa /** * {@inheritdoc} */ - public function getNodesForLocation($location) + public function getNodesForServerCreation() { - $instance = $this->getBuilder()->with('allocations')->where('location_id', $location)->get(); + $instance = $this->getBuilder()->with('allocations')->get(); return $instance->map(function ($item) { $filtered = $item->allocations->where('server_id', null)->map(function ($map) { diff --git a/public/themes/pterodactyl/js/admin/new-server.js b/public/themes/pterodactyl/js/admin/new-server.js index e15a14b73..97f05487b 100644 --- a/public/themes/pterodactyl/js/admin/new-server.js +++ b/public/themes/pterodactyl/js/admin/new-server.js @@ -29,7 +29,7 @@ $(document).ready(function() { }); $('#pNodeId').select2({ placeholder: 'Select a Node', - }); + }).change(); $('#pAllocation').select2({ placeholder: 'Select a Default Allocation', }); @@ -79,14 +79,6 @@ $(document).ready(function() { }); }); -function hideLoader() { - $('#allocationLoader').hide(); -} - -function showLoader() { - $('#allocationLoader').show(); -} - var lastActiveBox = null; $(document).on('click', function (event) { if (lastActiveBox !== null) { @@ -97,12 +89,9 @@ $(document).on('click', function (event) { lastActiveBox.addClass('box-primary'); }); -var curentNode = null; -var NodeData = []; - -$('#pNodeId').on('change', function (event) { +$('#pNodeId').on('change', function () { currentNode = $(this).val(); - $.each(NodeData, function (i, v) { + $.each(Pterodactyl.nodeData, function (i, v) { if (v.id == currentNode) { $('#pAllocation').html('').select2({ data: v.allocations, diff --git a/routes/admin.php b/routes/admin.php index 9332b82de..1dfdf9729 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -95,7 +95,6 @@ Route::group(['prefix' => 'servers'], function () { Route::get('/view/{server}/delete', 'ServersController@viewDelete')->name('admin.servers.view.delete'); Route::post('/new', 'ServersController@store'); - Route::post('/new/nodes', 'ServersController@nodes')->name('admin.servers.new.nodes'); Route::post('/view/{server}/build', 'ServersController@updateBuild'); Route::post('/view/{server}/startup', 'ServersController@saveStartup'); Route::post('/view/{server}/database', 'ServersController@newDatabase');