clean up front-end port allocation handling
This commit is contained in:
parent
2fb223c99b
commit
831399184f
5 changed files with 95 additions and 54 deletions
|
@ -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))
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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', [
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -80,16 +80,36 @@
|
|||
<div class="panel-heading"></div>
|
||||
<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>
|
||||
<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)
|
||||
<li role="presentation" @if($allocation->id === $server->allocation) class="active" @endif>
|
||||
<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
|
||||
<span class="badge">{{ $allocation->port }}</span>
|
||||
@if(!is_null($allocation->ip_alias))<small><span class="pull-right">Alias for {{ $allocation->ip }}</span></small>@endif
|
||||
</a>
|
||||
</li>
|
||||
<tr>
|
||||
<td>
|
||||
<code>{{ $allocation->ip }}</code>
|
||||
</td>
|
||||
<td @if(is_null($allocation->ip_alias))class="muted"@endif>
|
||||
@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
|
||||
</ul>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue