Skip to content

Commit b926d43

Browse files
committed
Thats enough re-theming for the day...
1 parent 911434d commit b926d43

File tree

15 files changed

+734
-39
lines changed

15 files changed

+734
-39
lines changed

app/Http/Controllers/Admin/ServersController.php

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,16 @@ public function __construct()
4646

4747
public function getIndex(Request $request)
4848
{
49+
$servers = Models\Server::withTrashed()->with(
50+
'node', 'user', 'allocation'
51+
);
52+
53+
if (! is_null($request->input('query'))) {
54+
$servers->search($request->input('query'));
55+
}
56+
4957
return view('admin.servers.index', [
50-
'servers' => Models\Server::withTrashed()->with('node', 'user')->paginate(25),
58+
'servers' => $servers->paginate(25),
5159
]);
5260
}
5361

@@ -109,13 +117,25 @@ public function postNewServer(Request $request)
109117
*/
110118
public function postNewServerGetNodes(Request $request)
111119
{
112-
if (! $request->input('location')) {
113-
return response()->json([
114-
'error' => 'Missing location in request.',
115-
], 500);
116-
}
117-
118-
return response()->json(Models\Node::select('id', 'name', 'public')->where('location_id', $request->input('location'))->get());
120+
$nodes = Models\Node::with('allocations')->where('location_id', $request->input('location'))->get();
121+
return $nodes->map(function ($item) {
122+
$filtered = $item->allocations->map(function($map) {
123+
return collect($map)->only(['ip', 'port']);
124+
});
125+
126+
$item->ports = $filtered->unique('ip')->map(function ($map) use ($item) {
127+
return [
128+
'ip' => $map['ip'],
129+
'ports' => $item->allocations->where('ip', $map['ip'])->pluck('port')->all(),
130+
];
131+
})->values();
132+
133+
return [
134+
'id' => $item->id,
135+
'text' => $item->name,
136+
'allocations' => $item->ports,
137+
];
138+
})->values();
119139
}
120140

121141
/**
@@ -126,24 +146,7 @@ public function postNewServerGetNodes(Request $request)
126146
*/
127147
public function postNewServerGetIps(Request $request)
128148
{
129-
if (! $request->input('node')) {
130-
return response()->json([
131-
'error' => 'Missing node in request.',
132-
], 500);
133-
}
134-
135-
$ips = Models\Allocation::where('node_id', $request->input('node'))->whereNull('server_id')->get();
136-
$listing = [];
137-
138-
foreach ($ips as &$ip) {
139-
if (array_key_exists($ip->ip, $listing)) {
140-
$listing[$ip->ip] = array_merge($listing[$ip->ip], [$ip->port]);
141-
} else {
142-
$listing[$ip->ip] = [$ip->port];
143-
}
144-
}
145-
146-
return response()->json($listing);
149+
return Models\Allocation::select('id', 'ip')->where('node_id', $request->input('node'))->whereNull('server_id')->get()->unique('ip')->values()->all();
147150
}
148151

