Skip to content

Commit 8313991

Browse files
committed
clean up front-end port allocation handling
1 parent 2fb223c commit 8313991

File tree

5 files changed

+95
-54
lines changed

5 files changed

+95
-54
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
1313
* Prevent clicking server start button until server is completely off, not just stopping.
1414
* Upon successful creation of a node it will redirect to the allocation tab and display a clearer message to add allocations.
1515
* Trying to add a new node if no location exists redirects user to location management page and alerts them to add a location first.
16+
* `Server\AjaxController@postSetConnection` is now `Server\AjaxController@postSetPrimary` and accepts one post parameter of `allocation` rather than a combined `ip:port` value.
17+
* Port allocations on server view are now cleaner and should make more sense.
1618

1719
### Fixed
1820
* Team Fortress named 'Insurgency' in panel in database seeder. ([#96](https://github.com/Pterodactyl/Panel/issues/96), PR by [@MeltedLux](https://github.com/MeltedLux))

app/Http/Controllers/Server/AjaxController.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,35 +171,40 @@ public function postSaveFile(Request $request, $uuid)
171171
}
172172

173173
/**
174-
* [postSetConnection description]
174+
* [postSetPrimary description]
175175
* @param Request $request
176176
* @param string $uuid
177177
* @return \Illuminate\Http\Response
178178
*/
179-
public function postSetConnection(Request $request, $uuid)
179+
public function postSetPrimary(Request $request, $uuid)
180180
{
181181

182182
$server = Models\Server::getByUUID($uuid);
183-
$allocation = Models\Allocation::findOrFail($server->allocation);
184-
185183
$this->authorize('set-connection', $server);
186184

187-
if ($request->input('connection') === $allocation->ip . ':' . $allocation->port) {
185+
if ((int) $request->input('allocation') === $server->allocation) {
188186
return response()->json([
189187
'error' => 'You are already using this as your default connection.'
190188
], 409);
191189
}
192190

193191
try {
192+
$allocation = Models\Allocation::where('id', $request->input('allocation'))->where('assigned_to', $server->id)->first();
193+
if (!$allocation) {
194+
return response()->json([
195+
'error' => 'No allocation matching your request was found in the system.'
196+
], 422);
197+
}
198+
194199
$repo = new Repositories\ServerRepository;
195200
$repo->changeBuild($server->id, [
196-
'default' => $request->input('connection'),
201+
'default' => $allocation->ip . ':' . $allocation->port,
197202
]);
198203
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.');
199204
} catch (DisplayValidationException $ex) {
200205
return response()->json([
201206
'error' => json_decode($ex->getMessage(), true),
202-
], 503);
207+
], 422);
203208
} catch (DisplayException $ex) {
204209
return response()->json([
205210
'error' => $ex->getMessage(),

app/Http/Routes/ServerRoutes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ public function map(Router $router) {
154154
]);
155155

156156
// Sets the Default Connection for the Server
157-
$router->post('set-connection', [
158-
'uses' => 'Server\AjaxController@postSetConnection'
157+
$router->post('set-primary', [
158+
'uses' => 'Server\AjaxController@postSetPrimary'
159159
]);
160160

161161
$router->post('settings/reset-database-password', [

public/themes/default/css/pterodactyl.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,17 @@ li.btn.btn-default.pill:active,li.btn.btn-default.pill:focus,li.btn.btn-default.
185185
.text-v-center {
186186
vertical-align: middle !important;
187187
}
188+
189+
.muted {
190+
filter: alpha(opacity=20);
191+
opacity: 0.2;
192+
}
193+
194+
.muted-hover:hover {
195+
filter: alpha(opacity=100);
196+
opacity: 1;
197+
}
198+
199+
.use-pointer {
200+
cursor: pointer !important;
201+
}

resources/views/server/index.blade.php

Lines changed: 65 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,36 @@
8080
<div class="panel-heading"></div>
8181
<div class="panel-body">
8282
<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>
83-
<ul class="nav nav-pills nav-stacked" id="conn_options">
83+
<table class="table table-hover">
84+
<tr>
85+
<th>IP Address</th>
86+
<th>Alias</th>
87+
<th>Port</th>
88+
<th></th>
89+
</tr>
8490
@foreach ($allocations as $allocation)
85-
<li role="presentation" @if($allocation->id === $server->allocation) class="active" @endif>
86-
<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
87-
<span class="badge">{{ $allocation->port }}</span>
88-
@if(!is_null($allocation->ip_alias))<small><span class="pull-right">Alias for {{ $allocation->ip }}</span></small>@endif
89-
</a>
90-
</li>
91+
<tr>
92+
<td>
93+
<code>{{ $allocation->ip }}</code>
94+
</td>
95+
<td @if(is_null($allocation->ip_alias))class="muted"@endif>
96+
@if(is_null($allocation->ip_alias))
97+
<span class="label label-default">none</span>
98+
@else
99+
<code>{{ $allocation->ip_alias }}</code>
100+
@endif
101+
</td>
102+
<td><code>{{ $allocation->port }}</code></td>
103+
<td class="col-xs-2">
104+
@if($allocation->id === $server->allocation)
105+
<span class="label label-primary is-primary" data-allocation="{{ $allocation->id }}">Primary</span>
106+
@else
107+
<span class="label label-success muted muted-hover use-pointer" data-action="set-connection" data-allocation="{{ $allocation->id }}">Make Primary</span>
108+
@endif
109+
</td>
110+
</tr>
91111
@endforeach
92-
</ul>
112+
</table>
93113
</div>
94114
</div>
95115
</div>
@@ -351,7 +371,6 @@ function (callback) {
351371
// Update Listings on Initial Status
352372
socket.on('initial_status', function (data) {
353373
currentStatus = data.status;
354-
console.log(data.status);
355374
if (data.status !== 0) {
356375
$.ajax({
357376
type: 'GET',
@@ -394,45 +413,46 @@ function updatePlayerListVisibility(data) {
394413
395414
@can('set-allocation', $server)
396415
// Send Request
397-
$('[data-action="set-connection"]').click(function (event) {
398-
event.preventDefault();
399-
var element = $(this);
400-
if (element.hasClass('active')) {
401-
return;
402-
}
416+
function handleChange() {
417+
$('[data-action="set-connection"]').click(function (event) {
418+
event.preventDefault();
419+
var element = $(this);
403420
404-
$.ajax({
405-
method: 'POST',
406-
url: '/server/{{ $server->uuidShort }}/ajax/set-connection',
407-
data: {
408-
connection: element.data('connection')
409-
},
410-
headers: {
411-
'X-CSRF-TOKEN': '{{ csrf_token() }}'
412-
}
413-
}).done(function (data) {
414-
swal({
415-
type: 'success',
416-
title: '',
417-
text: data
418-
});
419-
$('#conn_options').find('li.active').removeClass('active');
420-
element.parent().addClass('active');
421-
}).fail(function (jqXHR) {
422-
console.error(jqXHR);
423-
var respError;
424-
if (typeof jqXHR.responseJSON.error === 'undefined' || jqXHR.responseJSON.error === '') {
425-
respError = 'An error occured while attempting to perform this action.';
426-
} else {
427-
respError = jqXHR.responseJSON.error;
428-
}
429-
swal({
430-
type: 'error',
431-
title: 'Whoops!',
432-
text: respError
421+
$.ajax({
422+
method: 'POST',
423+
url: '/server/{{ $server->uuidShort }}/ajax/set-primary',
424+
data: {
425+
allocation: element.data('allocation')
426+
},
427+
headers: {
428+
'X-CSRF-TOKEN': '{{ csrf_token() }}'
429+
}
430+
}).done(function (data) {
431+
swal({
432+
type: 'success',
433+
title: '',
434+
text: data
435+
});
436+
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');
437+
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');
438+
handleChange();
439+
}).fail(function (jqXHR) {
440+
console.error(jqXHR);
441+
var respError;
442+
if (typeof jqXHR.responseJSON.error === 'undefined' || jqXHR.responseJSON.error === '') {
443+
respError = 'An error occured while attempting to perform this action.';
444+
} else {
445+
respError = jqXHR.responseJSON.error;
446+
}
447+
swal({
448+
type: 'error',
449+
title: 'Whoops!',
450+
text: respError
451+
});
433452
});
434453
});
435-
});
454+
}
455+
handleChange();
436456
@endcan
437457
438458
var can_run = true;

0 commit comments

Comments
 (0)