diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index d2f0b0679..a94793fc2 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -3,9 +3,11 @@ namespace App\Http\Controllers; use App\Media; +use App\Profile; use App\Report; use App\Status; use App\User; +use Carbon\Carbon; use Illuminate\Http\Request; use App\Http\Controllers\Admin\{ AdminReportController @@ -27,9 +29,17 @@ class AdminController extends Controller public function users(Request $request) { + $stats = $this->collectUserStats($request); $users = User::orderBy('id', 'desc')->paginate(10); + return view('admin.users.home', compact('users', 'stats')); + } - return view('admin.users.home', compact('users')); + + public function editUser(Request $request, $id) + { + $user = User::find($id); + $profile = $user->profile; + return view('admin.users.edit', compact('user', 'profile')); } public function statuses(Request $request) @@ -64,4 +74,33 @@ class AdminController extends Controller $report = Report::findOrFail($id); return view('admin.reports.show', compact('report')); } + + + protected function collectUserStats($request) + { + $total_duration = $request->query('total_duration') ?? '30'; + $new_duration = $request->query('new_duration') ?? '7'; + $stats = []; + $stats['total'] = [ + 'count' => User::where('created_at', '>', Carbon::now()->subDays($total_duration))->count(), + 'points' => User::selectRaw('day(created_at) day, count(*) as count')->where('created_at','>', Carbon::now()->subDays($total_duration))->groupBy('day')->pluck('count') + ]; + $stats['new'] = [ + 'count' => User::where('created_at', '>', Carbon::now()->subDays($new_duration))->count(), + 'points' => User::selectRaw('day(created_at) day, count(*) as count')->where('created_at','>', Carbon::now()->subDays($new_duration))->groupBy('day')->pluck('count') + ]; + $stats['active'] = [ + 'count' => Status::groupBy('profile_id')->count() + ]; + $stats['profile'] = [ + 'local' => Profile::whereNull('remote_url')->count(), + 'remote' => Profile::whereNotNull('remote_url')->count() + ]; + $stats['avg'] = [ + 'age' => Carbon::parse(substr(User::avg('created_at'),0,8))->diffForHumans(null,true,true), + 'posts' => floor(Status::avg('profile_id')) + ]; + return $stats; + + } } diff --git a/resources/views/admin/reports/home.blade.php b/resources/views/admin/reports/home.blade.php index 3a48393aa..644c32ae9 100644 --- a/resources/views/admin/reports/home.blade.php +++ b/resources/views/admin/reports/home.blade.php @@ -2,7 +2,7 @@ @section('section')
Open:
diff --git a/resources/views/admin/users/edit.blade.php b/resources/views/admin/users/edit.blade.php
new file mode 100644
index 000000000..29148e9db
--- /dev/null
+++ b/resources/views/admin/users/edit.blade.php
@@ -0,0 +1,101 @@
+@extends('admin.partial.template')
+
+@section('section')
+ {{$profile->statusCount()}} Posts {{$profile->likes()->count()}} Likes {{$profile->reports()->count()}} Reports {{PrettyNumber::size($profile->media()->sum('size'))}} Storage Used
+ {{$profile->username}}
+
+ {{$profile->emailUrl()}}
+
+ Member Since: {{$profile->created_at->format('M Y')}}
+ {{$stats['total']['count']}} {{$stats['new']['count']}} {{$stats['profile']['local']}} {{$stats['profile']['remote']}} {{$stats['avg']['age']}} {{$stats['avg']['posts']}}Edit User
+ Back
+
+
+
+ Users
+
-
-
-
@foreach($users as $user)
- Username
- Statuses
- Storage
- Role
- Created
+
+
+
-
+ ID
+
+
+ Avatar
+
+
+ Username
+
+
+ Status Count
+
+
+ Storage Used
+
+
+ Actions
+
+
@endforeach
@@ -39,14 +165,58 @@
@endsection
+@push('styles')
+
+@endpush
@push('scripts')
+
@endpush
diff --git a/routes/web.php b/routes/web.php
index 0ea061013..ae5365f20 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -13,6 +13,7 @@ Route::domain(config('pixelfed.domain.admin'))->prefix('i/admin')->group(functio
Route::get('statuses/show/{id}', 'AdminController@showStatus');
Route::redirect('users', '/users/list');
Route::get('users/list', 'AdminController@users')->name('admin.users');
+ Route::get('users/edit/{id}', 'AdminController@editUser');
Route::redirect('media', '/media/list');
Route::get('media/list', 'AdminController@media')->name('admin.media');
});
-
- {{$user->username}}
-
+ {{$user->id}}
- {{$user->profile->statuses->count()}}
-
- {!!$user->is_admin ? 'admin' : 'member'!!}
- {{$user->created_at->diffForHumans(null, true, true)}}
+
+
+
+
+
+ {{$user->username}}
+ @if($user->is_admin)
+
+ @endif
+
+
+
+ {{$user->profile->statusCount()}}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+