diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ab451c95..48f23eba7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. ### Added * Return node configuration from remote API by using `/api/nodes/{id}/config` endpoint. Only accepts SSL connections. +* Support for filtering servers within Admin CP to narrow down results by name, email, allocation, or defined fields. ### Changed * Creating a user, server, or node now returns `HTTP/1.1 200` and a JSON element with the user/server/node's ID. diff --git a/app/Http/Controllers/Admin/ServersController.php b/app/Http/Controllers/Admin/ServersController.php index 390cea64d..05cbe134d 100644 --- a/app/Http/Controllers/Admin/ServersController.php +++ b/app/Http/Controllers/Admin/ServersController.php @@ -51,8 +51,40 @@ class ServersController extends Controller public function getIndex(Request $request) { - return view('admin.servers.index', [ - 'servers' => Models\Server::select( + $query = Models\Server::select( + 'servers.*', + 'nodes.name as a_nodeName', + 'users.email as a_ownerEmail', + 'allocations.ip', + 'allocations.port', + 'allocations.ip_alias' + )->join('nodes', 'servers.node', '=', 'nodes.id') + ->join('users', 'servers.owner', '=', 'users.id') + ->join('allocations', 'servers.allocation', '=', 'allocations.id'); + + if ($request->input('filter') && !is_null($request->input('filter'))) { + preg_match_all('/[^\s"\']+|"([^"]*)"|\'([^\']*)\'/', urldecode($request->input('filter')), $matches); + foreach($matches[0] as $match) { + $match = str_replace('"', '', $match); + if (strpos($match, ':')) { + list($field, $term) = explode(':', $match); + $field = (strpos($field, '.')) ? $field : 'servers.' . $field; + $query->orWhere($field, 'LIKE', '%' . $term . '%'); + } else { + $query->where('servers.name', 'LIKE', '%' . $match . '%'); + $query->orWhere('servers.username', 'LIKE', '%' . $match . '%'); + $query->orWhere('users.email', 'LIKE', '%' . $match . '%'); + $query->orWhere('allocations.port', 'LIKE', '%' . $match . '%'); + $query->orWhere('allocations.ip', 'LIKE', '%' . $match . '%'); + } + } + } + + try { + $servers = $query->paginate(20); + } catch (\Exception $ex) { + Alert::warning('There was an error with the search parameters provided.'); + $servers = Models\Server::select( 'servers.*', 'nodes.name as a_nodeName', 'users.email as a_ownerEmail', @@ -62,7 +94,11 @@ class ServersController extends Controller )->join('nodes', 'servers.node', '=', 'nodes.id') ->join('users', 'servers.owner', '=', 'users.id') ->join('allocations', 'servers.allocation', '=', 'allocations.id') - ->paginate(20), + ->paginate(20); + } + + return view('admin.servers.index', [ + 'servers' => $servers ]); } diff --git a/resources/views/admin/servers/index.blade.php b/resources/views/admin/servers/index.blade.php index a1bf5611a..7ad8d3a52 100644 --- a/resources/views/admin/servers/index.blade.php +++ b/resources/views/admin/servers/index.blade.php @@ -30,6 +30,14 @@
  • Servers
  • All Servers


    +
    +
    + +
    + +
    +
    +