Skip to content

Commit edaa270

Browse files
committed
Add server descriptions, closes pterodactyl#338 🐖
🐷 https://s3.kelp.in/D0n2Z.png
1 parent 660cdca commit edaa270

File tree

7 files changed

+104
-52
lines changed

7 files changed

+104
-52
lines changed

app/Http/Controllers/Admin/ServersController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public function setDetails(Request $request, $id)
251251
$repo = new ServerRepository;
252252
try {
253253
$repo->updateDetails($id, $request->intersect([
254-
'owner_id', 'name', 'reset_token',
254+
'owner_id', 'name', 'description', 'reset_token',
255255
]));
256256

257257
Alert::success('Server details were successfully updated.')->flash();

app/Repositories/ServerRepository.php

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public function create(array $data)
8989
$validator = Validator::make($data, [
9090
'user_id' => 'required|exists:users,id',
9191
'name' => 'required|regex:/^([\w .-]{1,200})$/',
92+
'description' => 'sometimes|nullable|string',
9293
'memory' => 'required|numeric|min:0',
9394
'swap' => 'required|numeric|min:-1',
9495
'io' => 'required|numeric|min:10|max:1000',
@@ -363,6 +364,7 @@ public function updateDetails($id, array $data)
363364
$validator = Validator::make($data, [
364365
'owner_id' => 'sometimes|required|integer|exists:users,id',
365366
'name' => 'sometimes|required|regex:([\w .-]{1,200})',
367+
'description' => 'sometimes|required|string',
366368
'reset_token' => 'sometimes|required|accepted',
367369
]);
368370

@@ -384,24 +386,12 @@ public function updateDetails($id, array $data)
384386
$resetDaemonKey = true;
385387
}
386388

387-
// Update Server Owner if it was passed.
388-
if (isset($data['owner_id']) && (int) $data['owner_id'] !== $server->user->id) {
389-
$server->owner_id = $data['owner_id'];
390-
}
391-
392-
// Update Server Name if it was passed.
393-
if (isset($data['name'])) {
394-
$server->name = $data['name'];
395-
}
396-
397389
// Save our changes
398-
$server->save();
390+
$server->fill($data)->save();
399391

400392
// Do we need to update? If not, return successful.
401393
if (! $resetDaemonKey) {
402-
DB::commit();
403-
404-
return true;
394+
return DB::commit();
405395
}
406396

407397
$res = $server->node->guzzleClient([
@@ -418,16 +408,13 @@ public function updateDetails($id, array $data)
418408
]);
419409

420410
if ($res->getStatusCode() === 204) {
421-
DB::commit();
422-
423-
return true;
411+
return DB::commit();
424412
} else {
425413
throw new DisplayException('Daemon returned a a non HTTP/204 error code. HTTP/' + $res->getStatusCode());
426414
}
427415
} catch (\Exception $ex) {
428416
DB::rollBack();
429-
Log::error($ex);
430-
throw new DisplayException('An error occured while attempting to update this server\'s information.');
417+
throw $ex;
431418
}
432419
}
433420

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class AddServerDescriptionColumn extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('servers', function (Blueprint $table) {
17+
$table->text('description')->after('name');
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
Schema::table('servers', function (Blueprint $table) {
29+
$table->dropColumn('description');
30+
});
31+
}
32+
}

