Cleanup code, add basic functionality for Nests

This commit is contained in:
Matthew Penner 2021-01-01 15:55:30 -07:00
parent 6c85be72fa
commit 88ac1ce1fd
37 changed files with 331 additions and 159 deletions

View File

@ -113,6 +113,6 @@ class ApiController extends Controller
{
$this->repository->deleteApplicationKey($request->user(), $identifier);
return response('', 204);
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
}
}

View File

@ -205,7 +205,7 @@ class MountController extends Controller
{
$mount->eggs()->detach($egg_id);
return response('', 204);
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
}
/**
@ -219,6 +219,6 @@ class MountController extends Controller
{
$mount->nodes()->detach($node_id);
return response('', 204);
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
}
}

View File

@ -201,7 +201,7 @@ class NodesController extends Controller
{
$this->allocationDeletionService->handle($allocation);
return response('', 204);
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
}
/**
@ -222,7 +222,7 @@ class NodesController extends Controller
$this->allocationRemoveSingle($node, $allocation);
}
return response('', 204);
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
}
/**
@ -261,7 +261,7 @@ class NodesController extends Controller
'ip_alias' => (empty($request->input('alias'))) ? null : $request->input('alias'),
]);
return response('', 204);
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
}
/**

View File

@ -395,7 +395,7 @@ class ServersController extends Controller
$this->databasePasswordService->handle($database);
return response('', 204);
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
}
/**
@ -417,7 +417,7 @@ class ServersController extends Controller
$this->databaseManagementService->delete($database);
return response('', 204);
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
}
/**

View File

@ -112,7 +112,7 @@ class MailController extends Controller
$this->kernel->call('queue:restart');
return response('', 204);
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
}
/**
@ -130,6 +130,6 @@ class MailController extends Controller
return response($exception->getMessage(), 500);
}
return response('', 204);
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
}
}

View File

@ -59,7 +59,9 @@ abstract class ApplicationApiController extends Controller
* Return an instance of an application transformer.
*
* @param string $abstract
*
* @return \Pterodactyl\Transformers\Api\Application\BaseTransformer
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function getTransformer(string $abstract)
{

View File

@ -2,7 +2,6 @@
namespace Pterodactyl\Http\Controllers\Api\Application\Locations;
use Illuminate\Http\Response;
use Pterodactyl\Models\Location;
use Illuminate\Http\JsonResponse;
use Spatie\QueryBuilder\QueryBuilder;
@ -66,7 +65,9 @@ class LocationController extends ApplicationApiController
* Return all of the locations currently registered on the Panel.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Locations\GetLocationsRequest $request
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function index(GetLocationsRequest $request): array
{
@ -84,11 +85,14 @@ class LocationController extends ApplicationApiController
* Return a single location.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Locations\GetLocationRequest $request
* @param \Pterodactyl\Models\Location $location
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function view(GetLocationRequest $request): array
public function view(GetLocationRequest $request, Location $location): array
{
return $this->fractal->item($request->getModel(Location::class))
return $this->fractal->item($location)
->transformWith($this->getTransformer(LocationTransformer::class))
->toArray();
}
@ -98,9 +102,11 @@ class LocationController extends ApplicationApiController
* new location attached.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Locations\StoreLocationRequest $request
*
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function store(StoreLocationRequest $request): JsonResponse
{
@ -120,14 +126,17 @@ class LocationController extends ApplicationApiController
* Update a location on the Panel and return the updated record to the user.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Locations\UpdateLocationRequest $request
* @param \Pterodactyl\Models\Location $location
*
* @return array
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function update(UpdateLocationRequest $request): array
public function update(UpdateLocationRequest $request, Location $location): array
{
$location = $this->updateService->handle($request->getModel(Location::class), $request->validated());
$location = $this->updateService->handle($location, $request->validated());
return $this->fractal->item($location)
->transformWith($this->getTransformer(LocationTransformer::class))
@ -138,14 +147,16 @@ class LocationController extends ApplicationApiController
* Delete a location from the Panel.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Locations\DeleteLocationRequest $request
* @return \Illuminate\Http\Response
* @param \Pterodactyl\Models\Location $location
*
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\Service\Location\HasActiveNodesException
*/
public function delete(DeleteLocationRequest $request): Response
public function delete(DeleteLocationRequest $request, Location $location): JsonResponse
{
$this->deletionService->handle($request->getModel(Location::class));
$this->deletionService->handle($location);
return response('', 204);
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
}
}

View File

