Skip to content

Commit c739f29

Browse files
committed
paginate databases when viewing a host
1 parent e8cb441 commit c739f29

File tree

7 files changed

+47
-50
lines changed

7 files changed

+47
-50
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
77
### Fixed
88
* Fixes application API keys being created as a client API key.
99

10+
### Changed
11+
* Databases are now properly paginated when viewing a database host.
12+
1013
## v0.7.4-h1 (Derelict Dermodactylus)
1114
### Fixed
1215
* Being able to create servers is kind of a core aspect of the software, pushing releases late at night is not a great idea.

app/Contracts/Repository/DatabaseHostRepositoryInterface.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Pterodactyl\Contracts\Repository;
44

55
use Illuminate\Support\Collection;
6-
use Pterodactyl\Models\DatabaseHost;
76

87
interface DatabaseHostRepositoryInterface extends RepositoryInterface
98
{
@@ -14,15 +13,4 @@ interface DatabaseHostRepositoryInterface extends RepositoryInterface
1413
* @return \Illuminate\Support\Collection
1514
*/
1615
public function getWithViewDetails(): Collection;
17-
18-
/**
19-
* Return a database host with the databases and associated servers
20-
* that are attached to said databases.
21-
*
22-
* @param int $id
23-
* @return \Pterodactyl\Models\DatabaseHost
24-
*
25-
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
26-
*/
27-
public function getWithServers(int $id): DatabaseHost;
2816
}

app/Contracts/Repository/DatabaseRepositoryInterface.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
<?php
2-
/**
3-
* Pterodactyl - Panel
4-
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5-
*
6-
* This software is licensed under the terms of the MIT license.
7-
* https://opensource.org/licenses/MIT
8-
*/
92

103
namespace Pterodactyl\Contracts\Repository;
114

125
use Pterodactyl\Models\Database;
136
use Illuminate\Support\Collection;
7+
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
148

159
interface DatabaseRepositoryInterface extends RepositoryInterface
1610
{
@@ -39,6 +33,15 @@ public function getConnection(): string;
3933
*/
4034
public function getDatabasesForServer(int $server): Collection;
4135

36+
/**
37+
* Return all of the databases for a given host with the server relationship loaded.
38+
*
39+
* @param int $host
40+
* @param int $count
41+
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
42+
*/
43+
public function getDatabasesForHost(int $host, int $count = 25): LengthAwarePaginator;
44+
4245
/**
4346
* Create a new database if it does not already exist on the host with
4447
* the provided details.

app/Http/Controllers/Admin/DatabaseController.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
<?php
2-
/**
3-
* Pterodactyl - Panel
4-
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5-
*
6-
* This software is licensed under the terms of the MIT license.
7-
* https://opensource.org/licenses/MIT
8-
*/
92

103
namespace Pterodactyl\Http\Controllers\Admin;
114

@@ -19,6 +12,7 @@
1912
use Pterodactyl\Http\Requests\Admin\DatabaseHostFormRequest;
2013
use Pterodactyl\Services\Databases\Hosts\HostCreationService;
2114
use Pterodactyl\Services\Databases\Hosts\HostDeletionService;
15+
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
2216
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
2317
use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface;
2418

@@ -34,6 +28,11 @@ class DatabaseController extends Controller
3428
*/
3529
private $creationService;
3630

31+
/**
32+
* @var \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface
33+
*/
34+
private $databaseRepository;
35+
3736
/**
3837
* @var \Pterodactyl\Services\Databases\Hosts\HostDeletionService
3938
*/
@@ -59,6 +58,7 @@ class DatabaseController extends Controller
5958
*
6059
* @param \Prologue\Alerts\AlertsMessageBag $alert
6160
* @param \Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface $repository
61+
* @param \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface $databaseRepository
6262
* @param \Pterodactyl\Services\Databases\Hosts\HostCreationService $creationService
6363
* @param \Pterodactyl\Services\Databases\Hosts\HostDeletionService $deletionService
6464
* @param \Pterodactyl\Services\Databases\Hosts\HostUpdateService $updateService
@@ -67,13 +67,15 @@ class DatabaseController extends Controller
6767
public function __construct(
6868
AlertsMessageBag $alert,
6969
DatabaseHostRepositoryInterface $repository,
70+
DatabaseRepositoryInterface $databaseRepository,
7071
HostCreationService $creationService,
7172
HostDeletionService $deletionService,
7273
HostUpdateService $updateService,
7374
LocationRepositoryInterface $locationRepository
7475
) {
7576
$this->alert = $alert;
7677
$this->creationService = $creationService;
78+
$this->databaseRepository = $databaseRepository;
7779
$this->deletionService = $deletionService;
7880
$this->repository = $repository;
7981
$this->locationRepository = $locationRepository;
@@ -105,7 +107,8 @@ public function view(int $host): View
105107
{
106108
return view('admin.databases.view', [
107109
'locations' => $this->locationRepository->getAllWithNodes(),
108-
'host' => $this->repository->getWithServers($host),
110+
'host' => $this->repository->find($host),
111+
'databases' => $this->databaseRepository->getDatabasesForHost($host),
109112
]);
110113
}
111114

app/Repositories/Eloquent/DatabaseHostRepository.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
use Illuminate\Support\Collection;
66
use Pterodactyl\Models\DatabaseHost;
7-
use Illuminate\Database\Eloquent\ModelNotFoundException;
8-
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
97
use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface;
108

119
class DatabaseHostRepository extends EloquentRepository implements DatabaseHostRepositoryInterface
@@ -30,22 +28,4 @@ public function getWithViewDetails(): Collection
3028
{
3129
return $this->getBuilder()->withCount('databases')->with('node')->get();
3230
}
33-
34-
/**
35-
* Return a database host with the databases and associated servers
36-
* that are attached to said databases.
37-
*
38-
* @param int $id
39-
* @return \Pterodactyl\Models\DatabaseHost
40-
*
41-
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
42-
*/
43-
public function getWithServers(int $id): DatabaseHost
44-
{
45-
try {
46-
return $this->getBuilder()->with('databases.server')->findOrFail($id, $this->getColumns());
47-
} catch (ModelNotFoundException $exception) {
48-
throw new RecordNotFoundException;
49-
}
50-
}
5131
}

app/Repositories/Eloquent/DatabaseRepository.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Support\Collection;
77
use Illuminate\Foundation\Application;
88
use Illuminate\Database\DatabaseManager;
9+
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
910
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
1011
use Pterodactyl\Exceptions\Repository\DuplicateDatabaseNameException;
1112

@@ -78,6 +79,20 @@ public function getDatabasesForServer(int $server): Collection
7879
return $this->getBuilder()->where('server_id', $server)->get($this->getColumns());
7980
}
8081

