@@ -51,8 +51,40 @@ public function __construct()
5151
5252 public function getIndex (Request $ request )
5353 {
54- return view ('admin.servers.index ' , [
55- 'servers ' => Models \Server::select (
54+ $ query = Models \Server::select (
55+ 'servers.* ' ,
56+ 'nodes.name as a_nodeName ' ,
57+ 'users.email as a_ownerEmail ' ,
58+ 'allocations.ip ' ,
59+ 'allocations.port ' ,
60+ 'allocations.ip_alias '
61+ )->join ('nodes ' , 'servers.node ' , '= ' , 'nodes.id ' )
62+ ->join ('users ' , 'servers.owner ' , '= ' , 'users.id ' )
63+ ->join ('allocations ' , 'servers.allocation ' , '= ' , 'allocations.id ' );
64+
65+ if ($ request ->input ('filter ' ) && !is_null ($ request ->input ('filter ' ))) {
66+ preg_match_all ('/[^\s" \']+|"([^"]*)"| \'([^ \']*) \'/ ' , urldecode ($ request ->input ('filter ' )), $ matches );
67+ foreach ($ matches [0 ] as $ match ) {
68+ $ match = str_replace ('" ' , '' , $ match );
69+ if (strpos ($ match , ': ' )) {
70+ list ($ field , $ term ) = explode (': ' , $ match );
71+ $ field = (strpos ($ field , '. ' )) ? $ field : 'servers. ' . $ field ;
72+ $ query ->orWhere ($ field , 'LIKE ' , '% ' . $ term . '% ' );
73+ } else {
74+ $ query ->where ('servers.name ' , 'LIKE ' , '% ' . $ match . '% ' );
75+ $ query ->orWhere ('servers.username ' , 'LIKE ' , '% ' . $ match . '% ' );
76+ $ query ->orWhere ('users.email ' , 'LIKE ' , '% ' . $ match . '% ' );
77+ $ query ->orWhere ('allocations.port ' , 'LIKE ' , '% ' . $ match . '% ' );
78+ $ query ->orWhere ('allocations.ip ' , 'LIKE ' , '% ' . $ match . '% ' );
79+ }
80+ }
81+ }
82+
83+ try {
84+ $ servers = $ query ->paginate (20 );
85+ } catch (\Exception $ ex ) {
86+ Alert::warning ('There was an error with the search parameters provided. ' );
87+ $ servers = Models \Server::select (
5688 'servers.* ' ,
5789 'nodes.name as a_nodeName ' ,
5890 'users.email as a_ownerEmail ' ,
@@ -62,7 +94,11 @@ public function getIndex(Request $request)
6294 )->join ('nodes ' , 'servers.node ' , '= ' , 'nodes.id ' )
6395 ->join ('users ' , 'servers.owner ' , '= ' , 'users.id ' )
6496 ->join ('allocations ' , 'servers.allocation ' , '= ' , 'allocations.id ' )
65- ->paginate (20 ),
97+ ->paginate (20 );
98+ }
99+
100+ return view ('admin.servers.index ' , [
101+ 'servers ' => $ servers
66102 ]);
67103 }
68104
0 commit comments