clean up front-end port allocation handling

This commit is contained in:
Dane Everitt 2016-09-30 18:21:02 -04:00
parent 2fb223c99b
commit 831399184f
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
5 changed files with 95 additions and 54 deletions

View file

@ -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. * 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. * 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. * 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 ### 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)) * Team Fortress named 'Insurgency' in panel in database seeder. ([#96](https://github.com/Pterodactyl/Panel/issues/96), PR by [@MeltedLux](https://github.com/MeltedLux))

View file

@ -171,35 +171,40 @@ class AjaxController extends Controller
} }
/** /**
* [postSetConnection description] * [postSetPrimary description]
* @param Request $request * @param Request $request
* @param string $uuid * @param string $uuid
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function postSetConnection(Request $request, $uuid) public function postSetPrimary(Request $request, $uuid)
{ {
$server = Models\Server::getByUUID($uuid); $server = Models\Server::getByUUID($uuid);
$allocation = Models\Allocation::findOrFail($server->allocation);
$this->authorize('set-connection', $server); $this->authorize('set-connection', $server);
if ($request->input('connection') === $allocation->ip . ':' . $allocation->port) { if ((int) $request->input('allocation') === $server->allocation) {
return response()->json([ return response()->json([
'error' => 'You are already using this as your default connection.' 'error' => 'You are already using this as your default connection.'
], 409); ], 409);
} }
try { 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 = new Repositories\ServerRepository;
$repo->changeBuild($server->id, [ $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.'); 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) { } catch (DisplayValidationException $ex) {
return response()->json([ return response()->json([
'error' => json_decode($ex->getMessage(), true), 'error' => json_decode($ex->getMessage(), true),
], 503); ], 422);
} catch (DisplayException $ex) { } catch (DisplayException $ex) {
return response()->json([ return response()->json([
'error' => $ex->getMessage(), 'error' => $ex->getMessage(),

View file

@ -154,8 +154,8 @@ class ServerRoutes {
]); ]);
// Sets the Default Connection for the Server // Sets the Default Connection for the Server
$router->post('set-connection', [ $router->post('set-primary', [
'uses' => 'Server\AjaxController@postSetConnection' 'uses' => 'Server\AjaxController@postSetPrimary'
]); ]);
$router->post('settings/reset-database-password', [ $router->post('settings/reset-database-password', [

View file

@ -185,3 +185,17 @@ li.btn.btn-default.pill:active,li.btn.btn-default.pill:focus,li.btn.btn-default.
.text-v-center { .text-v-center {
vertical-align: middle !important; 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;
}

View file

@ -80,16 +80,36 @@
<div class="panel-heading"></div> <div class="panel-heading"></div>
<div class="panel-body"> <div class="panel-body">
<div class="alert alert-info">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.</div> <div class="alert alert-info">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.</div>
<ul class="nav nav-pills nav-stacked" id="conn_options"> <table class="table table-hover">
<tr>
<th>IP Address</th>
<th>Alias</th>
<th>Port</th>
<th></th>
</tr>
@foreach ($allocations as $allocation) @foreach ($allocations as $allocation)
<li role="presentation" @if($allocation->id === $server->allocation) class="active" @endif> <tr>
<a href="#/set-connnection/{{ $allocation->ip }}:{{ $allocation->port }}" data-action="set-connection" data-connection="{{ $allocation->ip }}:{{ $allocation->port }}">@if(!is_null($allocation->ip_alias)){{ $allocation->ip_alias }}@else{{ $allocation->ip }}@endif <td>
<span class="badge">{{ $allocation->port }}</span> <code>{{ $allocation->ip }}</code>
@if(!is_null($allocation->ip_alias))<small><span class="pull-right">Alias for {{ $allocation->ip }}</span></small>@endif </td>
</a> <td @if(is_null($allocation->ip_alias))class="muted"@endif>
</li> @if(is_null($allocation->ip_alias))
<span class="label label-default">none</span>
@else
<code>{{ $allocation->ip_alias }}</code>
@endif
</td>
<td><code>{{ $allocation->port }}</code></td>
<td class="col-xs-2">
@if($allocation->id === $server->allocation)
<span class="label label-primary is-primary" data-allocation="{{ $allocation->id }}">Primary</span>
@else
<span class="label label-success muted muted-hover use-pointer" data-action="set-connection" data-allocation="{{ $allocation->id }}">Make Primary</span>
@endif
</td>
</tr>
@endforeach @endforeach
</ul> </table>
</div> </div>
</div> </div>
</div> </div>
@ -351,7 +371,6 @@ $(window).load(function () {
// Update Listings on Initial Status // Update Listings on Initial Status
socket.on('initial_status', function (data) { socket.on('initial_status', function (data) {
currentStatus = data.status; currentStatus = data.status;
console.log(data.status);
if (data.status !== 0) { if (data.status !== 0) {
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
@ -394,18 +413,16 @@ $(window).load(function () {
@can('set-allocation', $server) @can('set-allocation', $server)
// Send Request // Send Request
function handleChange() {
$('[data-action="set-connection"]').click(function (event) { $('[data-action="set-connection"]').click(function (event) {
event.preventDefault(); event.preventDefault();
var element = $(this); var element = $(this);
if (element.hasClass('active')) {
return;
}
$.ajax({ $.ajax({
method: 'POST', method: 'POST',
url: '/server/{{ $server->uuidShort }}/ajax/set-connection', url: '/server/{{ $server->uuidShort }}/ajax/set-primary',
data: { data: {
connection: element.data('connection') allocation: element.data('allocation')
}, },
headers: { headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}' 'X-CSRF-TOKEN': '{{ csrf_token() }}'
@ -416,8 +433,9 @@ $(window).load(function () {
title: '', title: '',
text: data text: data
}); });
$('#conn_options').find('li.active').removeClass('active'); 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.parent().addClass('active'); 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) { }).fail(function (jqXHR) {
console.error(jqXHR); console.error(jqXHR);
var respError; var respError;
@ -433,6 +451,8 @@ $(window).load(function () {
}); });
}); });
}); });
}
handleChange();
@endcan @endcan
var can_run = true; var can_run = true;