Add back server sidebar list

This commit is contained in:
Dane Everitt 2018-02-24 13:58:48 -06:00
parent 5b6d3b8325
commit a1e704d3a7
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
6 changed files with 99 additions and 18 deletions

View file

@ -13,6 +13,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
### Added ### Added
* Adds ability to include egg variables on an API request. * 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 `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) ## v0.7.1 (Derelict Dermodactylus)
### Fixed ### Fixed

View file

@ -103,9 +103,10 @@ interface ServerRepositoryInterface extends RepositoryInterface, SearchableInter
* *
* @param \Pterodactyl\Models\User $user * @param \Pterodactyl\Models\User $user
* @param int $level * @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. * Return a server by UUID.

View 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);
}
}

View file

@ -1,15 +1,9 @@
<?php <?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; namespace Pterodactyl\Providers;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use Pterodactyl\Http\ViewComposers\ServerListComposer;
use Pterodactyl\Http\ViewComposers\Server\ServerDataComposer; use Pterodactyl\Http\ViewComposers\Server\ServerDataComposer;
class ViewComposerServiceProvider extends ServiceProvider class ViewComposerServiceProvider extends ServiceProvider
@ -20,5 +14,8 @@ class ViewComposerServiceProvider extends ServiceProvider
public function boot() public function boot()
{ {
$this->app->make('view')->composer('server.*', ServerDataComposer::class); $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);
} }
} }

View file

@ -211,11 +211,12 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt
* *
* @param \Pterodactyl\Models\User $user * @param \Pterodactyl\Models\User $user
* @param int $level * @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 // If access level is set to owner, only display servers
// that the user owns. // 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 // 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 // those they access as an admin. If set to subuser, only return
// they are owner, or marked as a subuser of the server. // 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) { elseif (($level === User::FILTER_LEVEL_ALL && ! $user->root_admin) || $level === User::FILTER_LEVEL_SUBUSER) {
$instance->whereIn('id', $this->getUserAccessServers($user->id)); $instance->whereIn('id', $this->getUserAccessServers($user->id));
} }
@ -236,7 +238,9 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt
$instance->whereNotIn('id', $this->getUserAccessServers($user->id)); $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();
} }
/** /**

View file

@ -60,9 +60,13 @@
<span class="hidden-xs">{{ Auth::user()->name_first }} {{ Auth::user()->name_last }}</span> <span class="hidden-xs">{{ Auth::user()->name_first }} {{ Auth::user()->name_last }}</span>
</a> </a>
</li> </li>
{{--<li>--}} @if(isset($sidebarServerList))
{{--<a href="#" data-action="control-sidebar" data-toggle="tooltip" data-placement="bottom" title="@lang('strings.servers')"><i class="fa fa-server"></i></a>--}} <li>
{{--</li>--}} <a href="#" data-toggle="control-sidebar">
<i class="fa fa-server"></i>
</a>
</li>
@endif
@if(Auth::user()->root_admin) @if(Auth::user()->root_admin)
<li> <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> <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> </div>
Copyright &copy; 2015 - {{ date('Y') }} <a href="https://pterodactyl.io/">Pterodactyl Software</a>. Copyright &copy; 2015 - {{ date('Y') }} <a href="https://pterodactyl.io/">Pterodactyl Software</a>.
</footer> </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 class="control-sidebar-bg"></div>
</div> </div>
@section('footer-scripts') @section('footer-scripts')