From fa902cc07423acbc7cb901bd697675a5747d10a0 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Thu, 21 May 2020 13:19:59 -0600 Subject: [PATCH] Add mounts page to server admin view --- .../Controllers/Admin/MountController.php | 7 +- .../Admin/Servers/ServerViewController.php | 39 ++++++++--- .../Controllers/Admin/ServersController.php | 10 ++- app/Repositories/Eloquent/MountRepository.php | 19 +++++ resources/views/admin/mounts/view.blade.php | 17 +++-- .../servers/partials/navigation.blade.php | 3 + .../admin/servers/view/database.blade.php | 2 +- .../views/admin/servers/view/mounts.blade.php | 70 +++++++++++++++++++ routes/admin.php | 1 + 9 files changed, 151 insertions(+), 17 deletions(-) create mode 100644 resources/views/admin/servers/view/mounts.blade.php diff --git a/app/Http/Controllers/Admin/MountController.php b/app/Http/Controllers/Admin/MountController.php index 1132f68f4..945835293 100644 --- a/app/Http/Controllers/Admin/MountController.php +++ b/app/Http/Controllers/Admin/MountController.php @@ -8,9 +8,9 @@ use Prologue\Alerts\AlertsMessageBag; use Pterodactyl\Exceptions\DisplayException; use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Services\Mounts\MountUpdateService; +use Pterodactyl\Http\Requests\Admin\MountFormRequest; use Pterodactyl\Services\Mounts\MountCreationService; use Pterodactyl\Services\Mounts\MountDeletionService; -use Pterodactyl\Http\Requests\Admin\MountFormRequest; use Pterodactyl\Repositories\Eloquent\MountRepository; use Pterodactyl\Contracts\Repository\NestRepositoryInterface; use Pterodactyl\Contracts\Repository\LocationRepositoryInterface; @@ -22,6 +22,11 @@ class MountController extends Controller */ protected $alert; + /** + * @var \Pterodactyl\Repositories\Eloquent\MountRepository + */ + protected $mountRepository; + /** * @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface */ diff --git a/app/Http/Controllers/Admin/Servers/ServerViewController.php b/app/Http/Controllers/Admin/Servers/ServerViewController.php index 25e198592..5706850a1 100644 --- a/app/Http/Controllers/Admin/Servers/ServerViewController.php +++ b/app/Http/Controllers/Admin/Servers/ServerViewController.php @@ -9,6 +9,7 @@ use Pterodactyl\Models\Server; use Illuminate\Contracts\View\Factory; use Pterodactyl\Exceptions\DisplayException; use Pterodactyl\Http\Controllers\Controller; +use Pterodactyl\Repositories\Eloquent\MountRepository; use Pterodactyl\Repositories\Eloquent\NestRepository; use Pterodactyl\Repositories\Eloquent\NodeRepository; use Pterodactyl\Repositories\Eloquent\ServerRepository; @@ -35,6 +36,11 @@ class ServerViewController extends Controller */ private $repository; + /** + * @var \Pterodactyl\Repositories\Eloquent\MountRepository + */ + protected $mountRepository; + /** * @var \Pterodactyl\Repositories\Eloquent\NestRepository */ @@ -53,27 +59,30 @@ class ServerViewController extends Controller /** * ServerViewController constructor. * + * @param \Illuminate\Contracts\View\Factory $view * @param \Pterodactyl\Repositories\Eloquent\DatabaseHostRepository $databaseHostRepository - * @param \Pterodactyl\Repositories\Eloquent\NestRepository $nestRepository * @param \Pterodactyl\Repositories\Eloquent\LocationRepository $locationRepository + * @param \Pterodactyl\Repositories\Eloquent\MountRepository $mountRepository + * @param \Pterodactyl\Repositories\Eloquent\NestRepository $nestRepository * @param \Pterodactyl\Repositories\Eloquent\NodeRepository $nodeRepository * @param \Pterodactyl\Repositories\Eloquent\ServerRepository $repository - * @param \Illuminate\Contracts\View\Factory $view */ public function __construct( + Factory $view, DatabaseHostRepository $databaseHostRepository, - NestRepository $nestRepository, LocationRepository $locationRepository, + MountRepository $mountRepository, + NestRepository $nestRepository, NodeRepository $nodeRepository, - ServerRepository $repository, - Factory $view + ServerRepository $repository ) { $this->view = $view; $this->databaseHostRepository = $databaseHostRepository; - $this->repository = $repository; + $this->locationRepository = $locationRepository; + $this->mountRepository = $mountRepository; $this->nestRepository = $nestRepository; $this->nodeRepository = $nodeRepository; - $this->locationRepository = $locationRepository; + $this->repository = $repository; } /** @@ -160,6 +169,21 @@ class ServerViewController extends Controller ]); } + /** + * Returns all of the mounts that exist for the server. + * + * @param \Illuminate\Http\Request $request + * @param \Pterodactyl\Models\Server $server + * @return \Illuminate\Contracts\View\View + */ + public function mounts(Request $request, Server $server) + { + return $this->view->make('admin.servers.view.mounts', [ + 'mounts' => $this->mountRepository->getMountListForServer($server), + 'server' => $server, + ]); + } + /** * Returns the base server management page, or an exception if the server * is in a state that cannot be recovered from. @@ -169,7 +193,6 @@ class ServerViewController extends Controller * @return \Illuminate\Contracts\View\View * * @throws \Pterodactyl\Exceptions\DisplayException - * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException */ public function manage(Request $request, Server $server) { diff --git a/app/Http/Controllers/Admin/ServersController.php b/app/Http/Controllers/Admin/ServersController.php index 864423cf9..bcd0913a1 100644 --- a/app/Http/Controllers/Admin/ServersController.php +++ b/app/Http/Controllers/Admin/ServersController.php @@ -16,6 +16,7 @@ use Prologue\Alerts\AlertsMessageBag; use Pterodactyl\Exceptions\DisplayException; use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Services\Servers\SuspensionService; +use Pterodactyl\Repositories\Eloquent\MountRepository; use Pterodactyl\Services\Servers\ServerDeletionService; use Pterodactyl\Services\Servers\ReinstallServerService; use Pterodactyl\Services\Servers\BuildModificationService; @@ -83,6 +84,11 @@ class ServersController extends Controller */ protected $detailsModificationService; + /** + * @var \Pterodactyl\Repositories\Eloquent\MountRepository + */ + protected $mountRepository; + /** * @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface */ @@ -123,6 +129,7 @@ class ServersController extends Controller * @param \Pterodactyl\Services\Servers\DetailsModificationService $detailsModificationService * @param \Pterodactyl\Services\Servers\ReinstallServerService $reinstallService * @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository + * @param \Pterodactyl\Repositories\Eloquent\MountRepository $mountRepository * @param \Pterodactyl\Contracts\Repository\NestRepositoryInterface $nestRepository * @param \Pterodactyl\Services\Servers\StartupModificationService $startupModificationService * @param \Pterodactyl\Services\Servers\SuspensionService $suspensionService @@ -140,6 +147,7 @@ class ServersController extends Controller DetailsModificationService $detailsModificationService, ReinstallServerService $reinstallService, ServerRepositoryInterface $repository, + MountRepository $mountRepository, NestRepositoryInterface $nestRepository, StartupModificationService $startupModificationService, SuspensionService $suspensionService @@ -157,6 +165,7 @@ class ServersController extends Controller $this->nestRepository = $nestRepository; $this->reinstallService = $reinstallService; $this->repository = $repository; + $this->mountRepository = $mountRepository; $this->startupModificationService = $startupModificationService; $this->suspensionService = $suspensionService; } @@ -168,7 +177,6 @@ class ServersController extends Controller * @param \Pterodactyl\Models\Server $server * @return \Illuminate\Http\RedirectResponse * - * @throws \Pterodactyl\Exceptions\DisplayException * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException */ diff --git a/app/Repositories/Eloquent/MountRepository.php b/app/Repositories/Eloquent/MountRepository.php index 26766b88b..f12b876d1 100644 --- a/app/Repositories/Eloquent/MountRepository.php +++ b/app/Repositories/Eloquent/MountRepository.php @@ -4,6 +4,7 @@ namespace Pterodactyl\Repositories\Eloquent; use Pterodactyl\Models\Mount; use Illuminate\Support\Collection; +use Pterodactyl\Models\Server; use Pterodactyl\Repositories\Concerns\Searchable; use Illuminate\Database\Eloquent\ModelNotFoundException; use Pterodactyl\Exceptions\Repository\RecordNotFoundException; @@ -48,4 +49,22 @@ class MountRepository extends EloquentRepository throw new RecordNotFoundException; } } + + /** + * Return mounts available to a server. (ignoring if they are or are not mounted) + * + * @param Server $server + * @return \Illuminate\Support\Collection + */ + public function getMountListForServer(Server $server): Collection + { + return $this->getBuilder() + ->whereHas('eggs', function ($q) use ($server) { + $q->where('id', '=', $server->egg_id); + }) + ->whereHas('nodes', function ($q) use ($server) { + $q->where('id', '=', $server->node_id); + }) + ->get($this->getColumns()); + } } diff --git a/resources/views/admin/mounts/view.blade.php b/resources/views/admin/mounts/view.blade.php index 6fe95202f..f53007f3f 100644 --- a/resources/views/admin/mounts/view.blade.php +++ b/resources/views/admin/mounts/view.blade.php @@ -29,6 +29,11 @@
+
+ + +
+
@@ -117,8 +122,8 @@ @foreach ($mount->eggs as $egg) - {{ $egg->id }} - {{ $egg->name }} + {{ $egg->id }} + {{ $egg->name }} @@ -148,9 +153,9 @@ @foreach ($mount->nodes as $node) - {{ $node->id }} - {{ $node->name }} - {{ $node->fqdn }} + {{ $node->id }} + {{ $node->name }} + {{ $node->fqdn }} @@ -254,7 +259,7 @@ @section('footer-scripts') @parent -