From 484c5582ab7f1babb1d2f46f9f5264393076e3eb Mon Sep 17 00:00:00 2001 From: aneust Date: Sat, 17 Aug 2024 13:54:39 +0200 Subject: [PATCH 1/9] Added a "Recently joined" button to the admin users page - This button filters and displays users who have recently joined within the last 7 days. - The button shows a badge with the count of such users. - This enhancement makes it easier for admins to quickly access and review the most recently joined users. --- resources/views/admin/users.blade.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/resources/views/admin/users.blade.php b/resources/views/admin/users.blade.php index b2fcdc5a3..5e8d20512 100644 --- a/resources/views/admin/users.blade.php +++ b/resources/views/admin/users.blade.php @@ -8,13 +8,17 @@ The user was deleted. @endif -New user + + Recently joined + {{$usersCount}} +
@if ($query) @endif +New user From 1354be81dcaffde7d5aee46a5c47f9f41917bd5f Mon Sep 17 00:00:00 2001 From: aneust Date: Sat, 17 Aug 2024 14:08:27 +0200 Subject: [PATCH 2/9] Implemented function to display recently joined users --- .../Views/Admin/UsersController.php | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Views/Admin/UsersController.php b/app/Http/Controllers/Views/Admin/UsersController.php index 8bd7a75cf..3260f6541 100644 --- a/app/Http/Controllers/Views/Admin/UsersController.php +++ b/app/Http/Controllers/Views/Admin/UsersController.php @@ -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) { @@ -44,11 +44,51 @@ public function get(Request $request) Role::guestId() => 'Guest', ]; + $usersCount = User::whereDate('created_at', '>=', now()->subDays(7)->setTime(0, 0, 0)->toDateTimeString()) + ->count(); + return view('admin.users', [ 'users' => $users, 'roleClass' => $this->roleClassMap(), 'roleNames' => $roleNames, 'query' => $request->get('q'), + 'usersCount' => $usersCount + ]); + } + + /** + * Shows newest users. + * + * @return \Illuminate\Http\Response + */ + public function getRecentUsers() + { + /* +
+ + {{$usersCount}} + */ + // Fetch users created in the last 7 days + $users = User::select('id', 'firstname', 'lastname', 'email', 'login_at', 'created_at', 'role_id', 'affiliation') + // Orders by created_at in descending order + ->whereDate('created_at', '>=', now()->subDays(7)->setTime(0, 0, 0)->toDateTimeString()) + ->orderBy('created_at', 'desc') + ->paginate(100); + + $roleNames = [ + Role::adminId() => 'Admin', + Role::editorId() => 'Editor', + Role::guestId() => 'Guest', + ]; + + // $usersCount = User::whereDate('created_at', '>=', now()->subDays(7)->setTime(0, 0, 0)->toDateTimeString())->count(); + $usersCount = $users->total(); + + return view('admin.users.recent', [ + 'users' => $users, + 'roleNames' => $roleNames, + 'usersCount' => $usersCount, + 'roleClass' => $this->roleClassMap(), ]); } From 03c912638467e8f58be0f8c68e58b14a3af8607c Mon Sep 17 00:00:00 2001 From: aneust Date: Sat, 17 Aug 2024 14:14:23 +0200 Subject: [PATCH 3/9] Added route for displaying recently joined users in the admin area --- routes/web.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/routes/web.php b/routes/web.php index 0970d1c79..e8aa3c2e3 100644 --- a/routes/web.php +++ b/routes/web.php @@ -114,6 +114,11 @@ 'uses' => 'UsersController@get', ]); + $router->get('users/recent', [ + 'as' => 'admin-users-recent', + 'uses' => 'UsersController@getRecentUsers', + ]); + $router->get('users/new', [ 'as' => 'admin-users-new', 'uses' => 'UsersController@newUser', From 165fc5808051803b4a8ef958b6f9fcf9b2d30893 Mon Sep 17 00:00:00 2001 From: aneust Date: Sat, 17 Aug 2024 14:16:03 +0200 Subject: [PATCH 4/9] Created 'Recent Users' view to admin area --- resources/views/admin/users/recent.blade.php | 62 ++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 resources/views/admin/users/recent.blade.php diff --git a/resources/views/admin/users/recent.blade.php b/resources/views/admin/users/recent.blade.php new file mode 100644 index 000000000..5ee480ded --- /dev/null +++ b/resources/views/admin/users/recent.blade.php @@ -0,0 +1,62 @@ +@extends('admin.base') + +@section('title', 'Recent Users') + +@section('admin-content') +@if ($usersCount > 0) + +@endif +
+ + + + + + + + + + + + @forelse($users as $u) + + + + + + + + + @empty + + + + @endforelse + +
NameEmailRoleAffiliationActivityCreated
+ {{$u->firstname}} {{$u->lastname}} + {{$u->email}} + {{$roleNames[$u->role_id][0]}} + + @if ($u->affiliation) + {{Str::limit($u->affiliation, 20)}} + @else + none + @endif + + @if ($u->login_at) + + @else + none + @endif + + +
+ No users found. +
+ +@endsection \ No newline at end of file From 4cfe7631b6cad153f7aa3def449f6a48cc988891 Mon Sep 17 00:00:00 2001 From: aneust Date: Sat, 17 Aug 2024 16:36:10 +0200 Subject: [PATCH 5/9] Adjusted the view to display only a message, when no new users found --- resources/views/admin/users/recent.blade.php | 98 ++++++++++---------- 1 file changed, 48 insertions(+), 50 deletions(-) diff --git a/resources/views/admin/users/recent.blade.php b/resources/views/admin/users/recent.blade.php index 5ee480ded..ca00d554a 100644 --- a/resources/views/admin/users/recent.blade.php +++ b/resources/views/admin/users/recent.blade.php @@ -7,56 +7,54 @@ -@endif - - - - - - - - - - - - - @forelse($users as $u) - - - - - - - - - @empty +
NameEmailRoleAffiliationActivityCreated
- {{$u->firstname}} {{$u->lastname}} - {{$u->email}} - {{$roleNames[$u->role_id][0]}} - - @if ($u->affiliation) - {{Str::limit($u->affiliation, 20)}} - @else - none - @endif - - @if ($u->login_at) - - @else - none - @endif - - -
+ - + + + + + + - @endforelse - -
- No users found. - NameEmailRoleAffiliationActivityCreated
- + + + @foreach($users as $u) + + + {{$u->firstname}} {{$u->lastname}} + + {{$u->email}} + + {{$roleNames[$u->role_id][0]}} + + + @if ($u->affiliation) + {{Str::limit($u->affiliation, 20)}} + @else + none + @endif + + + @if ($u->login_at) + + @else + none + @endif + + + + + + @endforeach + + + +@else + +@endif @endsection \ No newline at end of file From 6f03b397bbf49ce49f5ea1baf65865b0733aecc8 Mon Sep 17 00:00:00 2001 From: aneust Date: Wed, 21 Aug 2024 20:16:58 +0200 Subject: [PATCH 6/9] Rearranged fields search input, "recently joined" button, "new user" button --- resources/views/admin/users.blade.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/resources/views/admin/users.blade.php b/resources/views/admin/users.blade.php index 5e8d20512..62398b46d 100644 --- a/resources/views/admin/users.blade.php +++ b/resources/views/admin/users.blade.php @@ -8,16 +8,19 @@ The user was deleted. @endif - - Recently joined - {{$usersCount}} -
@if ($query) @endif + + Recently joined + {{$usersCount}} + +@if(request('recent')) + +@endif New user From 70a96b16e544df07035bb5f06b355fe7d9a57126 Mon Sep 17 00:00:00 2001 From: aneust Date: Wed, 21 Aug 2024 20:22:06 +0200 Subject: [PATCH 7/9] Removed "recent user" view instead the list of users is filtered in the same view --- resources/views/admin/users/recent.blade.php | 60 -------------------- routes/web.php | 5 -- 2 files changed, 65 deletions(-) delete mode 100644 resources/views/admin/users/recent.blade.php diff --git a/resources/views/admin/users/recent.blade.php b/resources/views/admin/users/recent.blade.php deleted file mode 100644 index ca00d554a..000000000 --- a/resources/views/admin/users/recent.blade.php +++ /dev/null @@ -1,60 +0,0 @@ -@extends('admin.base') - -@section('title', 'Recent Users') - -@section('admin-content') -@if ($usersCount > 0) - -
- - - - - - - - - - - - @foreach($users as $u) - - - - - - - - - @endforeach - -
NameEmailRoleAffiliationActivityCreated
- {{$u->firstname}} {{$u->lastname}} - {{$u->email}} - {{$roleNames[$u->role_id][0]}} - - @if ($u->affiliation) - {{Str::limit($u->affiliation, 20)}} - @else - none - @endif - - @if ($u->login_at) - - @else - none - @endif - - -
- -@else - -@endif -@endsection \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index e8aa3c2e3..0970d1c79 100644 --- a/routes/web.php +++ b/routes/web.php @@ -114,11 +114,6 @@ 'uses' => 'UsersController@get', ]); - $router->get('users/recent', [ - 'as' => 'admin-users-recent', - 'uses' => 'UsersController@getRecentUsers', - ]); - $router->get('users/new', [ 'as' => 'admin-users-new', 'uses' => 'UsersController@newUser', From 8c820ec9143d89d6118ed6d3156535acea473ac5 Mon Sep 17 00:00:00 2001 From: aneust Date: Wed, 21 Aug 2024 20:23:15 +0200 Subject: [PATCH 8/9] Applied requested changes --- .../Views/Admin/UsersController.php | 42 +++---------------- 1 file changed, 5 insertions(+), 37 deletions(-) diff --git a/app/Http/Controllers/Views/Admin/UsersController.php b/app/Http/Controllers/Views/Admin/UsersController.php index 3260f6541..96be5209e 100644 --- a/app/Http/Controllers/Views/Admin/UsersController.php +++ b/app/Http/Controllers/Views/Admin/UsersController.php @@ -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') @@ -44,7 +48,7 @@ public function get(Request $request) Role::guestId() => 'Guest', ]; - $usersCount = User::whereDate('created_at', '>=', now()->subDays(7)->setTime(0, 0, 0)->toDateTimeString()) + $usersCount = User::whereDate('created_at', '>=', now()->subWeek()) ->count(); return view('admin.users', [ @@ -56,42 +60,6 @@ public function get(Request $request) ]); } - /** - * Shows newest users. - * - * @return \Illuminate\Http\Response - */ - public function getRecentUsers() - { - /* -
- - {{$usersCount}} -
*/ - // Fetch users created in the last 7 days - $users = User::select('id', 'firstname', 'lastname', 'email', 'login_at', 'created_at', 'role_id', 'affiliation') - // Orders by created_at in descending order - ->whereDate('created_at', '>=', now()->subDays(7)->setTime(0, 0, 0)->toDateTimeString()) - ->orderBy('created_at', 'desc') - ->paginate(100); - - $roleNames = [ - Role::adminId() => 'Admin', - Role::editorId() => 'Editor', - Role::guestId() => 'Guest', - ]; - - // $usersCount = User::whereDate('created_at', '>=', now()->subDays(7)->setTime(0, 0, 0)->toDateTimeString())->count(); - $usersCount = $users->total(); - - return view('admin.users.recent', [ - 'users' => $users, - 'roleNames' => $roleNames, - 'usersCount' => $usersCount, - 'roleClass' => $this->roleClassMap(), - ]); - } - /** * Shows the admin new user page. * From 125f669ed196753e8b377fe5ff49ffa961e56c38 Mon Sep 17 00:00:00 2001 From: Martin Zurowietz Date: Thu, 22 Aug 2024 08:19:15 +0200 Subject: [PATCH 9/9] Tweak UI of recent users filtering in admin area --- resources/views/admin/users.blade.php | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/resources/views/admin/users.blade.php b/resources/views/admin/users.blade.php index 62398b46d..ac2100843 100644 --- a/resources/views/admin/users.blade.php +++ b/resources/views/admin/users.blade.php @@ -8,20 +8,19 @@ The user was deleted. @endif -
- -
-@if ($query) - -@endif - - Recently joined - {{$usersCount}} - -@if(request('recent')) - -@endif -New user +
+
+ +
+ @if ($query) + + @endif + + Recently joined + {{$usersCount}} + + New user +