Skip to content

Commit a1e704d

Browse files
committed
Add back server sidebar list
1 parent 5b6d3b8 commit a1e704d

File tree

6 files changed

+99
-18
lines changed

6 files changed

+99
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
1313
### Added
1414
* Adds ability to include egg variables on an API request.
1515
* Added `external_id` column to servers that allows for easier linking with external services such as WHMCS.
16+
* Added back the sidebar when viewing servers that allows for quick-switching to a different server.
1617

1718
## v0.7.1 (Derelict Dermodactylus)
1819
### Fixed

app/Contracts/Repository/ServerRepositoryInterface.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,10 @@ public function getDaemonServiceData(Server $server, bool $refresh = false): arr
103103
*
104104
* @param \Pterodactyl\Models\User $user
105105
* @param int $level
106-
* @return \Illuminate\Pagination\LengthAwarePaginator
106+
* @param bool $paginate
107+
* @return \Illuminate\Pagination\LengthAwarePaginator|\Illuminate\Database\Eloquent\Collection
107108
*/
108-
public function filterUserAccessServers(User $user, int $level): LengthAwarePaginator;
109+
public function filterUserAccessServers(User $user, int $level, bool $paginate = true);
109110

110111
/**
111112
* Return a server by UUID.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Pterodactyl\Http\ViewComposers;
4+
5+
use Illuminate\View\View;
6+
use Illuminate\Http\Request;
7+
use Pterodactyl\Models\User;
8+
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
9+
10+
class ServerListComposer
11+
{
12+
/**
13+
* @var \Illuminate\Http\Request
14+
*/
15+
private $request;
16+
17+
/**
18+
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
19+
*/
20+
private $repository;
21+
22+
/**
23+
* ServerListComposer constructor.
24+
*
25+
* @param \Illuminate\Http\Request $request
26+
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
27+
*/
28+
public function __construct(Request $request, ServerRepositoryInterface $repository)
29+
{
30+
$this->request = $request;
31+
$this->repository = $repository;
32+
}
33+
34+
/**
35+
* Attach a list of servers the user can access to the view.
36+
*
37+
* @param \Illuminate\View\View $view
38+
*/
39+
public function compose(View $view)
40+
{
41+
if (! $this->request->user()) {
42+
return;
43+
}
44+
45+
$servers = $this->repository
46+
->setColumns(['id', 'owner_id', 'uuidShort', 'name', 'description'])
47+
->filterUserAccessServers($this->request->user(), User::FILTER_LEVEL_SUBUSER, false);
48+
49+
$view->with('sidebarServerList', $servers);
50+
}
51+
}
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
<?php
2-
/**
3-
* Pterodactyl - Panel
4-
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5-
*
6-
* This software is licensed under the terms of the MIT license.
7-
* https://opensource.org/licenses/MIT
8-
*/
92

103
namespace Pterodactyl\Providers;
114

125
use Illuminate\Support\ServiceProvider;
6+
use Pterodactyl\Http\ViewComposers\ServerListComposer;
137
use Pterodactyl\Http\ViewComposers\Server\ServerDataComposer;
148

159
class ViewComposerServiceProvider extends ServiceProvider
@@ -20,5 +14,8 @@ class ViewComposerServiceProvider extends ServiceProvider
2014
public function boot()
2115
{
2216
$this->app->make('view')->composer('server.*', ServerDataComposer::class);
17+
18+
// Add data to make the sidebar work when viewing a server.
19+
$this->app->make('view')->composer(['server.*'], ServerListComposer::class);
2320
}
2421
}

