Skip to content

Commit 3cd0a83

Browse files
committed
Add ability to filter user list
1 parent ed5b755 commit 3cd0a83

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
77
### Added
88
* Changing node configuration values now automatically makes a call to the daemon and updates the configuration there. Changing daemon tokens now does not require any intervention, and takes effect immediately. SSL & Port configurations will still require a daemon reboot.
99
* New button in file manager that triggers the right click menu to enable support on mobile devices and those who cannot right click (blessed be them).
10+
* Support for filtering users when listing all users on the system.
1011

1112
### Changed
1213
* File uploads now account for a maximum file size that is assigned for the daemon, and gives cleaner errors when that limit is reached.

app/Http/Controllers/Admin/UserController.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,33 @@ public function __construct()
5151

5252
public function getIndex(Request $request)
5353
{
54+
$query = User::select('users.*');
55+
if ($request->input('filter') && !is_null($request->input('filter'))) {
56+
preg_match_all('/[^\s"\']+|"([^"]*)"|\'([^\']*)\'/', urldecode($request->input('filter')), $matches);
57+
foreach($matches[0] as $match) {
58+
$match = str_replace('"', '', $match);
59+
if (strpos($match, ':')) {
60+
list($field, $term) = explode(':', $match);
61+
$query->orWhere($field, 'LIKE', '%' . $term . '%');
62+
} else {
63+
$query->where('email', 'LIKE', '%' . $match . '%');
64+
$query->orWhere([
65+
['uuid', 'LIKE', '%' . $match . '%'],
66+
['root_admin', 'LIKE', '%' . $match . '%']
67+
]);
68+
}
69+
}
70+
}
71+
72+
try {
73+
$users = $query->paginate(20);
74+
} catch (\Exception $ex) {
75+
Alert::warning('There was an error with the search parameters provided.');
76+
$users = User::all()->paginate(20);
77+
}
78+
5479
return view('admin.users.index', [
55-
'users' => User::paginate(20)
80+
'users' => $users
5681
]);
5782
}
5883

resources/views/admin/users/index.blade.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
<li class="active">Accounts</li>
3232
</ul>
3333
<h3>All Registered Users</h3><hr />
34+
<form method="GET" style="margin-bottom:20px;">
35+
<div class="input-group">
36+
<input type="text" name="filter" class="form-control" value="{{ urldecode(Input::get('filter')) }}" placeholder="search term" />
37+
<div class="input-group-btn">
38+
<button type="submit" class="btn btn-sm btn-primary">Filter Users</button>
39+
</div>
40+
</div>
41+
</form>
3442
<table class="table table-striped table-bordered table-hover">
3543
<thead>
3644
<tr>

0 commit comments

Comments
 (0)