Add back server sidebar list
This commit is contained in:
parent
5b6d3b8325
commit
a1e704d3a7
6 changed files with 99 additions and 18 deletions
|
@ -13,6 +13,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
|
|||
### Added
|
||||
* Adds ability to include egg variables on an API request.
|
||||
* Added `external_id` column to servers that allows for easier linking with external services such as WHMCS.
|
||||
* Added back the sidebar when viewing servers that allows for quick-switching to a different server.
|
||||
|
||||
## v0.7.1 (Derelict Dermodactylus)
|
||||
### Fixed
|
||||
|
|
|
@ -103,9 +103,10 @@ interface ServerRepositoryInterface extends RepositoryInterface, SearchableInter
|
|||
*
|
||||
* @param \Pterodactyl\Models\User $user
|
||||
* @param int $level
|
||||
* @return \Illuminate\Pagination\LengthAwarePaginator
|
||||
* @param bool $paginate
|
||||
* @return \Illuminate\Pagination\LengthAwarePaginator|\Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function filterUserAccessServers(User $user, int $level): LengthAwarePaginator;
|
||||
public function filterUserAccessServers(User $user, int $level, bool $paginate = true);
|
||||
|
||||
/**
|
||||
* Return a server by UUID.
|
||||
|
|
51
app/Http/ViewComposers/ServerListComposer.php
Normal file
51
app/Http/ViewComposers/ServerListComposer.php
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Http\ViewComposers;
|
||||
|
||||
use Illuminate\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
use Pterodactyl\Models\User;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
|
||||
class ServerListComposer
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Http\Request
|
||||
*/
|
||||
private $request;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ServerListComposer constructor.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
|
||||
*/
|
||||
public function __construct(Request $request, ServerRepositoryInterface $repository)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach a list of servers the user can access to the view.
|
||||
*
|
||||
* @param \Illuminate\View\View $view
|
||||
*/
|
||||
public function compose(View $view)
|
||||
{
|
||||
if (! $this->request->user()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$servers = $this->repository
|
||||
->setColumns(['id', 'owner_id', 'uuidShort', 'name', 'description'])
|
||||
->filterUserAccessServers($this->request->user(), User::FILTER_LEVEL_SUBUSER, false);
|
||||
|
||||
$view->with('sidebarServerList', $servers);
|
||||
}
|
||||
}
|
|
@ -1,15 +1,9 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Pterodactyl\Http\ViewComposers\ServerListComposer;
|
||||
use Pterodactyl\Http\ViewComposers\Server\ServerDataComposer;
|
||||
|
||||
class ViewComposerServiceProvider extends ServiceProvider
|
||||
|
@ -20,5 +14,8 @@ class ViewComposerServiceProvider extends ServiceProvider
|
|||
public function boot()
|
||||
{
|
||||
$this->app->make('view')->composer('server.*', ServerDataComposer::class);
|
||||
|
||||
// Add data to make the sidebar work when viewing a server.
|
||||
$this->app->make('view')->composer(['server.*'], ServerListComposer::class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -211,11 +211,12 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt
|
|||
*
|
||||
* @param \Pterodactyl\Models\User $user
|
||||
* @param int $level
|
||||
* @return \Illuminate\Pagination\LengthAwarePaginator
|
||||
* @param bool $paginate
|
||||
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function filterUserAccessServers(User $user, int $level): LengthAwarePaginator
|
||||
public function filterUserAccessServers(User $user, int $level, bool $paginate = true)
|
||||
{
|
||||
$instance = $this->getBuilder()->with(['user']);
|
||||
$instance = $this->getBuilder()->select($this->getColumns())->with(['user']);
|
||||
|
||||
// If access level is set to owner, only display servers
|
||||
// that the user owns.
|
||||
|
@ -224,8 +225,9 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt
|
|||
}
|
||||
|
||||
// If set to all, display all servers they can access, including
|
||||
// those they access as an admin. If set to subuser, only return the servers they can access because
|
||||
// they are owner, or marked as a subuser of the server.
|
||||
// those they access as an admin. If set to subuser, only return
|
||||
// the servers they can access because they are owner, or marked
|
||||
// as a subuser of the server.
|
||||
elseif (($level === User::FILTER_LEVEL_ALL && ! $user->root_admin) || $level === User::FILTER_LEVEL_SUBUSER) {
|
||||
$instance->whereIn('id', $this->getUserAccessServers($user->id));
|
||||
}
|
||||
|
@ -236,7 +238,9 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt
|
|||
$instance->whereNotIn('id', $this->getUserAccessServers($user->id));
|
||||
}
|
||||
|
||||
return $instance->search($this->getSearchTerm())->paginate(25);
|
||||
$instance->search($this->getSearchTerm());
|
||||
|
||||
return $paginate ? $instance->paginate(25) : $instance->get();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -60,9 +60,13 @@
|
|||
<span class="hidden-xs">{{ Auth::user()->name_first }} {{ Auth::user()->name_last }}</span>
|
||||
</a>
|
||||
</li>
|
||||
{{--<li>--}}
|
||||
{{--<a href="#" data-action="control-sidebar" data-toggle="tooltip" data-placement="bottom" title="@lang('strings.servers')"><i class="fa fa-server"></i></a>--}}
|
||||
{{--</li>--}}
|
||||
@if(isset($sidebarServerList))
|
||||
<li>
|
||||
<a href="#" data-toggle="control-sidebar">
|
||||
<i class="fa fa-server"></i>
|
||||
</a>
|
||||
</li>
|
||||
@endif
|
||||
@if(Auth::user()->root_admin)
|
||||
<li>
|
||||
<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 @@
|
|||
</div>
|
||||
Copyright © 2015 - {{ date('Y') }} <a href="https://pterodactyl.io/">Pterodactyl Software</a>.
|
||||
</footer>
|
||||
@if(isset($sidebarServerList))
|
||||
<aside class="control-sidebar control-sidebar-dark">
|
||||
<div class="tab-content">
|
||||
<ul class="control-sidebar-menu">
|
||||
@foreach($sidebarServerList as $sidebarServer)
|
||||
<li>
|
||||
<a href="{{ route('server.index', $sidebarServer->uuidShort) }}" @if(isset($server) && $sidebarServer->id === $server->id)class="active"@endif>
|
||||
@if($sidebarServer->owner_id === Auth::user()->id)
|
||||
<i class="menu-icon fa fa-user bg-blue"></i>
|
||||
@else
|
||||
<i class="menu-icon fa fa-user-o bg-gray"></i>
|
||||
@endif
|
||||
<div class="menu-info">
|
||||
<h4 class="control-sidebar-subheading">{{ str_limit($sidebarServer->name, 20) }}</h4>
|
||||
<p>{{ str_limit($sidebarServer->description, 20) }}</p>
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
</aside>
|
||||
@endif
|
||||
<div class="control-sidebar-bg"></div>
|
||||
</div>
|
||||
@section('footer-scripts')
|
||||
|
|
Loading…
Reference in a new issue