From 831399184f83d9012a4bac49033eae92a047cb7c Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Fri, 30 Sep 2016 18:21:02 -0400 Subject: [PATCH] clean up front-end port allocation handling --- CHANGELOG.md | 2 + .../Controllers/Server/AjaxController.php | 19 +-- app/Http/Routes/ServerRoutes.php | 4 +- public/themes/default/css/pterodactyl.css | 14 +++ resources/views/server/index.blade.php | 110 +++++++++++------- 5 files changed, 95 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a61ce2026..027d9c0a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. * Prevent clicking server start button until server is completely off, not just stopping. * Upon successful creation of a node it will redirect to the allocation tab and display a clearer message to add allocations. * Trying to add a new node if no location exists redirects user to location management page and alerts them to add a location first. +* `Server\AjaxController@postSetConnection` is now `Server\AjaxController@postSetPrimary` and accepts one post parameter of `allocation` rather than a combined `ip:port` value. +* Port allocations on server view are now cleaner and should make more sense. ### Fixed * Team Fortress named 'Insurgency' in panel in database seeder. ([#96](https://github.com/Pterodactyl/Panel/issues/96), PR by [@MeltedLux](https://github.com/MeltedLux)) diff --git a/app/Http/Controllers/Server/AjaxController.php b/app/Http/Controllers/Server/AjaxController.php index baf745922..dd81c2184 100644 --- a/app/Http/Controllers/Server/AjaxController.php +++ b/app/Http/Controllers/Server/AjaxController.php @@ -171,35 +171,40 @@ class AjaxController extends Controller } /** - * [postSetConnection description] + * [postSetPrimary description] * @param Request $request * @param string $uuid * @return \Illuminate\Http\Response */ - public function postSetConnection(Request $request, $uuid) + public function postSetPrimary(Request $request, $uuid) { $server = Models\Server::getByUUID($uuid); - $allocation = Models\Allocation::findOrFail($server->allocation); - $this->authorize('set-connection', $server); - if ($request->input('connection') === $allocation->ip . ':' . $allocation->port) { + if ((int) $request->input('allocation') === $server->allocation) { return response()->json([ 'error' => 'You are already using this as your default connection.' ], 409); } try { + $allocation = Models\Allocation::where('id', $request->input('allocation'))->where('assigned_to', $server->id)->first(); + if (!$allocation) { + return response()->json([ + 'error' => 'No allocation matching your request was found in the system.' + ], 422); + } + $repo = new Repositories\ServerRepository; $repo->changeBuild($server->id, [ - 'default' => $request->input('connection'), + 'default' => $allocation->ip . ':' . $allocation->port, ]); return response('The default connection for this server has been updated. Please be aware that you will need to restart your server for this change to go into effect.'); } catch (DisplayValidationException $ex) { return response()->json([ 'error' => json_decode($ex->getMessage(), true), - ], 503); + ], 422); } catch (DisplayException $ex) { return response()->json([ 'error' => $ex->getMessage(), diff --git a/app/Http/Routes/ServerRoutes.php b/app/Http/Routes/ServerRoutes.php index 9707d4447..5a454fcd1 100644 --- a/app/Http/Routes/ServerRoutes.php +++ b/app/Http/Routes/ServerRoutes.php @@ -154,8 +154,8 @@ class ServerRoutes { ]); // Sets the Default Connection for the Server - $router->post('set-connection', [ - 'uses' => 'Server\AjaxController@postSetConnection' + $router->post('set-primary', [ + 'uses' => 'Server\AjaxController@postSetPrimary' ]); $router->post('settings/reset-database-password', [ diff --git a/public/themes/default/css/pterodactyl.css b/public/themes/default/css/pterodactyl.css index 6284089f9..0a5530468 100755 --- a/public/themes/default/css/pterodactyl.css +++ b/public/themes/default/css/pterodactyl.css @@ -185,3 +185,17 @@ li.btn.btn-default.pill:active,li.btn.btn-default.pill:focus,li.btn.btn-default. .text-v-center { vertical-align: middle !important; } + +.muted { + filter: alpha(opacity=20); + opacity: 0.2; +} + +.muted-hover:hover { + filter: alpha(opacity=100); + opacity: 1; +} + +.use-pointer { + cursor: pointer !important; +} diff --git a/resources/views/server/index.blade.php b/resources/views/server/index.blade.php index 0355e9b1f..92eb1bdc1 100644 --- a/resources/views/server/index.blade.php +++ b/resources/views/server/index.blade.php @@ -80,16 +80,36 @@
Below is a listing of all avaliable IPs and Ports for your service. To change the default connection address for your server, simply click on the one you would like to make default below.
-
@@ -351,7 +371,6 @@ $(window).load(function () { // Update Listings on Initial Status socket.on('initial_status', function (data) { currentStatus = data.status; - console.log(data.status); if (data.status !== 0) { $.ajax({ type: 'GET', @@ -394,45 +413,46 @@ $(window).load(function () { @can('set-allocation', $server) // Send Request - $('[data-action="set-connection"]').click(function (event) { - event.preventDefault(); - var element = $(this); - if (element.hasClass('active')) { - return; - } + function handleChange() { + $('[data-action="set-connection"]').click(function (event) { + event.preventDefault(); + var element = $(this); - $.ajax({ - method: 'POST', - url: '/server/{{ $server->uuidShort }}/ajax/set-connection', - data: { - connection: element.data('connection') - }, - headers: { - 'X-CSRF-TOKEN': '{{ csrf_token() }}' - } - }).done(function (data) { - swal({ - type: 'success', - title: '', - text: data - }); - $('#conn_options').find('li.active').removeClass('active'); - element.parent().addClass('active'); - }).fail(function (jqXHR) { - console.error(jqXHR); - var respError; - if (typeof jqXHR.responseJSON.error === 'undefined' || jqXHR.responseJSON.error === '') { - respError = 'An error occured while attempting to perform this action.'; - } else { - respError = jqXHR.responseJSON.error; - } - swal({ - type: 'error', - title: 'Whoops!', - text: respError + $.ajax({ + method: 'POST', + url: '/server/{{ $server->uuidShort }}/ajax/set-primary', + data: { + allocation: element.data('allocation') + }, + headers: { + 'X-CSRF-TOKEN': '{{ csrf_token() }}' + } + }).done(function (data) { + swal({ + type: 'success', + title: '', + text: data + }); + element.parents().eq(2).find('.is-primary').addClass('muted muted-hover label-success use-pointer').attr('data-action', 'set-connection').data('action', 'set-connection').removeClass('label-primary is-primary').html('Make Primary'); + element.removeClass('muted muted-hover label-success use-pointer').attr('data-action', 'do-nothing').data('action', 'do-nothing').addClass('label-primary is-primary').html('Primary'); + handleChange(); + }).fail(function (jqXHR) { + console.error(jqXHR); + var respError; + if (typeof jqXHR.responseJSON.error === 'undefined' || jqXHR.responseJSON.error === '') { + respError = 'An error occured while attempting to perform this action.'; + } else { + respError = jqXHR.responseJSON.error; + } + swal({ + type: 'error', + title: 'Whoops!', + text: respError + }); }); }); - }); + } + handleChange(); @endcan var can_run = true;