149152
/**

app/Http/Controllers/Admin/UserController.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ public function updateUser(Request $request, $user)
124124

125125
public function getJson(Request $request)
126126
{
127-
return User::select('email')->get()->pluck('email');
127+
return User::select('id', 'email', 'username', 'name_first', 'name_last')
128+
->search($request->input('q'))
129+
->get()->transform(function ($item) {
130+
$item->md5 = md5(strtolower($item->email));
131+
132+
return $item;
133+
});
128134
}
129135
}

app/Http/Middleware/AdminAuthenticate.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ public function handle($request, Closure $next)
6969
return abort(403);
7070
}
7171

72-
// @TODO: eventually update admin themes
73-
Theme::set('default');
74-
7572
return $next($request);
7673
}
7774
}

app/Http/Routes/AdminRoutes.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,22 @@ public function map(Router $router)
136136

137137
// Assorted Page Helpers
138138
$router->post('/new/get-nodes', [
139+
'as' => 'admin.servers.new.get-nodes',
139140
'uses' => 'Admin\ServersController@postNewServerGetNodes',
140141
]);
141142

142143
$router->post('/new/get-ips', [
144+
'as' => 'admin.servers.new.get-ips',
143145
'uses' => 'Admin\ServersController@postNewServerGetIps',
144146
]);
145147

146148
$router->post('/new/service-options', [
149+
'as' => 'admin.servers.new.service-options',
147150
'uses' => 'Admin\ServersController@postNewServerServiceOption',
148151
]);
149152

150153
$router->post('/new/option-details', [
154+
'as' => 'admin.servers.new.option-details',
151155
'uses' => 'Admin\ServersController@postNewServerOptionDetails',
152156
]);
153157
// End Assorted Page Helpers

app/Models/Server.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@
2929
use Javascript;
3030
use Illuminate\Database\Eloquent\Model;
3131
use Illuminate\Notifications\Notifiable;
32+
use Nicolaslopezj\Searchable\SearchableTrait;
3233
use Illuminate\Database\Eloquent\SoftDeletes;
3334

3435
class Server extends Model
3536
{
36-
use Notifiable, SoftDeletes;
37+
use Notifiable, SearchableTrait, SoftDeletes;
3738

3839
/**
3940
* The table associated with the model.
@@ -85,6 +86,22 @@ class Server extends Model
8586
'installed' => 'integer',
8687
];
8788

89+
protected $searchable = [
90+
'columns' => [
91+
'servers.name' => 10,
92+
'servers.username' => 10,
93+
'servers.uuidShort' => 9,
94+
'servers.uuid' => 8,
95+
'users.email' => 6,
96+
'users.username' => 6,
97+
'nodes.name' => 2,
98+
],
99+
'joins' => [
100+
'users' => ['users.id', 'servers.owner_id'],
101+
'nodes' => ['nodes.id', 'servers.node_id'],
102+
],
103+
];
104+
88105
/**
89106
* Returns a single server specified by UUID.
90107
* DO NOT USE THIS TO MODIFY SERVER DETAILS OR SAVE THOSE DETAILS.

app/Models/User.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use Illuminate\Database\Eloquent\Model;
3131
use Illuminate\Notifications\Notifiable;
3232
use Pterodactyl\Exceptions\DisplayException;
33+
use Nicolaslopezj\Searchable\SearchableTrait;
3334
use Illuminate\Auth\Passwords\CanResetPassword;
3435
use Illuminate\Foundation\Auth\Access\Authorizable;
3536
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
@@ -39,7 +40,7 @@
3940

4041
class User extends Model implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract
4142
{
42-
use Authenticatable, Authorizable, CanResetPassword, Notifiable;
43+
use Authenticatable, Authorizable, CanResetPassword, Notifiable, SearchableTrait;
4344

4445
/**
4546
* The rules for user passwords.
@@ -87,6 +88,16 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
8788
*/
8889
protected $hidden = ['password', 'remember_token', 'totp_secret'];
8990

91+
protected $searchable = [
92+
'columns' => [
93+
'email' => 10,
94+
'username' => 9,
95+
'name_first' => 6,
96+
'name_last' => 6,
97+
'uuid' => 1,
98+
],
99+
];
100+
90101
/**
91102
* Enables or disables TOTP on an account if the token is valid.
92103
*

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"predis/predis": "1.1.1",
3030
"fideloper/proxy": "3.2.0",
3131
"laracasts/utilities": "2.1.0",
32-
"lord/laroute": "2.3.0"
32+
"lord/laroute": "2.3.0",
33+
"nicolaslopezj/searchable": "1.9.5"
3334
},
3435
"require-dev": {
3536
"fzaninotto/faker": "~1.4",

composer.lock

Lines changed: 48 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/laroute.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/themes/pterodactyl/css/pterodactyl.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,20 @@ td.has-progress {
132132
.no-margin {
133133
margin: 0 !important;
134134
}
135+
136+
li.select2-results__option--highlighted[aria-selected="false"] > .user-block > .username > a {
137+
color: #fff;
138+
}
139+
140+
li.select2-results__option--highlighted[aria-selected="false"] > .user-block > .description {
141+
color: #eee;
142+
}
143+
144+
.img-bordered-xs {
145+
border: 1px solid #d2d6de;
146+
padding: 1px;
147+
}
148+
149+
span[aria-labelledby="select2-pOwner-container"] {
150+
padding-left: 2px !important;
151+
}

0 commit comments

Comments
 (0)