Thats enough re-theming for the day...

This commit is contained in:
Dane Everitt 2017-02-18 19:31:44 -05:00
parent 911434d033
commit b926d432e8
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
15 changed files with 733 additions and 38 deletions

View file

@ -46,8 +46,16 @@ class ServersController extends Controller
public function getIndex(Request $request)
{
$servers = Models\Server::withTrashed()->with(
'node', 'user', 'allocation'
);
if (! is_null($request->input('query'))) {
$servers->search($request->input('query'));
}
return view('admin.servers.index', [
'servers' => Models\Server::withTrashed()->with('node', 'user')->paginate(25),
'servers' => $servers->paginate(25),
]);
}
@ -109,13 +117,25 @@ class ServersController extends Controller
*/
public function postNewServerGetNodes(Request $request)
{
if (! $request->input('location')) {
return response()->json([
'error' => 'Missing location in request.',
], 500);
}
$nodes = Models\Node::with('allocations')->where('location_id', $request->input('location'))->get();
return $nodes->map(function ($item) {
$filtered = $item->allocations->map(function($map) {
return collect($map)->only(['ip', 'port']);
});
return response()->json(Models\Node::select('id', 'name', 'public')->where('location_id', $request->input('location'))->get());
$item->ports = $filtered->unique('ip')->map(function ($map) use ($item) {
return [
'ip' => $map['ip'],
'ports' => $item->allocations->where('ip', $map['ip'])->pluck('port')->all(),
];
})->values();
return [
'id' => $item->id,
'text' => $item->name,
'allocations' => $item->ports,
];
})->values();
}
/**
@ -126,24 +146,7 @@ class ServersController extends Controller
*/
public function postNewServerGetIps(Request $request)
{
if (! $request->input('node')) {
return response()->json([
'error' => 'Missing node in request.',
], 500);
}
$ips = Models\Allocation::where('node_id', $request->input('node'))->whereNull('server_id')->get();
$listing = [];
foreach ($ips as &$ip) {
if (array_key_exists($ip->ip, $listing)) {
$listing[$ip->ip] = array_merge($listing[$ip->ip], [$ip->port]);
} else {
$listing[$ip->ip] = [$ip->port];
}
}
return response()->json($listing);
return Models\Allocation::select('id', 'ip')->where('node_id', $request->input('node'))->whereNull('server_id')->get()->unique('ip')->values()->all();
}
/**

View file

@ -124,6 +124,12 @@ class UserController extends Controller
public function getJson(Request $request)
{
return User::select('email')->get()->pluck('email');
return User::select('id', 'email', 'username', 'name_first', 'name_last')
->search($request->input('q'))
->get()->transform(function ($item) {
$item->md5 = md5(strtolower($item->email));
return $item;
});
}
}

View file

@ -69,9 +69,6 @@ class AdminAuthenticate
return abort(403);
}
// @TODO: eventually update admin themes
Theme::set('default');
return $next($request);
}
}

View file

@ -136,18 +136,22 @@ class AdminRoutes
// Assorted Page Helpers
$router->post('/new/get-nodes', [
'as' => 'admin.servers.new.get-nodes',
'uses' => 'Admin\ServersController@postNewServerGetNodes',
]);
$router->post('/new/get-ips', [
'as' => 'admin.servers.new.get-ips',
'uses' => 'Admin\ServersController@postNewServerGetIps',
]);
$router->post('/new/service-options', [
'as' => 'admin.servers.new.service-options',
'uses' => 'Admin\ServersController@postNewServerServiceOption',
]);
$router->post('/new/option-details', [
'as' => 'admin.servers.new.option-details',
'uses' => 'Admin\ServersController@postNewServerOptionDetails',
]);
// End Assorted Page Helpers

View file

@ -29,11 +29,12 @@ use Cache;
use Javascript;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Nicolaslopezj\Searchable\SearchableTrait;
use Illuminate\Database\Eloquent\SoftDeletes;
class Server extends Model
{
use Notifiable, SoftDeletes;
use Notifiable, SearchableTrait, SoftDeletes;
/**
* The table associated with the model.
@ -85,6 +86,22 @@ class Server extends Model
'installed' => 'integer',
];
protected $searchable = [
'columns' => [
'servers.name' => 10,
'servers.username' => 10,
'servers.uuidShort' => 9,
'servers.uuid' => 8,
'users.email' => 6,
'users.username' => 6,
'nodes.name' => 2,
],
'joins' => [
'users' => ['users.id', 'servers.owner_id'],
'nodes' => ['nodes.id', 'servers.node_id'],
],
];
/**
* Returns a single server specified by UUID.
* DO NOT USE THIS TO MODIFY SERVER DETAILS OR SAVE THOSE DETAILS.

View file

@ -30,6 +30,7 @@ use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Pterodactyl\Exceptions\DisplayException;
use Nicolaslopezj\Searchable\SearchableTrait;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
@ -39,7 +40,7 @@ use Pterodactyl\Notifications\SendPasswordReset as ResetPasswordNotification;
class User extends Model implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract
{
use Authenticatable, Authorizable, CanResetPassword, Notifiable;
use Authenticatable, Authorizable, CanResetPassword, Notifiable, SearchableTrait;
/**
* The rules for user passwords.
@ -87,6 +88,16 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
*/
protected $hidden = ['password', 'remember_token', 'totp_secret'];
protected $searchable = [
'columns' => [
'email' => 10,
'username' => 9,
'name_first' => 6,
'name_last' => 6,
'uuid' => 1,
],
];
/**
* Enables or disables TOTP on an account if the token is valid.
*