Add very basic server search and dynamic rendering functionality

This commit is contained in:
Dane Everitt 2018-05-26 23:17:02 -07:00
parent f337a89320
commit 6f2fcabf22
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
7 changed files with 169 additions and 46 deletions

View file

@ -0,0 +1,54 @@
<?php
namespace Pterodactyl\Http\Controllers\Base;
use Illuminate\Http\Request;
use Pterodactyl\Models\User;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
class DashboardController extends Controller
{
/**
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
*/
private $repository;
/**
* DashboardController constructor.
*
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
*/
public function __construct(ServerRepositoryInterface $repository)
{
$this->repository = $repository;
}
public function servers(Request $request)
{
$servers = $this->repository->setSearchTerm($request->input('query'))->filterUserAccessServers(
$request->user(), User::FILTER_LEVEL_ALL
);
$data = [];
foreach ($servers->items() as $server) {
$cleaned = collect($server)->only([
'uuidShort',
'uuid',
'name',
'cpu',
'memory',
]);
$data[] = array_merge($cleaned->toArray(), [
'allocation' => [
'ip' => $server->allocation->ip,
'port' => $server->allocation->port,
],
'node_name' => $server->node->name,
]);
}
return response()->json($data);
}
}