diff --git a/CHANGELOG.md b/CHANGELOG.md index 44d320e82..b4edd9765 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/app/Contracts/Repository/ServerRepositoryInterface.php b/app/Contracts/Repository/ServerRepositoryInterface.php index 6d1c14e78..0ca74bf40 100644 --- a/app/Contracts/Repository/ServerRepositoryInterface.php +++ b/app/Contracts/Repository/ServerRepositoryInterface.php @@ -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. diff --git a/app/Http/ViewComposers/ServerListComposer.php b/app/Http/ViewComposers/ServerListComposer.php new file mode 100644 index 000000000..4c3ac71fb --- /dev/null +++ b/app/Http/ViewComposers/ServerListComposer.php @@ -0,0 +1,51 @@ +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); + } +} diff --git a/app/Providers/ViewComposerServiceProvider.php b/app/Providers/ViewComposerServiceProvider.php index dddc925f4..ab8c9e164 100644 --- a/app/Providers/ViewComposerServiceProvider.php +++ b/app/Providers/ViewComposerServiceProvider.php @@ -1,15 +1,9 @@ . - * - * 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); } } diff --git a/app/Repositories/Eloquent/ServerRepository.php b/app/Repositories/Eloquent/ServerRepository.php index 4bf058a72..7bca12691 100644 --- a/app/Repositories/Eloquent/ServerRepository.php +++ b/app/Repositories/Eloquent/ServerRepository.php @@ -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(); } /** diff --git a/resources/themes/pterodactyl/layouts/master.blade.php b/resources/themes/pterodactyl/layouts/master.blade.php index 7ffb06847..39e5a9dd6 100644 --- a/resources/themes/pterodactyl/layouts/master.blade.php +++ b/resources/themes/pterodactyl/layouts/master.blade.php @@ -60,9 +60,13 @@ - {{--
  • --}} - {{----}} - {{--
  • --}} + @if(isset($sidebarServerList)) +
  • + + + +
  • + @endif @if(Auth::user()->root_admin)
  • @@ -240,6 +244,29 @@ Copyright © 2015 - {{ date('Y') }} Pterodactyl Software. + @if(isset($sidebarServerList)) + + @endif
    @section('footer-scripts')