paginate databases when viewing a host

This commit is contained in:
Dane Everitt 2018-03-03 17:52:35 -06:00
parent e8cb441fc8
commit c739f292e4
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
7 changed files with 47 additions and 50 deletions

View file

@ -7,6 +7,9 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
### Fixed ### Fixed
* Fixes application API keys being created as a client API key. * Fixes application API keys being created as a client API key.
### Changed
* Databases are now properly paginated when viewing a database host.
## v0.7.4-h1 (Derelict Dermodactylus) ## v0.7.4-h1 (Derelict Dermodactylus)
### Fixed ### Fixed
* Being able to create servers is kind of a core aspect of the software, pushing releases late at night is not a great idea. * Being able to create servers is kind of a core aspect of the software, pushing releases late at night is not a great idea.

View file

@ -3,7 +3,6 @@
namespace Pterodactyl\Contracts\Repository; namespace Pterodactyl\Contracts\Repository;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Pterodactyl\Models\DatabaseHost;
interface DatabaseHostRepositoryInterface extends RepositoryInterface interface DatabaseHostRepositoryInterface extends RepositoryInterface
{ {
@ -14,15 +13,4 @@ interface DatabaseHostRepositoryInterface extends RepositoryInterface
* @return \Illuminate\Support\Collection * @return \Illuminate\Support\Collection
*/ */
public function getWithViewDetails(): Collection; public function getWithViewDetails(): Collection;
/**
* Return a database host with the databases and associated servers
* that are attached to said databases.
*
* @param int $id
* @return \Pterodactyl\Models\DatabaseHost
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function getWithServers(int $id): DatabaseHost;
} }

View file

@ -1,16 +1,10 @@
<?php <?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\Contracts\Repository; namespace Pterodactyl\Contracts\Repository;
use Pterodactyl\Models\Database; use Pterodactyl\Models\Database;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
interface DatabaseRepositoryInterface extends RepositoryInterface interface DatabaseRepositoryInterface extends RepositoryInterface
{ {
@ -39,6 +33,15 @@ interface DatabaseRepositoryInterface extends RepositoryInterface
*/ */
public function getDatabasesForServer(int $server): Collection; public function getDatabasesForServer(int $server): Collection;
/**
* Return all of the databases for a given host with the server relationship loaded.
*
* @param int $host
* @param int $count
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
*/
public function getDatabasesForHost(int $host, int $count = 25): LengthAwarePaginator;
/** /**
* Create a new database if it does not already exist on the host with * Create a new database if it does not already exist on the host with
* the provided details. * the provided details.

View file

@ -1,11 +1,4 @@
<?php <?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; namespace Pterodactyl\Http\Controllers\Admin;
@ -19,6 +12,7 @@ use Pterodactyl\Services\Databases\Hosts\HostUpdateService;
use Pterodactyl\Http\Requests\Admin\DatabaseHostFormRequest; use Pterodactyl\Http\Requests\Admin\DatabaseHostFormRequest;
use Pterodactyl\Services\Databases\Hosts\HostCreationService; use Pterodactyl\Services\Databases\Hosts\HostCreationService;
use Pterodactyl\Services\Databases\Hosts\HostDeletionService; use Pterodactyl\Services\Databases\Hosts\HostDeletionService;
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface; use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface; use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface;
@ -34,6 +28,11 @@ class DatabaseController extends Controller
*/ */
private $creationService; private $creationService;
/**
* @var \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface
*/
private $databaseRepository;
/** /**
* @var \Pterodactyl\Services\Databases\Hosts\HostDeletionService * @var \Pterodactyl\Services\Databases\Hosts\HostDeletionService
*/ */
@ -59,6 +58,7 @@ class DatabaseController extends Controller
* *
* @param \Prologue\Alerts\AlertsMessageBag $alert * @param \Prologue\Alerts\AlertsMessageBag $alert
* @param \Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface $repository * @param \Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface $repository
* @param \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface $databaseRepository
* @param \Pterodactyl\Services\Databases\Hosts\HostCreationService $creationService * @param \Pterodactyl\Services\Databases\Hosts\HostCreationService $creationService
* @param \Pterodactyl\Services\Databases\Hosts\HostDeletionService $deletionService * @param \Pterodactyl\Services\Databases\Hosts\HostDeletionService $deletionService
* @param \Pterodactyl\Services\Databases\Hosts\HostUpdateService $updateService * @param \Pterodactyl\Services\Databases\Hosts\HostUpdateService $updateService
@ -67,6 +67,7 @@ class DatabaseController extends Controller
public function __construct( public function __construct(
AlertsMessageBag $alert, AlertsMessageBag $alert,
DatabaseHostRepositoryInterface $repository, DatabaseHostRepositoryInterface $repository,
DatabaseRepositoryInterface $databaseRepository,
HostCreationService $creationService, HostCreationService $creationService,
HostDeletionService $deletionService, HostDeletionService $deletionService,
HostUpdateService $updateService, HostUpdateService $updateService,
@ -74,6 +75,7 @@ class DatabaseController extends Controller
) { ) {
$this->alert = $alert; $this->alert = $alert;
$this->creationService = $creationService; $this->creationService = $creationService;
$this->databaseRepository = $databaseRepository;
$this->deletionService = $deletionService; $this->deletionService = $deletionService;
$this->repository = $repository; $this->repository = $repository;
$this->locationRepository = $locationRepository; $this->locationRepository = $locationRepository;
@ -105,7 +107,8 @@ class DatabaseController extends Controller
{ {
return view('admin.databases.view', [ return view('admin.databases.view', [
'locations' => $this->locationRepository->getAllWithNodes(), 'locations' => $this->locationRepository->getAllWithNodes(),
'host' => $this->repository->getWithServers($host), 'host' => $this->repository->find($host),
'databases' => $this->databaseRepository->getDatabasesForHost($host),
]); ]);
} }

View file

@ -4,8 +4,6 @@ namespace Pterodactyl\Repositories\Eloquent;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Pterodactyl\Models\DatabaseHost; use Pterodactyl\Models\DatabaseHost;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface; use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface;
class DatabaseHostRepository extends EloquentRepository implements DatabaseHostRepositoryInterface class DatabaseHostRepository extends EloquentRepository implements DatabaseHostRepositoryInterface
@ -30,22 +28,4 @@ class DatabaseHostRepository extends EloquentRepository implements DatabaseHostR
{ {
return $this->getBuilder()->withCount('databases')->with('node')->get(); return $this->getBuilder()->withCount('databases')->with('node')->get();
} }
/**
* Return a database host with the databases and associated servers
* that are attached to said databases.
*
* @param int $id
* @return \Pterodactyl\Models\DatabaseHost
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function getWithServers(int $id): DatabaseHost
{
try {
return $this->getBuilder()->with('databases.server')->findOrFail($id, $this->getColumns());
} catch (ModelNotFoundException $exception) {
throw new RecordNotFoundException;
}
}
} }

View file

@ -6,6 +6,7 @@ use Pterodactyl\Models\Database;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Foundation\Application; use Illuminate\Foundation\Application;
use Illuminate\Database\DatabaseManager; use Illuminate\Database\DatabaseManager;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface; use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
use Pterodactyl\Exceptions\Repository\DuplicateDatabaseNameException; use Pterodactyl\Exceptions\Repository\DuplicateDatabaseNameException;
@ -78,6 +79,20 @@ class DatabaseRepository extends EloquentRepository implements DatabaseRepositor
return $this->getBuilder()->where('server_id', $server)->get($this->getColumns()); return $this->getBuilder()->where('server_id', $server)->get($this->getColumns());
} }
/**
* Return all of the databases for a given host with the server relationship loaded.
*
* @param int $host
* @param int $count
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
*/
public function getDatabasesForHost(int $host, int $count = 25): LengthAwarePaginator
{
return $this->getBuilder()->with('server')
->where('database_host_id', $host)
->paginate($count, $this->getColumns());
}
/** /**
* Create a new database if it does not already exist on the host with * Create a new database if it does not already exist on the host with
* the provided details. * the provided details.

View file

@ -101,14 +101,14 @@
<th>Connections From</th> <th>Connections From</th>
<th></th> <th></th>
</tr> </tr>
@foreach($host->databases as $database) @foreach($databases as $database)
<tr> <tr>
<td class="middle"><a href="{{ route('admin.servers.view', $database->server->id) }}">{{ $database->server->name }}</a></td> <td class="middle"><a href="{{ route('admin.servers.view', $database->getRelation('server')->id) }}">{{ $database->getRelation('server')->name }}</a></td>
<td class="middle">{{ $database->database }}</td> <td class="middle">{{ $database->database }}</td>
<td class="middle">{{ $database->username }}</td> <td class="middle">{{ $database->username }}</td>
<td class="middle">{{ $database->remote }}</td> <td class="middle">{{ $database->remote }}</td>
<td class="text-center"> <td class="text-center">
<a href="{{ route('admin.servers.view.database', $database->server->id) }}"> <a href="{{ route('admin.servers.view.database', $database->getRelation('server')->id) }}">
<button class="btn btn-xs btn-primary">Manage</button> <button class="btn btn-xs btn-primary">Manage</button>
</a> </a>
</td> </td>
@ -116,6 +116,11 @@
@endforeach @endforeach
</table> </table>
</div> </div>
@if($databases->hasPages())
<div class="box-footer with-border">
<div class="col-md-12 text-center">{!! $databases->render() !!}</div>
</div>
@endif
</div> </div>
</div> </div>
</div> </div>