public/themes/pterodactyl/css/pterodactyl.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,12 @@ span[aria-labelledby="select2-pUserId-container"] {
280280
.strong {
281281
font-weight: bold !important;
282282
}
283+
284+
.server-description > td {
285+
padding-top: 0 !important;
286+
border-top: 0 !important;
287+
}
288+
289+
tr:hover + tr.server-description {
290+
background-color: #f5f5f5 !important;
291+
}

resources/themes/pterodactyl/admin/servers/new.blade.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,21 @@
4141
<h3 class="box-title">Core Details</h3>
4242
</div>
4343
<div class="box-body row">
44-
<div class="form-group col-sm-6">
45-
<label for="pName">Server Name</label>
46-
<input type="text" class="form-control" id="pName" name="name" value="{{ old('name') }}" placeholder="Server Name">
47-
<p class="small text-muted no-margin">Character limits: <code>a-z A-Z 0-9 _ - .</code> and <code>[Space]</code> (max 200 characters).</p>
48-
</div>
49-
<div class="form-group col-sm-6">
50-
<label for="pUserId">Server Owner</label>
51-
<select class="form-control" style="padding-left:0;" name="user_id" id="pUserId"></select>
44+
<div class="col-md-6">
45+
<div class="form-group">
46+
<label for="pName">Server Name</label>
47+
<input type="text" class="form-control" id="pName" name="name" value="{{ old('name') }}" placeholder="Server Name">
48+
<p class="small text-muted no-margin">Character limits: <code>a-z A-Z 0-9 _ - .</code> and <code>[Space]</code> (max 200 characters).</p>
49+
</div>
50+
<div class="form-group">
51+
<label for="pUserId">Server Owner</label>
52+
<select class="form-control" style="padding-left:0;" name="user_id" id="pUserId"></select>
53+
</div>
54+
</div>
55+
<div class="form-group col-md-6">
56+
<label for="description" class="control-label">Server Description</label>
57+
<textarea name="description" rows="3" class="form-control">{{ old('description') }}</textarea>
58+
<p class="text-muted small">A brief description of this server.</p>
5259
</div>
5360
</div>
5461
</div>

resources/themes/pterodactyl/admin/servers/view/details.blade.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@
7171
</select>
7272
<p class="text-muted small">You can change the owner of this server by changing this field to an email matching another use on this system. If you do this a new daemon security token will be generated automatically.</p>
7373
</div>
74+
<div class="form-group">
75+
<label for="description" class="control-label">Server Description</label>
76+
<textarea name="description" rows="3" class="form-control">{{ old('description', $server->description) }}</textarea>
77+
<p class="text-muted small">A brief description of this server.</p>
78+
</div>
7479
<div class="form-group">
7580
<label for="name" class="control-label">Daemon Secret Token</label>
7681
<input type="text" disabled value="{{ $server->daemonSecret }}" class="form-control" />

resources/themes/pterodactyl/base/index.blade.php

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,30 +60,35 @@
6060
<th class="text-center">@lang('strings.status')</th>
6161
</tr>
6262
@foreach($servers as $server)
63-
<tr class="dynamic-update" data-server="{{ $server->uuidShort }}">
64-
<td><code>{{ $server->uuidShort }}</code></td>
65-
<td><a href="{{ route('server.index', $server->uuidShort) }}">{{ $server->name }}</a></td>
66-
<td>{{ $server->node->name }}</td>
67-
<td><code>{{ $server->allocation->alias }}:{{ $server->allocation->port }}</code></td>
68-
<td class="text-center hidden-sm hidden-xs"><span data-action="memory">--</span> / {{ $server->memory === 0 ? '&infin;' : $server->memory }} MB</td>
69-
<td class="text-center hidden-sm hidden-xs"><span data-action="cpu" data-cpumax="{{ $server->cpu }}">--</span> %</td>
70-
<td class="text-center">
71-
@if($server->user->id === Auth::user()->id)
72-
<span class="label bg-purple">@lang('strings.owner')</span>
73-
@elseif(Auth::user()->isRootAdmin())
74-
<span class="label bg-maroon">@lang('strings.admin')</span>
75-
@else
76-
<span class="label bg-blue">@lang('strings.subuser')</span>
77-
@endif
78-
</td>
79-
<td class="text-center" data-action="status">
80-
@if($server->suspended === 1)
81-
<span class="label label-warning">@lang('strings.suspended')</span>
82-
@else
83-
<span class="label label-default"><i class="fa fa-refresh fa-fw fa-spin"></i></span>
84-
@endif
85-
</td>
86-
</tr>
63+
<tr class="dynamic-update" data-server="{{ $server->uuidShort }}">
64+
<td @if(! empty($server->description)) rowspan="2" @endif><code>{{ $server->uuidShort }}</code></td>
65+
<td><a href="{{ route('server.index', $server->uuidShort) }}">{{ $server->name }}</a></td>
66+
<td>{{ $server->node->name }}</td>
67+
<td><code>{{ $server->allocation->alias }}:{{ $server->allocation->port }}</code></td>
68+
<td class="text-center hidden-sm hidden-xs"><span data-action="memory">--</span> / {{ $server->memory === 0 ? '&infin;' : $server->memory }} MB</td>
69+
<td class="text-center hidden-sm hidden-xs"><span data-action="cpu" data-cpumax="{{ $server->cpu }}">--</span> %</td>
70+
<td class="text-center">
71+
@if($server->user->id === Auth::user()->id)
72+
<span class="label bg-purple">@lang('strings.owner')</span>
73+
@elseif(Auth::user()->isRootAdmin())
74+
<span class="label bg-maroon">@lang('strings.admin')</span>
75+
@else
76+
<span class="label bg-blue">@lang('strings.subuser')</span>
77+
@endif
78+
</td>
79+
<td class="text-center" data-action="status">
80+
@if($server->suspended === 1)
81+
<span class="label label-warning">@lang('strings.suspended')</span>
82+
@else
83+
<span class="label label-default"><i class="fa fa-refresh fa-fw fa-spin"></i></span>
84+
@endif
85+
</td>
86+
</tr>
87+
@if (! empty($server->description))
88+
<tr class="server-description">
89+
<td colspan="7"><p class="text-muted small no-margin">{{ str_limit($server->description, 400) }}</p></td>
90+
</tr>
91+
@endif
8792
@endforeach
8893
</tbody>
8994
</table>
@@ -100,5 +105,12 @@
100105

101106
@section('footer-scripts')
102107
@parent
108+
<script>
109+
$('tr.server-description').on('mouseenter mouseleave', function (event) {
110+
$(this).prev('tr').css({
111+
'background-color': (event.type === 'mouseenter') ? '#f5f5f5' : '',
112+
});
113+
});
114+
</script>
103115
{!! Theme::js('js/frontend/serverlist.js') !!}
104116
@endsection

0 commit comments

Comments
 (0)