Skip to content

Commit

Permalink
Merge pull request #905 from biigle/joinedUsers
Browse files Browse the repository at this point in the history
View recently joined users in admin area
  • Loading branch information
mzur authored Aug 22, 2024
2 parents a8117e4 + 125f669 commit 99bbd57
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
10 changes: 9 additions & 1 deletion app/Http/Controllers/Views/Admin/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class UsersController extends Controller
*/
public function get(Request $request)
{
$users = User::select('id', 'firstname', 'lastname', 'email', 'login_at', 'role_id', 'affiliation')
$users = User::select('id', 'firstname', 'lastname', 'email', 'login_at', 'created_at', 'role_id', 'affiliation')
->when($request->has('q'), function ($query) use ($request) {
$q = $request->get('q');
$query->where(function ($query) use ($q) {
Expand All @@ -32,6 +32,10 @@ public function get(Request $request)
->orWhere('email', 'ilike', "%$q%");
});
})
->when(
$request->get('recent'),
fn ($query) => $query->where('created_at', '>=', now()->subWeek())
)
// Orders by login_at in descending order (most recent first) but puts
// users with login_at=NULL at the end.
->orderByRaw('login_at IS NULL, login_at DESC')
Expand All @@ -44,11 +48,15 @@ public function get(Request $request)
Role::guestId() => 'Guest',
];

$usersCount = User::whereDate('created_at', '>=', now()->subWeek())
->count();

return view('admin.users', [
'users' => $users,
'roleClass' => $this->roleClassMap(),
'roleNames' => $roleNames,
'query' => $request->get('q'),
'usersCount' => $usersCount
]);
}

Expand Down
20 changes: 13 additions & 7 deletions resources/views/admin/users.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@
The user was deleted.
</div>
@endif
<a href="{{route('admin-users-new')}}" class="btn btn-default" title="Create a new user">New user</a>
<form class="form-inline inline-block-form" action="{{route('admin-users')}}" method="get">
<input class="form-control" type="text" name="q" placeholder="Search users" value="{{$query}}">
</form>
@if ($query)
<a href="{{route('admin-users')}}" class="btn btn-info" title="Clear filtering"><i class="fas fa-times"></i></a>
@endif
<div class="clearfix">
<form class="form-inline inline-block-form" action="{{route('admin-users')}}" method="get">
<input class="form-control" type="text" name="q" placeholder="Search users" value="{{$query}}">
</form>
@if ($query)
<a href="{{route('admin-users')}}" class="btn btn-info" title="Clear filtering"><i class="fas fa-times"></i></a>
@endif
<a @if (request('recent')) href="{{route('admin-users')}}" class="btn btn-info active" @else href="{{route('admin-users')}}?recent=1" class="btn btn-default" @endif title="Show users who joined within the last 7 days">
Recently joined
<span class="badge">{{$usersCount}}</span>
</a>
<a href="{{route('admin-users-new')}}" class="btn btn-default pull-right" title="Create a new user">New user</a>
</div>
<table class="table table-hover">
<thead>
<tr>
Expand Down

0 comments on commit 99bbd57

Please sign in to comment.