2017-10-07 04:57:53 +00:00
|
|
|
<?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\Http\Controllers\Admin\Nests;
|
|
|
|
|
|
|
|
use Illuminate\View\View;
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
use Prologue\Alerts\AlertsMessageBag;
|
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
|
|
|
use Pterodactyl\Services\Nests\NestUpdateService;
|
|
|
|
use Pterodactyl\Services\Nests\NestCreationService;
|
|
|
|
use Pterodactyl\Services\Nests\NestDeletionService;
|
|
|
|
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
|
|
|
|
use Pterodactyl\Http\Requests\Admin\Nest\StoreNestFormRequest;
|
|
|
|
|
|
|
|
class NestController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Prologue\Alerts\AlertsMessageBag
|
|
|
|
*/
|
|
|
|
protected $alert;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Nests\NestCreationService
|
|
|
|
*/
|
|
|
|
protected $nestCreationService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Nests\NestDeletionService
|
|
|
|
*/
|
|
|
|
protected $nestDeletionService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface
|
|
|
|
*/
|
|
|
|
protected $repository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Nests\NestUpdateService
|
|
|
|
*/
|
|
|
|
protected $nestUpdateService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* NestController constructor.
|
|
|
|
*
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param \Prologue\Alerts\AlertsMessageBag $alert
|
|
|
|
* @param \Pterodactyl\Services\Nests\NestCreationService $nestCreationService
|
|
|
|
* @param \Pterodactyl\Services\Nests\NestDeletionService $nestDeletionService
|
2017-10-07 04:57:53 +00:00
|
|
|
* @param \Pterodactyl\Contracts\Repository\NestRepositoryInterface $repository
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param \Pterodactyl\Services\Nests\NestUpdateService $nestUpdateService
|
2017-10-07 04:57:53 +00:00
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
AlertsMessageBag $alert,
|
|
|
|
NestCreationService $nestCreationService,
|
|
|
|
NestDeletionService $nestDeletionService,
|
|
|
|
NestRepositoryInterface $repository,
|
|
|
|
NestUpdateService $nestUpdateService
|
|
|
|
) {
|
|
|
|
$this->alert = $alert;
|
|
|
|
$this->nestDeletionService = $nestDeletionService;
|
|
|
|
$this->nestCreationService = $nestCreationService;
|
|
|
|
$this->nestUpdateService = $nestUpdateService;
|
|
|
|
$this->repository = $repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render nest listing page.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
*/
|
|
|
|
public function index(): View
|
|
|
|
{
|
|
|
|
return view('admin.nests.index', [
|
|
|
|
'nests' => $this->repository->getWithCounts(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render nest creation page.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function create(): View
|
|
|
|
{
|
|
|
|
return view('admin.nests.new');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the storage of a new nest.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Http\Requests\Admin\Nest\StoreNestFormRequest $request
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*
|
|
|
|
* @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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return details about a nest including all of the eggs and servers per egg.
|
|
|
|
*
|
|
|
|
* @param int $nest
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
*/
|
|
|
|
public function view(int $nest): View
|
|
|
|
{
|
|
|
|
return view('admin.nests.view', [
|
|
|
|
'nest' => $this->repository->getWithEggServers($nest),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle request to update a nest.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Http\Requests\Admin\Nest\StoreNestFormRequest $request
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param int $nest
|
2017-10-07 04:57:53 +00:00
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
* @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.
|
|
|
|
*
|
2017-10-07 21:16:51 +00:00
|
|
|
* @param int $nest
|
2017-10-07 04:57:53 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*
|
|
|
|
* @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');
|
|
|
|
}
|
|
|
|
}
|