82+
/**
83+
* Return all of the databases for a given host with the server relationship loaded.
84+
*
85+
* @param int $host
86+
* @param int $count
87+
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
88+
*/
89+
public function getDatabasesForHost(int $host, int $count = 25): LengthAwarePaginator
90+
{
91+
return $this->getBuilder()->with('server')
92+
->where('database_host_id', $host)
93+
->paginate($count, $this->getColumns());
94+
}
95+
8196
/**
8297
* Create a new database if it does not already exist on the host with
8398
* the provided details.

resources/themes/pterodactyl/admin/databases/view.blade.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,26 @@
101101
<th>Connections From</th>
102102
<th></th>
103103
</tr>
104-
@foreach($host->databases as $database)
104+
@foreach($databases as $database)
105105
<tr>
106-
<td class="middle"><a href="{{ route('admin.servers.view', $database->server->id) }}">{{ $database->server->name }}</a></td>
106+
<td class="middle"><a href="{{ route('admin.servers.view', $database->getRelation('server')->id) }}">{{ $database->getRelation('server')->name }}</a></td>
107107
<td class="middle">{{ $database->database }}</td>
108108
<td class="middle">{{ $database->username }}</td>
109109
<td class="middle">{{ $database->remote }}</td>
110110
<td class="text-center">
111-
<a href="{{ route('admin.servers.view.database', $database->server->id) }}">
111+
<a href="{{ route('admin.servers.view.database', $database->getRelation('server')->id) }}">
112112
<button class="btn btn-xs btn-primary">Manage</button>
113113
</a>
114114
</td>
115115
</tr>
116116
@endforeach
117117
</table>
118118
</div>
119+
@if($databases->hasPages())
120+
<div class="box-footer with-border">
121+
<div class="col-md-12 text-center">{!! $databases->render() !!}</div>
122+
</div>
123+
@endif
119124
</div>
120125
</div>
121126
</div>

0 commit comments

Comments
 (0)