2017-10-07 04:57:53 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Admin\Nests;
|
|
|
|
|
|
|
|
use Illuminate\View\View;
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
use Prologue\Alerts\AlertsMessageBag;
|
2022-10-14 16:59:20 +00:00
|
|
|
use Illuminate\View\Factory as ViewFactory;
|
2017-10-07 04:57:53 +00:00
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
2022-10-24 00:15:11 +00:00
|
|
|
use Pterodactyl\Models\Nest;
|
2017-10-07 04:57:53 +00:00
|
|
|
use Pterodactyl\Services\Nests\NestUpdateService;
|
|
|
|
use Pterodactyl\Services\Nests\NestCreationService;
|
|
|
|
use Pterodactyl\Services\Nests\NestDeletionService;
|
|
|
|
use Pterodactyl\Http\Requests\Admin\Nest\StoreNestFormRequest;
|
|
|
|
|
|
|
|
class NestController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* NestController constructor.
|
|
|
|
*/
|
|
|
|
public function __construct(
|
2022-10-14 16:59:20 +00:00
|
|
|
protected AlertsMessageBag $alert,
|
|
|
|
protected NestCreationService $nestCreationService,
|
|
|
|
protected NestDeletionService $nestDeletionService,
|
|
|
|
protected NestUpdateService $nestUpdateService,
|
|
|
|
protected ViewFactory $view
|
2017-10-07 04:57:53 +00:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render nest listing page.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function index(): View
|
|
|
|
{
|
2022-10-24 00:15:11 +00:00
|
|
|
$nests = Nest::query()->withCount(['eggs', 'servers']);
|
|
|
|
|
2022-10-14 16:59:20 +00:00
|
|
|
return $this->view->make('admin.nests.index', [
|
2022-10-24 00:15:11 +00:00
|
|
|
'nests' => $nests,
|
2017-10-07 04:57:53 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render nest creation page.
|
|
|
|
*/
|
|
|
|
public function create(): View
|
|
|
|
{
|
2022-10-14 16:59:20 +00:00
|
|
|
return $this->view->make('admin.nests.new');
|
2017-10-07 04:57:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the storage of a new nest.
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
*/
|
|
|
|
public function store(StoreNestFormRequest $request): RedirectResponse
|
|
|
|
{
|
|
|
|
$nest = $this->nestCreationService->handle($request->normalize());
|
|
|
|
$this->alert->success(trans('admin/nests.notices.created', ['name' => $nest->name]))->flash();
|
|
|
|
|
|
|
|
return redirect()->route('admin.nests.view', $nest->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-10-14 16:59:20 +00:00
|
|
|
* Return details about a nest including all the eggs and servers per egg.
|
2017-10-07 04:57:53 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function view(int $nest): View
|
|
|
|
{
|
2022-10-14 16:59:20 +00:00
|
|
|
return $this->view->make('admin.nests.view', [
|
2022-10-24 00:15:11 +00:00
|
|
|
'nest' => Nest::with('eggs.servers')->findOrFail($nest),
|
2017-10-07 04:57:53 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle request to update a nest.
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
*/
|
|
|
|
public function update(StoreNestFormRequest $request, int $nest): RedirectResponse
|
|
|
|
{
|
|
|
|
$this->nestUpdateService->handle($nest, $request->normalize());
|
|
|
|
$this->alert->success(trans('admin/nests.notices.updated'))->flash();
|
|
|
|
|
|
|
|
return redirect()->route('admin.nests.view', $nest);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle request to delete a nest.
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
|
|
|
|
*/
|
2017-10-07 21:16:51 +00:00
|
|
|
public function destroy(int $nest): RedirectResponse
|
2017-10-07 04:57:53 +00:00
|
|
|
{
|
|
|
|
$this->nestDeletionService->handle($nest);
|
|
|
|
$this->alert->success(trans('admin/nests.notices.deleted'))->flash();
|
|
|
|
|
|
|
|
return redirect()->route('admin.nests');
|
|
|
|
}
|
|
|
|
}
|