app/Repositories/Eloquent/ServerRepository.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,12 @@ public function getDaemonServiceData(Server $server, bool $refresh = false): arr
211211
*
212212
* @param \Pterodactyl\Models\User $user
213213
* @param int $level
214-
* @return \Illuminate\Pagination\LengthAwarePaginator
214+
* @param bool $paginate
215+
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Illuminate\Database\Eloquent\Collection
215216
*/
216-
public function filterUserAccessServers(User $user, int $level): LengthAwarePaginator
217+
public function filterUserAccessServers(User $user, int $level, bool $paginate = true)
217218
{
218-
$instance = $this->getBuilder()->with(['user']);
219+
$instance = $this->getBuilder()->select($this->getColumns())->with(['user']);
219220

220221
// If access level is set to owner, only display servers
221222
// that the user owns.
@@ -224,8 +225,9 @@ public function filterUserAccessServers(User $user, int $level): LengthAwarePagi
224225
}
225226

226227
// If set to all, display all servers they can access, including
227-
// those they access as an admin. If set to subuser, only return the servers they can access because
228-
// they are owner, or marked as a subuser of the server.
228+
// those they access as an admin. If set to subuser, only return
229+
// the servers they can access because they are owner, or marked
230+
// as a subuser of the server.
229231
elseif (($level === User::FILTER_LEVEL_ALL && ! $user->root_admin) || $level === User::FILTER_LEVEL_SUBUSER) {
230232
$instance->whereIn('id', $this->getUserAccessServers($user->id));
231233
}
@@ -236,7 +238,9 @@ public function filterUserAccessServers(User $user, int $level): LengthAwarePagi
236238
$instance->whereNotIn('id', $this->getUserAccessServers($user->id));
237239
}
238240

239-
return $instance->search($this->getSearchTerm())->paginate(25);
241+
$instance->search($this->getSearchTerm());
242+
243+
return $paginate ? $instance->paginate(25) : $instance->get();
240244
}
241245

242246
/**

resources/themes/pterodactyl/layouts/master.blade.php

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,13 @@
6060
<span class="hidden-xs">{{ Auth::user()->name_first }} {{ Auth::user()->name_last }}</span>
6161
</a>
6262
</li>
63-
{{--<li>--}}
64-
{{--<a href="#" data-action="control-sidebar" data-toggle="tooltip" data-placement="bottom" title="@lang('strings.servers')"><i class="fa fa-server"></i></a>--}}
65-
{{--</li>--}}
63+
@if(isset($sidebarServerList))
64+
<li>
65+
<a href="#" data-toggle="control-sidebar">
66+
<i class="fa fa-server"></i>
67+
</a>
68+
</li>
69+
@endif
6670
@if(Auth::user()->root_admin)
6771
<li>
6872
<li><a href="{{ route('admin.index') }}" data-toggle="tooltip" data-placement="bottom" title="@lang('strings.admin_cp')"><i class="fa fa-gears"></i></a></li>
@@ -240,6 +244,29 @@ class="active"
240244
</div>
241245
Copyright &copy; 2015 - {{ date('Y') }} <a href="https://pterodactyl.io/">Pterodactyl Software</a>.
242246
</footer>
247+
@if(isset($sidebarServerList))
248+
<aside class="control-sidebar control-sidebar-dark">
249+
<div class="tab-content">
250+
<ul class="control-sidebar-menu">
251+
@foreach($sidebarServerList as $sidebarServer)
252+
<li>
253+
<a href="{{ route('server.index', $sidebarServer->uuidShort) }}" @if(isset($server) && $sidebarServer->id === $server->id)class="active"@endif>
254+
@if($sidebarServer->owner_id === Auth::user()->id)
255+
<i class="menu-icon fa fa-user bg-blue"></i>
256+
@else
257+
<i class="menu-icon fa fa-user-o bg-gray"></i>
258+
@endif
259+
<div class="menu-info">
260+
<h4 class="control-sidebar-subheading">{{ str_limit($sidebarServer->name, 20) }}</h4>
261+
<p>{{ str_limit($sidebarServer->description, 20) }}</p>
262+
</div>
263+
</a>
264+
</li>
265+
@endforeach
266+
</ul>
267+
</div>
268+
</aside>
269+
@endif
243270
<div class="control-sidebar-bg"></div>
244271
</div>
245272
@section('footer-scripts')

0 commit comments

Comments
 (0)