@ -33,12 +33,15 @@ class EggController extends ApplicationApiController
* Return all eggs that exist for a given nest.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Nests\Eggs\GetEggsRequest $request
* @param \Pterodactyl\Models\Nest $nest
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function index(GetEggsRequest $request): array
public function index(GetEggsRequest $request, Nest $nest): array
{
$eggs = $this->repository->findWhere([
['nest_id', '=', $request->getModel(Nest::class)->id],
['nest_id', '=', $nest->id],
]);
return $this->fractal->collection($eggs)
@ -50,11 +53,14 @@ class EggController extends ApplicationApiController
* Return a single egg that exists on the specified nest.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Nests\Eggs\GetEggRequest $request
* @param \Pterodactyl\Models\Egg $egg
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function view(GetEggRequest $request): array
public function view(GetEggRequest $request, Egg $egg): array
{
return $this->fractal->item($request->getModel(Egg::class))
return $this->fractal->item($egg)
->transformWith($this->getTransformer(EggTransformer::class))
->toArray();
}

View File

@ -31,7 +31,9 @@ class NestController extends ApplicationApiController
* Return all Nests that exist on the Panel.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Nests\GetNestsRequest $request
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function index(GetNestsRequest $request): array
{
@ -46,11 +48,14 @@ class NestController extends ApplicationApiController
* Return information about a single Nest model.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Nests\GetNestsRequest $request
* @param \Pterodactyl\Models\Nest $nest
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function view(GetNestsRequest $request): array
public function view(GetNestsRequest $request, Nest $nest): array
{
return $this->fractal->item($request->getModel(Nest::class))
return $this->fractal->item($nest)
->transformWith($this->getTransformer(NestTransformer::class))
->toArray();
}

View File

@ -46,7 +46,9 @@ class AllocationController extends ApplicationApiController
*
* @param \Pterodactyl\Http\Requests\Api\Application\Allocations\GetAllocationsRequest $request
* @param \Pterodactyl\Models\Node $node
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function index(GetAllocationsRequest $request, Node $node): array
{

View File

@ -20,6 +20,6 @@ class NodeConfigurationController extends ApplicationApiController
*/
public function __invoke(GetNodeRequest $request, Node $node)
{
return JsonResponse::create($node->getConfiguration());
return new JsonResponse($node->getConfiguration());
}
}

View File

@ -65,7 +65,9 @@ class NodeController extends ApplicationApiController
* Return all of the nodes currently available on the Panel.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Nodes\GetNodesRequest $request
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function index(GetNodesRequest $request): array
{
@ -84,7 +86,9 @@ class NodeController extends ApplicationApiController
*
* @param \Pterodactyl\Http\Requests\Api\Application\Nodes\GetNodeRequest $request
* @param \Pterodactyl\Models\Node $node
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function view(GetNodeRequest $request, Node $node): array
{
@ -98,9 +102,10 @@ class NodeController extends ApplicationApiController
* status response on success.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Nodes\StoreNodeRequest $request
*
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException*@throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function store(StoreNodeRequest $request): JsonResponse
{
@ -121,6 +126,7 @@ class NodeController extends ApplicationApiController
*
* @param \Pterodactyl\Http\Requests\Api\Application\Nodes\UpdateNodeRequest $request
* @param \Pterodactyl\Models\Node $node
*
* @return array
*
* @throws \Throwable
@ -142,6 +148,7 @@ class NodeController extends ApplicationApiController
*
* @param \Pterodactyl\Http\Requests\Api\Application\Nodes\DeleteNodeRequest $request
* @param \Pterodactyl\Models\Node $node
*
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException

View File

@ -37,8 +37,9 @@ class RoleController extends ApplicationApiController
* @param \Pterodactyl\Http\Requests\Api\Application\Roles\GetRolesRequest $request
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function index(GetRolesRequest $request)
public function index(GetRolesRequest $request): array
{
return $this->fractal->collection(AdminRole::all())
->transformWith($this->getTransformer(AdminRoleTransformer::class))
@ -52,6 +53,7 @@ class RoleController extends ApplicationApiController
* @param \Pterodactyl\Models\AdminRole $role
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function view(GetRolesRequest $request, AdminRole $role): array
{
@ -66,8 +68,9 @@ class RoleController extends ApplicationApiController
* @param \Pterodactyl\Http\Requests\Api\Application\Roles\StoreRoleRequest $request
*
* @return \Illuminate\Http\JsonResponse
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function store(StoreRoleRequest $request)
public function store(StoreRoleRequest $request): JsonResponse
{
$role = AdminRole::query()->create($request->validated());
@ -83,8 +86,9 @@ class RoleController extends ApplicationApiController
* @param \Pterodactyl\Models\AdminRole $role
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function update(UpdateRoleRequest $request, AdminRole $role)
public function update(UpdateRoleRequest $request, AdminRole $role): array
{
$role->update($request->validated());
@ -101,7 +105,7 @@ class RoleController extends ApplicationApiController
*
* @return \Illuminate\Http\JsonResponse
*/
public function delete(DeleteRoleRequest $request, AdminRole $role)
public function delete(DeleteRoleRequest $request, AdminRole $role): JsonResponse
{
$this->repository->delete($role->id);

View File

@ -44,7 +44,8 @@ class DatabaseController extends ApplicationApiController
DatabaseManagementService $databaseManagementService,
DatabasePasswordService $databasePasswordService,
DatabaseRepositoryInterface $repository
) {
)
{
parent::__construct();
$this->databaseManagementService = $databaseManagementService;
@ -58,7 +59,9 @@ class DatabaseController extends ApplicationApiController
*
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\Databases\GetServerDatabasesRequest $request
* @param \Pterodactyl\Models\Server $server
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function index(GetServerDatabasesRequest $request, Server $server): array
{
@ -73,7 +76,9 @@ class DatabaseController extends ApplicationApiController
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\Databases\GetServerDatabaseRequest $request
* @param \Pterodactyl\Models\Server $server
* @param \Pterodactyl\Models\Database $database
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function view(GetServerDatabaseRequest $request, Server $server, Database $database): array
{
@ -88,6 +93,7 @@ class DatabaseController extends ApplicationApiController
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\Databases\ServerDatabaseWriteRequest $request
* @param \Pterodactyl\Models\Server $server
* @param \Pterodactyl\Models\Database $database
*
* @return \Illuminate\Http\JsonResponse
*
* @throws \Throwable
@ -96,7 +102,7 @@ class DatabaseController extends ApplicationApiController
{
$this->databasePasswordService->handle($database);
return JsonResponse::create([], JsonResponse::HTTP_NO_CONTENT);
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
}
/**
@ -104,6 +110,7 @@ class DatabaseController extends ApplicationApiController
*
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\Databases\StoreServerDatabaseRequest $request
* @param \Pterodactyl\Models\Server $server
*
* @return \Illuminate\Http\JsonResponse
*
* @throws \Throwable
@ -129,14 +136,16 @@ class DatabaseController extends ApplicationApiController
* Handle a request to delete a specific server database from the Panel.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\Databases\ServerDatabaseWriteRequest $request
* @return \Illuminate\Http\Response
* @param \Pterodactyl\Models\Database $database
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @return \Illuminate\Http\JsonResponse
*
* @throws \Exception
*/
public function delete(ServerDatabaseWriteRequest $request): Response
public function delete(ServerDatabaseWriteRequest $request, Database $database): JsonResponse
{
$this->databaseManagementService->delete($request->getModel(Database::class));
$this->databaseManagementService->delete($database);
return response('', 204);
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
}
}

View File

@ -12,7 +12,9 @@ class ExternalServerController extends ApplicationApiController
* Retrieve a specific server from the database using its external ID.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\GetExternalServerRequest $request
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function index(GetExternalServerRequest $request): array
{

View File

@ -22,12 +22,10 @@ class ServerController extends ApplicationApiController
* @var \Pterodactyl\Services\Servers\ServerCreationService
*/
private $creationService;
/**
* @var \Pterodactyl\Services\Servers\ServerDeletionService
*/
private $deletionService;
/**
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
*/
@ -44,7 +42,8 @@ class ServerController extends ApplicationApiController
ServerCreationService $creationService,
ServerDeletionService $deletionService,
ServerRepositoryInterface $repository
) {
)
{
parent::__construct();
$this->creationService = $creationService;
@ -56,7 +55,9 @@ class ServerController extends ApplicationApiController
* Return all of the servers that currently exist on the Panel.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\GetServersRequest $request
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function index(GetServersRequest $request): array
{
@ -74,12 +75,12 @@ class ServerController extends ApplicationApiController
* Create a new server on the system.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\StoreServerRequest $request
*
* @return \Illuminate\Http\JsonResponse
*
* @throws \Throwable
* @throws \Illuminate\Validation\ValidationException
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Pterodactyl\Exceptions\Service\Deployment\NoViableAllocationException
* @throws \Pterodactyl\Exceptions\Service\Deployment\NoViableNodeException
@ -97,22 +98,28 @@ class ServerController extends ApplicationApiController
* Show a single server transformed for the application API.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\GetServerRequest $request
* @param \Pterodactyl\Models\Server $server
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function view(GetServerRequest $request): array
public function view(GetServerRequest $request, Server $server): array
{
return $this->fractal->item($request->getModel(Server::class))
return $this->fractal->item($server)
->transformWith($this->getTransformer(ServerTransformer::class))
->toArray();
}
/**
* Deletes a server.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\ServerWriteRequest $request
* @param \Pterodactyl\Models\Server $server
* @param string $force
*
* @return \Illuminate\Http\Response
*
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Throwable
*/
public function delete(ServerWriteRequest $request, Server $server, string $force = ''): Response
{

View File

@ -42,16 +42,17 @@ class ServerDetailsController extends ApplicationApiController
* Update the details for a specific server.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\UpdateServerDetailsRequest $request
* @param \Pterodactyl\Models\Server $server
*
* @return array
*
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
* @throws \Throwable
*/
public function details(UpdateServerDetailsRequest $request): array
public function details(UpdateServerDetailsRequest $request, Server $server): array
{
$server = $this->detailsModificationService->returnUpdatedModel()->handle(
$request->getModel(Server::class), $request->validated()
$server, $request->validated()
);
return $this->fractal->item($server)
@ -64,11 +65,11 @@ class ServerDetailsController extends ApplicationApiController
*
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\UpdateServerBuildConfigurationRequest $request
* @param \Pterodactyl\Models\Server $server
*
* @return array
*
* @throws \Throwable
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function build(UpdateServerBuildConfigurationRequest $request, Server $server): array
{

View File

@ -42,6 +42,7 @@ class ServerManagementController extends ApplicationApiController
*
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\ServerWriteRequest $request
* @param \Pterodactyl\Models\Server $server
*
* @return \Illuminate\Http\Response
*
* @throws \Throwable
@ -58,6 +59,7 @@ class ServerManagementController extends ApplicationApiController
*
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\ServerWriteRequest $request
* @param \Pterodactyl\Models\Server $server
*
* @return \Illuminate\Http\Response
*
* @throws \Throwable
@ -74,11 +76,10 @@ class ServerManagementController extends ApplicationApiController
*
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\ServerWriteRequest $request
* @param \Pterodactyl\Models\Server $server
*
* @return \Illuminate\Http\Response
*
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Throwable
*/
public function reinstall(ServerWriteRequest $request, Server $server): Response
{

View File

@ -32,18 +32,16 @@ class StartupController extends ApplicationApiController
* Update the startup and environment settings for a specific server.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\UpdateServerStartupRequest $request
* @return array
* @param \Pterodactyl\Models\Server $server
*
* @throws \Illuminate\Validation\ValidationException
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @return array
* @throws \Throwable
*/
public function index(UpdateServerStartupRequest $request): array
public function index(UpdateServerStartupRequest $request, Server $server): array
{
$server = $this->modificationService
->setUserLevel(User::USER_LEVEL_ADMIN)
->handle($request->getModel(Server::class), $request->validated());
->handle($server, $request->validated());
return $this->fractal->item($server)
->transformWith($this->getTransformer(ServerTransformer::class))

View File

@ -12,7 +12,9 @@ class ExternalUserController extends ApplicationApiController
* Retrieve a specific user from the database using their external ID.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Users\GetExternalUserRequest $request
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function index(GetExternalUserRequest $request): array
{

View File

@ -3,7 +3,6 @@
namespace Pterodactyl\Http\Controllers\Api\Application\Users;
use Pterodactyl\Models\User;
use Illuminate\Http\Response;
use Illuminate\Http\JsonResponse;
use Spatie\QueryBuilder\QueryBuilder;
use Pterodactyl\Services\Users\UserUpdateService;
@ -52,7 +51,8 @@ class UserController extends ApplicationApiController
UserCreationService $creationService,
UserDeletionService $deletionService,
UserUpdateService $updateService
) {
)
{
parent::__construct();
$this->creationService = $creationService;
@ -67,7 +67,9 @@ class UserController extends ApplicationApiController
* the request.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Users\GetUsersRequest $request
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function index(GetUsersRequest $request): array
{
@ -87,7 +89,9 @@ class UserController extends ApplicationApiController
*
* @param \Pterodactyl\Http\Requests\Api\Application\Users\GetUsersRequest $request
* @param \Pterodactyl\Models\User $user
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function view(GetUsersRequest $request, User $user): array
{
@ -106,10 +110,12 @@ class UserController extends ApplicationApiController
*
* @param \Pterodactyl\Http\Requests\Api\Application\Users\UpdateUserRequest $request
* @param \Pterodactyl\Models\User $user
*
* @return array
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function update(UpdateUserRequest $request, User $user): array
{
@ -127,6 +133,7 @@ class UserController extends ApplicationApiController
* header on successful creation.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Users\StoreUserRequest $request
*
* @return \Illuminate\Http\JsonResponse
*
* @throws \Exception
@ -152,6 +159,7 @@ class UserController extends ApplicationApiController
*
* @param \Pterodactyl\Http\Requests\Api\Application\Users\DeleteUserRequest $request
* @param \Pterodactyl\Models\User $user
*
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\DisplayException

View File

@ -29,6 +29,7 @@ class GetExternalUserRequest extends ApplicationApiRequest
* Determine if the requested external user exists.
*
* @return bool
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function resourceExists(): bool
{

View File

@ -19,15 +19,15 @@ class AdminRoleTransformer extends BaseTransformer
/**
* Return a transformed User model that can be consumed by external services.
*
* @param \Pterodactyl\Models\AdminRole $role
* @param \Pterodactyl\Models\AdminRole $model
* @return array
*/
public function transform(AdminRole $role): array
public function transform(AdminRole $model): array
{
return [
'id' => $role->id,
'name' => $role->name,
'description' => $role->description,
'id' => $model->id,
'name' => $model->name,
'description' => $model->description,
];
}
}

View File

@ -29,18 +29,19 @@ class AllocationTransformer extends BaseTransformer
/**
* Return a generic transformed allocation array.
*
* @param \Pterodactyl\Models\Allocation $allocation
* @param \Pterodactyl\Models\Allocation $model
*
* @return array
*/
public function transform(Allocation $allocation)
public function transform(Allocation $model)
{
return [
'id' => $allocation->id,
'ip' => $allocation->ip,
'alias' => $allocation->ip_alias,
'port' => $allocation->port,
'notes' => $allocation->notes,
'assigned' => ! is_null($allocation->server_id),
'id' => $model->id,
'ip' => $model->ip,
'alias' => $model->ip_alias,
'port' => $model->port,
'notes' => $model->notes,
'assigned' => ! is_null($model->server_id),
];
}
@ -48,8 +49,10 @@ class AllocationTransformer extends BaseTransformer
* Load the node relationship onto a given transformation.
*
* @param \Pterodactyl\Models\Allocation $allocation
*
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function includeNode(Allocation $allocation)
{
@ -66,8 +69,10 @@ class AllocationTransformer extends BaseTransformer
* Load the server relationship onto a given transformation.
*
* @param \Pterodactyl\Models\Allocation $allocation
*
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function includeServer(Allocation $allocation)
{

View File

@ -44,6 +44,7 @@ abstract class BaseTransformer extends TransformerAbstract
* Set the HTTP request class being used for this request.
*
* @param \Pterodactyl\Models\ApiKey $key
*
* @return $this
*/
public function setKey(ApiKey $key)
@ -69,6 +70,7 @@ abstract class BaseTransformer extends TransformerAbstract
* models on a transformation request.
*
* @param string $resource
*
* @return bool
*/
protected function authorize(string $resource): bool
@ -82,8 +84,10 @@ abstract class BaseTransformer extends TransformerAbstract
*
* @param string $abstract
* @param array $parameters
*
* @return \Pterodactyl\Transformers\Api\Application\BaseTransformer
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
*/
protected function makeTransformer(string $abstract, array $parameters = [])
@ -103,6 +107,7 @@ abstract class BaseTransformer extends TransformerAbstract
* Return an ISO-8601 formatted timestamp to use in the API response.
*
* @param string $timestamp
*
* @return string
*/
protected function formatTimestamp(string $timestamp): string

View File

@ -30,6 +30,7 @@ class DatabaseHostTransformer extends BaseTransformer
* Transform database host into a representation for the application API.
*
* @param \Pterodactyl\Models\DatabaseHost $model
*
* @return array
*/
public function transform(DatabaseHost $model)
@ -54,6 +55,7 @@ class DatabaseHostTransformer extends BaseTransformer
* Include the databases associated with this host.
*
* @param \Pterodactyl\Models\DatabaseHost $model
*
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
*/

View File

@ -34,6 +34,7 @@ class EggTransformer extends BaseTransformer
* the application api.
*
* @param \Pterodactyl\Models\Egg $model
*
* @return array
*/
public function transform(Egg $model)
@ -74,8 +75,10 @@ class EggTransformer extends BaseTransformer
* Include the Nest relationship for the given Egg in the transformation.
*
* @param \Pterodactyl\Models\Egg $model
*
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function includeNest(Egg $model)
{
@ -92,8 +95,10 @@ class EggTransformer extends BaseTransformer
* Include the Servers relationship for the given Egg in the transformation.
*
* @param \Pterodactyl\Models\Egg $model
*
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function includeServers(Egg $model)
{
@ -111,6 +116,7 @@ class EggTransformer extends BaseTransformer
* extending another.
*
* @param \Pterodactyl\Models\Egg $model
*
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
*/
public function includeConfig(Egg $model)
@ -136,6 +142,7 @@ class EggTransformer extends BaseTransformer
* Egg is extending another.
*
* @param \Pterodactyl\Models\Egg $model
*
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
*/
public function includeScript(Egg $model)
@ -160,8 +167,10 @@ class EggTransformer extends BaseTransformer
* Include the variables that are defined for this Egg.
*
* @param \Pterodactyl\Models\Egg $model
*
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function includeVariables(Egg $model)
{

View File

@ -27,17 +27,17 @@ class LocationTransformer extends BaseTransformer
/**
* Return a generic transformed location array.
*
* @param \Pterodactyl\Models\Location $location
* @param \Pterodactyl\Models\Location $model
* @return array
*/
public function transform(Location $location): array
public function transform(Location $model): array
{
return [
'id' => $location->id,
'short' => $location->short,
'long' => $location->long,
$location->getUpdatedAtColumn() => $this->formatTimestamp($location->updated_at),
$location->getCreatedAtColumn() => $this->formatTimestamp($location->created_at),
'id' => $model->id,
'short' => $model->short,
'long' => $model->long,
$model->getUpdatedAtColumn() => $this->formatTimestamp($model->updated_at),
$model->getCreatedAtColumn() => $this->formatTimestamp($model->created_at),
];
}

View File

@ -28,12 +28,13 @@ class NodeTransformer extends BaseTransformer
* Return a node transformed into a format that can be consumed by the
* external administrative API.
*
* @param \Pterodactyl\Models\Node $node
* @param \Pterodactyl\Models\Node $model
*
* @return array
*/
public function transform(Node $node): array
public function transform(Node $model): array
{
$response = collect($node->toArray())->mapWithKeys(function ($value, $key) {
$response = collect($model->toArray())->mapWithKeys(function ($value, $key) {
// I messed up early in 2016 when I named this column as poorly
// as I did. This is the tragic result of my mistakes.
$key = ($key === 'daemonSFTP') ? 'daemonSftp' : $key;
@ -41,10 +42,10 @@ class NodeTransformer extends BaseTransformer
return [snake_case($key) => $value];
})->toArray();
$response[$node->getUpdatedAtColumn()] = $this->formatTimestamp($node->updated_at);
$response[$node->getCreatedAtColumn()] = $this->formatTimestamp($node->created_at);
$response[$model->getUpdatedAtColumn()] = $this->formatTimestamp($model->updated_at);
$response[$model->getCreatedAtColumn()] = $this->formatTimestamp($model->created_at);
$resources = $node->servers()->select(['memory', 'disk'])->get();
$resources = $model->servers()->select(['memory', 'disk'])->get();
$response['allocated_resources'] = [
'memory' => $resources->sum('memory'),
@ -58,8 +59,10 @@ class NodeTransformer extends BaseTransformer
* Return the nodes associated with this location.
*
* @param \Pterodactyl\Models\Node $node
*
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function includeAllocations(Node $node)
{
@ -78,8 +81,10 @@ class NodeTransformer extends BaseTransformer
* Return the nodes associated with this location.
*
* @param \Pterodactyl\Models\Node $node
*
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function includeLocation(Node $node)
{
@ -98,8 +103,10 @@ class NodeTransformer extends BaseTransformer
* Return the nodes associated with this location.
*
* @param \Pterodactyl\Models\Node $node
*
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function includeServers(Node $node)
{

View File

@ -54,45 +54,46 @@ class ServerTransformer extends BaseTransformer
/**
* Return a generic transformed server array.
*
* @param \Pterodactyl\Models\Server $server
* @param \Pterodactyl\Models\Server $model
*
* @return array
*/
public function transform(Server $server): array
public function transform(Server $model): array
{
return [
'id' => $server->getKey(),
'external_id' => $server->external_id,
'uuid' => $server->uuid,
'identifier' => $server->uuidShort,
'name' => $server->name,
'description' => $server->description,
'suspended' => (bool) $server->suspended,
'id' => $model->getKey(),
'external_id' => $model->external_id,
'uuid' => $model->uuid,
'identifier' => $model->uuidShort,
'name' => $model->name,
'description' => $model->description,
'suspended' => (bool) $model->suspended,
'limits' => [
'memory' => $server->memory,
'swap' => $server->swap,
'disk' => $server->disk,
'io' => $server->io,
'cpu' => $server->cpu,
'threads' => $server->threads,
'memory' => $model->memory,
'swap' => $model->swap,
'disk' => $model->disk,
'io' => $model->io,
'cpu' => $model->cpu,
'threads' => $model->threads,
],
'feature_limits' => [
'databases' => $server->database_limit,
'allocations' => $server->allocation_limit,
'backups' => $server->backup_limit,
'databases' => $model->database_limit,
'allocations' => $model->allocation_limit,
'backups' => $model->backup_limit,
],
'user' => $server->owner_id,
'node' => $server->node_id,
'allocation' => $server->allocation_id,
'nest' => $server->nest_id,
'egg' => $server->egg_id,
'user' => $model->owner_id,
'node' => $model->node_id,
'allocation' => $model->allocation_id,
'nest' => $model->nest_id,
'egg' => $model->egg_id,
'container' => [
'startup_command' => $server->startup,
'image' => $server->image,
'installed' => (int) $server->installed === 1,
'environment' => $this->environmentService->handle($server),
'startup_command' => $model->startup,
'image' => $model->image,
'installed' => (int) $model->installed === 1,
'environment' => $this->environmentService->handle($model),
],
$server->getUpdatedAtColumn() => $this->formatTimestamp($server->updated_at),
$server->getCreatedAtColumn() => $this->formatTimestamp($server->created_at),
$model->getUpdatedAtColumn() => $this->formatTimestamp($model->updated_at),
$model->getCreatedAtColumn() => $this->formatTimestamp($model->created_at),
];
}
@ -100,9 +101,11 @@ class ServerTransformer extends BaseTransformer
* Return a generic array of allocations for this server.
*
* @param \Pterodactyl\Models\Server $server
*
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
*
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function includeAllocations(Server $server)
{
@ -119,9 +122,11 @@ class ServerTransformer extends BaseTransformer
* Return a generic array of data about subusers for this server.
*
* @param \Pterodactyl\Models\Server $server
*
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
*
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function includeSubusers(Server $server)
{
@ -138,9 +143,11 @@ class ServerTransformer extends BaseTransformer
* Return a generic array of data about subusers for this server.
*
* @param \Pterodactyl\Models\Server $server
*
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
*
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function includeUser(Server $server)
{
@ -157,9 +164,11 @@ class ServerTransformer extends BaseTransformer
* Return a generic array with nest information for this server.
*
* @param \Pterodactyl\Models\Server $server
*
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
*
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function includeNest(Server $server)
{
@ -176,9 +185,11 @@ class ServerTransformer extends BaseTransformer
* Return a generic array with egg information for this server.
*
* @param \Pterodactyl\Models\Server $server
*
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
*
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function includeEgg(Server $server)
{
@ -195,9 +206,11 @@ class ServerTransformer extends BaseTransformer
* Return a generic array of data about subusers for this server.
*
* @param \Pterodactyl\Models\Server $server
*
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
*
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function includeVariables(Server $server)
{
@ -214,9 +227,11 @@ class ServerTransformer extends BaseTransformer
* Return a generic array with location information for this server.
*
* @param \Pterodactyl\Models\Server $server
*
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
*
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function includeLocation(Server $server)
{
@ -233,9 +248,11 @@ class ServerTransformer extends BaseTransformer
* Return a generic array with node information for this server.
*
* @param \Pterodactyl\Models\Server $server
*
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
*
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function includeNode(Server $server)
{
@ -252,9 +269,11 @@ class ServerTransformer extends BaseTransformer
* Return a generic array with database information for this server.
*
* @param \Pterodactyl\Models\Server $server
*
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
*
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function includeDatabases(Server $server)
{

View File

@ -3,7 +3,7 @@ import React from 'react';
import styled from 'styled-components/macro';
import tw from 'twin.macro';
const Checkbox = styled(Input)`
export const TableCheckbox = styled(Input)`
&& {
${tw`border-neutral-500 bg-transparent`};
@ -13,12 +13,14 @@ const Checkbox = styled(Input)`
}
`;
export default ({ name }: { name: string }) => {
export default ({ name, checked, onChange }: { name: string, checked: boolean, onChange(e: React.ChangeEvent<HTMLInputElement>): void }) => {
return (
<Checkbox
<TableCheckbox
type={'checkbox'}
name={'selectedItems'}
value={name}
type={'checkbox'}
checked={checked}
onChange={onChange}
/>
);
};

View File

@ -1,29 +1,29 @@
import React from 'react';
import { CSSTransition } from 'react-transition-group';
// import { CSSTransition } from 'react-transition-group';
import tw from 'twin.macro';
import FlashMessageRender from '@/components/FlashMessageRender';
const PageContentBlock: React.FC<{ showFlashKey?: string; className?: string }> = ({ children, showFlashKey }) => (
<CSSTransition timeout={150} classNames={'fade'} appear in>
<>
{showFlashKey &&
<FlashMessageRender byKey={showFlashKey} css={tw`mb-4`}/>
}
{children}
// <CSSTransition timeout={150} classNames={'fade'} appear in>
<>
{showFlashKey &&
<FlashMessageRender byKey={showFlashKey} css={tw`mb-4`}/>
}
{children}
{/* <p css={tw`text-center text-neutral-500 text-xs mt-4`}>
&copy; 2015 - 2020&nbsp;
<a
rel={'noopener nofollow noreferrer'}
href={'https://pterodactyl.io'}
target={'_blank'}
css={tw`no-underline text-neutral-500 hover:text-neutral-300`}
>
Pterodactyl Software
</a>
</p> */}
</>
</CSSTransition>
{/* <p css={tw`text-center text-neutral-500 text-xs mt-4`}>
&copy; 2015 - 2021&nbsp;
<a
rel={'noopener nofollow noreferrer'}
href={'https://pterodactyl.io'}
target={'_blank'}
css={tw`no-underline text-neutral-500 hover:text-neutral-300`}
>
Pterodactyl Software
</a>
</p> */}
</>
// </CSSTransition>
);
export default PageContentBlock;

View File

@ -1,4 +1,3 @@
import AdminCheckbox from '@/components/admin/AdminCheckbox';
import React, { useEffect, useState } from 'react';
import getNests from '@/api/admin/nests/getNests';
import { httpErrorToHuman } from '@/api/http';
@ -11,6 +10,27 @@ import { AdminContext } from '@/state/admin';
import { NavLink, useRouteMatch } from 'react-router-dom';
import tw from 'twin.macro';
import AdminContentBlock from '@/components/admin/AdminContentBlock';
import AdminCheckbox, { TableCheckbox } from '@/components/admin/AdminCheckbox';
const RowCheckbox = ({ id }: { id: number}) => {
const isChecked = AdminContext.useStoreState(state => state.nests.selectedNests.indexOf(id) >= 0);
const appendSelectedNest = AdminContext.useStoreActions(actions => actions.nests.appendSelectedNest);
const removeSelectedNest = AdminContext.useStoreActions(actions => actions.nests.removeSelectedNest);
return (
<AdminCheckbox
name={id.toString()}
checked={isChecked}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
if (e.currentTarget.checked) {
appendSelectedNest(name);
} else {
removeSelectedNest(name);
}
}}
/>
);
};
export default () => {
const match = useRouteMatch();
@ -21,6 +41,9 @@ export default () => {
const nests = useDeepMemoize(AdminContext.useStoreState(state => state.nests.data));
const setNests = AdminContext.useStoreActions(state => state.nests.setNests);
const setSelectedNests = AdminContext.useStoreActions(actions => actions.nests.setSelectedNests);
const selectedNestsLength = AdminContext.useStoreState(state => state.nests.selectedNests.length);
useEffect(() => {
setLoading(!nests.length);
clearFlashes('nests');
@ -34,6 +57,10 @@ export default () => {
.then(() => setLoading(false));
}, []);
const onSelectAllClick = (e: React.ChangeEvent<HTMLInputElement>) => {
setSelectedNests(e.currentTarget.checked ? (nests?.map(nest => nest.id) || []) : []);
};
return (
<AdminContentBlock>
<div css={tw`w-full flex flex-row items-center mb-8`}>
@ -47,8 +74,8 @@ export default () => {
<FlashMessageRender byKey={'nests'} css={tw`mb-4`}/>
<div css={tw`w-full flex flex-col`}>
<div css={tw`w-full flex flex-col bg-neutral-700 rounded-lg shadow-md`}>
<div css={tw`flex flex-col w-full`}>
<div css={tw`rounded-lg shadow-md bg-neutral-700`}>
{ loading ?
<div css={tw`w-full flex flex-col items-center justify-center`} style={{ height: '24rem' }}>
<Spinner size={'base'}/>
@ -66,7 +93,12 @@ export default () => {
<>
<div css={tw`flex flex-row items-center h-12 px-6`}>
<div css={tw`flex flex-row items-center`}>
<AdminCheckbox name={'selectAll'}/>
<TableCheckbox
type={'checkbox'}
name={'selectAll'}
checked={selectedNestsLength === (nests?.length === 0 ? -1 : nests?.length)}
onChange={onSelectAllClick}
/>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" css={tw`w-4 h-4 ml-1 text-neutral-200`}>
<path clipRule="evenodd" fillRule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z"/>
@ -138,16 +170,16 @@ export default () => {
nests.map(nest => (
<tr key={nest.id} css={tw`h-12 hover:bg-neutral-600`}>
<td css={tw`pl-6`}>
<AdminCheckbox name={nest.id.toString()}/>
<RowCheckbox id={nest.id}/>
</td>
<td css={tw`px-6 text-sm text-neutral-200 text-left whitespace-nowrap pl-8`}>{nest.id}</td>
<td css={tw`px-6 text-sm text-neutral-200 text-left whitespace-nowrap`}>{nest.id}</td>
<td css={tw`px-6 text-sm text-neutral-200 text-left whitespace-nowrap`}>
<NavLink to={`${match.url}/${nest.id}`}>
{nest.name}
</NavLink>
</td>
<td css={tw`px-6 text-sm text-neutral-200 text-left whitespace-nowrap pr-8`}>{nest.description}</td>
<td css={tw`px-6 text-sm text-neutral-200 text-left whitespace-nowrap`}>{nest.description}</td>
</tr>
))
}
@ -168,35 +200,35 @@ export default () => {
</svg>
</a>
<a href="javascript:void(0)" css={tw`relative inline-flex items-center px-3 py-1 -ml-px text-sm font-medium leading-5 transition duration-150 ease-in-out border border-neutral-500 bg-neutral-500 text-neutral-50 focus:z-10 focus:outline-none focus:border-primary-300`}>
<a href="javascript:void(0)" css={tw`relative inline-flex items-center px-3 py-1 -ml-px text-sm font-normal leading-5 transition duration-150 ease-in-out border border-neutral-500 bg-neutral-500 text-neutral-50 focus:z-10 focus:outline-none focus:border-primary-300`}>
1
</a>
<a href="javascript:void(0)" css={tw`relative inline-flex items-center px-3 py-1 -ml-px text-sm font-medium leading-5 transition duration-150 ease-in-out border border-neutral-500 bg-neutral-600 text-neutral-200 hover:text-neutral-300 focus:z-10 focus:outline-none focus:border-primary-300 active:bg-neutral-100 active:text-neutral-700`}>
<a href="javascript:void(0)" css={tw`relative inline-flex items-center px-3 py-1 -ml-px text-sm font-normal leading-5 transition duration-150 ease-in-out border border-neutral-500 bg-neutral-600 text-neutral-200 hover:text-neutral-300 focus:z-10 focus:outline-none focus:border-primary-300 active:bg-neutral-100 active:text-neutral-700`}>
2
</a>
<a href="javascript:void(0)" css={tw`relative items-center hidden px-3 py-1 -ml-px text-sm font-medium leading-5 transition duration-150 ease-in-out border md:inline-flex border-neutral-500 bg-neutral-600 text-neutral-200 hover:text-neutral-300 focus:z-10 focus:outline-none focus:border-primary-300 active:bg-neutral-100 active:text-neutral-700`}>
<a href="javascript:void(0)" css={tw`relative items-center hidden px-3 py-1 -ml-px text-sm font-normal leading-5 transition duration-150 ease-in-out border md:inline-flex border-neutral-500 bg-neutral-600 text-neutral-200 hover:text-neutral-300 focus:z-10 focus:outline-none focus:border-primary-300 active:bg-neutral-100 active:text-neutral-700`}>
3
</a>
<span css={tw`relative inline-flex items-center px-3 py-1 -ml-px text-sm font-medium leading-5 border border-neutral-500 bg-neutral-600 text-neutral-200 cursor-default`}>
<span css={tw`relative inline-flex items-center px-3 py-1 -ml-px text-sm font-normal leading-5 border border-neutral-500 bg-neutral-600 text-neutral-200 cursor-default`}>
...
</span>
<a href="javascript:void(0)" css={tw`relative items-center hidden px-3 py-1 -ml-px text-sm font-medium leading-5 transition duration-150 ease-in-out border md:inline-flex border-neutral-500 bg-neutral-600 text-neutral-200 hover:text-neutral-300 focus:z-10 focus:outline-none focus:border-primary-300 active:bg-neutral-100 active:text-neutral-700`}>
<a href="javascript:void(0)" css={tw`relative items-center hidden px-3 py-1 -ml-px text-sm font-normal leading-5 transition duration-150 ease-in-out border md:inline-flex border-neutral-500 bg-neutral-600 text-neutral-200 hover:text-neutral-300 focus:z-10 focus:outline-none focus:border-primary-300 active:bg-neutral-100 active:text-neutral-700`}>
7
</a>
<a href="javascript:void(0)" css={tw`relative inline-flex items-center px-3 py-1 -ml-px text-sm font-medium leading-5 transition duration-150 ease-in-out border border-neutral-500 bg-neutral-600 text-neutral-200 hover:text-neutral-300 focus:z-10 focus:outline-none focus:border-primary-300 active:bg-neutral-100 active:text-neutral-700`}>
<a href="javascript:void(0)" css={tw`relative inline-flex items-center px-3 py-1 -ml-px text-sm font-normal leading-5 transition duration-150 ease-in-out border border-neutral-500 bg-neutral-600 text-neutral-200 hover:text-neutral-300 focus:z-10 focus:outline-none focus:border-primary-300 active:bg-neutral-100 active:text-neutral-700`}>
8
</a>
<a href="javascript:void(0)" css={tw`relative inline-flex items-center px-3 py-1 -ml-px text-sm font-medium leading-5 transition duration-150 ease-in-out border border-neutral-500 bg-neutral-600 text-neutral-200 hover:text-neutral-300 focus:z-10 focus:outline-none focus:border-primary-300 active:bg-neutral-100 active:text-neutral-700`}>
<a href="javascript:void(0)" css={tw`relative inline-flex items-center px-3 py-1 -ml-px text-sm font-normal leading-5 transition duration-150 ease-in-out border border-neutral-500 bg-neutral-600 text-neutral-200 hover:text-neutral-300 focus:z-10 focus:outline-none focus:border-primary-300 active:bg-neutral-100 active:text-neutral-700`}>
9
</a>
<a href="javascript:void(0)" css={tw`relative inline-flex items-center px-1 py-1 text-sm font-medium leading-5 transition duration-150 ease-in-out border rounded-r-md border-neutral-500 bg-neutral-600 text-neutral-400 hover:text-neutral-200 focus:z-10 focus:outline-none focus:border-primary-300 active:bg-neutral-100 active:text-neutral-500`} aria-label="Previous">
<a href="javascript:void(0)" css={tw`relative inline-flex items-center px-1 py-1 -ml-px text-sm font-medium leading-5 transition duration-150 ease-in-out border rounded-r-md border-neutral-500 bg-neutral-600 text-neutral-400 hover:text-neutral-200 focus:z-10 focus:outline-none focus:border-primary-300 active:bg-neutral-100 active:text-neutral-500`} aria-label="Next">
<svg css={tw`w-5 h-5`} xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path clipRule="evenodd" fillRule="evenodd" d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z"/>
</svg>

View File

@ -165,7 +165,7 @@ const AdminRouter = ({ location, match }: RouteComponentProps) => {
</Sidebar>
<div css={tw`h-full w-full flex flex-col items-center`}>
<div css={tw`min-h-screen w-full flex flex-col px-16 py-12 overflow-x-hidden`} style={{ maxWidth: '86rem' }}>
<div css={tw`min-h-screen w-full flex flex-col overflow-x-hidden`} style={{ maxWidth: '86rem' }}>
{/* <TransitionRouter> */}
<Switch location={location}>
<Route path={`${match.path}`} component={OverviewContainer} exact/>

View File

@ -1,5 +1,6 @@
import { createContextStore } from 'easy-peasy';
import { composeWithDevTools } from 'redux-devtools-extension';
import nests, { AdminNestStore } from '@/state/admin/nests';
import roles, { AdminRoleStore } from '@/state/admin/roles';

View File

@ -3,13 +3,20 @@ import { Nest } from '@/api/admin/nests/getNests';
export interface AdminNestStore {
data: Nest[];
selectedNests: number[];
setNests: Action<AdminNestStore, Nest[]>;
appendNest: Action<AdminNestStore, Nest>;
removeNest: Action<AdminNestStore, number>;
setSelectedNests: Action<AdminNestStore, number[]>;
appendSelectedNest: Action<AdminNestStore, number>;
removeSelectedNest: Action<AdminNestStore, number>;
}
const nests: AdminNestStore = {
data: [],
selectedNests: [],
setNests: action((state, payload) => {
state.data = payload;
@ -26,6 +33,22 @@ const nests: AdminNestStore = {
removeNest: action((state, payload) => {
state.data = [ ...state.data.filter(nest => nest.id !== payload) ];
}),
setSelectedNests: action((state, payload) => {
state.selectedNests = payload;
}),
appendSelectedNest: action((state, payload) => {
if (state.selectedNests.find(id => id === payload)) {
state.selectedNests = state.selectedNests.map(id => id === payload ? payload : id);
} else {
state.selectedNests = [ ...state.selectedNests, payload ];
}
}),
removeSelectedNest: action((state, payload) => {
state.selectedNests = [ ...state.selectedNests.filter(id => id !== payload) ];
}),
};
export default nests;

View File

@ -3,6 +3,7 @@ import { Role } from '@/api/admin/roles/getRoles';
export interface AdminRoleStore {
data: Role[];
setRoles: Action<AdminRoleStore, Role[]>;
appendRole: Action<AdminRoleStore, Role>;
removeRole: Action<AdminRoleStore, number>;