Update admin dashboard

This commit is contained in:
Daniel Supernault 2019-07-17 23:00:34 -06:00
parent 8e7f4000b6
commit 6751aa4ea6
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 7 additions and 131 deletions

View file

@ -105,10 +105,9 @@ class AdminController extends Controller
{
$col = $request->query('col') ?? 'id';
$dir = $request->query('dir') ?? 'desc';
$stats = $this->collectUserStats($request);
$users = User::withCount('statuses')->orderBy($col, $dir)->simplePaginate(10);
$users = User::select('id', 'username', 'status')->withCount('statuses')->orderBy($col, $dir)->simplePaginate(10);
return view('admin.users.home', compact('users', 'stats'));
return view('admin.users.home', compact('users'));
}
public function editUser(Request $request, $id)
@ -158,34 +157,6 @@ class AdminController extends Controller
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' => 0//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' => 0//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'] = [
'likes' => floor(Like::average('profile_id')),
'posts' => floor(Status::avg('profile_id'))
];
return $stats;
}
public function profiles(Request $request)
{
$this->validate($request, [