Skip to content

Commit cbeecfe

Browse files
committed
Implement front-end server searching 🍬
1 parent 27d4721 commit cbeecfe

File tree

7 files changed

+30
-15
lines changed

7 files changed

+30
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
1212

1313
### Added
1414
* Login attempts and pasword reset requests are now protected by invisible ReCaptcha. This feature can be disabled with a `.env` variable.
15+
* Server listing for individual users is now searchable on the front-end.
1516

1617
### Changed
1718
* Subuser permissions are now stored in `Permission::list()` to make views way cleaner and make adding to views significantly cleaner.

app/Http/Controllers/API/User/InfoController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class InfoController extends BaseController
3131
{
3232
public function me(Request $request)
3333
{
34-
return $request->user()->serverAccessCollection()->load('allocation', 'option')->map(function ($server) {
34+
return $request->user()->access('service', 'node', 'allocation', 'option')->get()->map(function ($server) {
3535
return [
3636
'id' => $server->uuidShort,
3737
'uuid' => $server->uuid,

app/Http/Controllers/Base/IndexController.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,14 @@ class IndexController extends Controller
3838
*/
3939
public function getIndex(Request $request)
4040
{
41+
$servers = $request->user()->access();
42+
43+
if (! is_null($request->input('query'))) {
44+
$servers->search($request->input('query'));
45+
}
46+
4147
return view('base.index', [
42-
'servers' => $request->user()->serverAccessCollection(config('pterodactyl.paginate.frontend.servers')),
48+
'servers' => $servers->paginate(config('pterodactyl.paginate.frontend.servers')),
4349
]);
4450
}
4551

app/Models/User.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
103103
],
104104
];
105105

106+
protected $query;
107+
106108
/**
107109
* Enables or disables TOTP on an account if the token is valid.
108110
*
@@ -200,18 +202,22 @@ public function serverAccessArray()
200202
* Returns an array of all servers a user is able to access.
201203
* Note: does not account for user admin status.
202204
*
203-
* @param int|null $paginate
204-
* @param array $load
205-
* @return \Illuminate\Pagination\LengthAwarePagination|\Illuiminate\Database\Eloquent\Collection
205+
* @param array $load
206+
* @return \Illuiminate\Database\Eloquent\Builder
206207
*/
207-
public function serverAccessCollection($paginate = null, $load = ['service', 'node', 'allocation'])
208+
public function access(...$load)
208209
{
209-
$query = Server::with($load);
210+
if (count($load) > 0 && is_null($load[0])) {
211+
$query = Server::query();
212+
} else {
213+
$query = Server::with(! empty($load) ? $load : ['service', 'node', 'allocation']);
214+
}
215+
210216
if (! $this->isRootAdmin()) {
211217
$query->whereIn('id', $this->serverAccessArray());
212218
}
213219

214-
return (is_numeric($paginate)) ? $query->paginate($paginate) : $query->get();
220+
return $query;
215221
}
216222

217223
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
</tr>
130130
</thead>
131131
<tbody>
132-
@foreach($user->serverAccessCollection() as $server)
132+
@foreach($user->access()->get() as $server)
133133
<tr>
134134
<td><a href="{{ route('server.index', $server->uuidShort) }}/"><i class="fa fa-tachometer"></i></a></td>
135135
<td><code>{{ $server->uuidShort }}</code></td>

resources/themes/pterodactyl/base/index.blade.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@
3838
<div class="box-header">
3939
<h3 class="box-title">@lang('base.index.list')</h3>
4040
<div class="box-tools">
41-
<div class="input-group input-group-sm" style="width: 150px;">
42-
<input type="text" name="table_search" class="form-control pull-right" placeholder="@lang('strings.search')">
43-
<div class="input-group-btn">
44-
<button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button>
41+
<form action="{{ route('index') }}" method="GET">
42+
<div class="input-group input-group-sm" style="width: 250px;">
43+
<input type="text" name="query" class="form-control pull-right" value="{{ request()->input('query') }}" placeholder="@lang('strings.search')">
44+
<div class="input-group-btn">
45+
<button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button>
46+
</div>
4547
</div>
46-
</div>
48+
</form>
4749
</div>
4850
</div>
4951
<div class="box-body table-responsive no-padding">

resources/themes/pterodactyl/layouts/master.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ class="active"
235235
<aside class="control-sidebar control-sidebar-dark">
236236
<div class="tab-content">
237237
<ul class="control-sidebar-menu">
238-
@foreach (Auth::user()->serverAccessCollection(null, []) as $s)
238+
@foreach (Auth::user()->access(null)->get() as $s)
239239
<li>
240240
<a
241241
@if(isset($server) && isset($node))

0 commit comments

Comments
 (0)