From 99497adcb2a070d038695e9011b015cb97c17c2f Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Fri, 17 Feb 2017 20:34:57 -0500 Subject: [PATCH] Show proper server status when viewing listing. closes #308 --- app/Http/Controllers/Server/AjaxController.php | 8 ++++++++ app/Http/Routes/ServerRoutes.php | 13 +++++++------ public/themes/pterodactyl/js/frontend/serverlist.js | 9 ++++++++- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/Server/AjaxController.php b/app/Http/Controllers/Server/AjaxController.php index d18aee7bf..8f3736da7 100644 --- a/app/Http/Controllers/Server/AjaxController.php +++ b/app/Http/Controllers/Server/AjaxController.php @@ -73,6 +73,14 @@ class AjaxController extends Controller return response()->json([], 404); } + if (! $server->installed) { + return response()->json(['status' => 20]); + } + + if ($server->suspended) { + return response()->json(['status' => 30]); + } + try { $res = $server->guzzleClient()->request('GET', '/server'); if ($res->getStatusCode() === 200) { diff --git a/app/Http/Routes/ServerRoutes.php b/app/Http/Routes/ServerRoutes.php index 284822db4..36c95827b 100644 --- a/app/Http/Routes/ServerRoutes.php +++ b/app/Http/Routes/ServerRoutes.php @@ -30,6 +30,13 @@ class ServerRoutes { public function map(Router $router) { + // Returns Server Status + $router->get('/server/{server}/ajax/status', [ + 'middleware' => ['auth', 'csrf'], + 'as' => 'server.ajax.status', + 'uses' => 'Server\AjaxController@getStatus', + ]); + $router->group([ 'prefix' => 'server/{server}', 'middleware' => [ @@ -164,12 +171,6 @@ class ServerRoutes // Assorted AJAX Routes $router->group(['prefix' => 'ajax'], function ($server) use ($router) { - // Returns Server Status - $router->get('status', [ - 'as' => 'server.ajax.status', - 'uses' => 'Server\AjaxController@getStatus', - ]); - // Sets the Default Connection for the Server $router->post('set-primary', [ 'uses' => 'Server\AjaxController@postSetPrimary', diff --git a/public/themes/pterodactyl/js/frontend/serverlist.js b/public/themes/pterodactyl/js/frontend/serverlist.js index 605c33d2f..fc2ae0aff 100644 --- a/public/themes/pterodactyl/js/frontend/serverlist.js +++ b/public/themes/pterodactyl/js/frontend/serverlist.js @@ -28,6 +28,7 @@ var Status = { $('.dynamic-update').each(function (index, data) { var element = $(this); var serverShortUUID = $(this).data('server'); + $.ajax({ type: 'GET', url: Router.route('server.ajax.status', { server: serverShortUUID }), @@ -53,8 +54,14 @@ var Status = { case 3: element.find('[data-action="status"]').html('Stopping'); break; + case 20: + element.find('[data-action="status"]').html('Installing'); + break; + case 30: + element.find('[data-action="status"]').html('Suspended'); + break; } - if (data.status !== 0) { + if (data.status > 0 && data.status < 4) { var cpuMax = element.find('[data-action="cpu"]').data('cpumax'); var currentCpu = data.proc.cpu.total; if (cpuMax !== 0) {