diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index d4a7d2424..ecc5903b5 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -2,21 +2,36 @@ namespace App\Http\Controllers; -use App\Media; -use App\Like; -use App\Profile; -use App\Report; -use App\Status; -use App\User; +use App\{ + FailedJob, + Hashtag, + Instance, + Media, + Like, + OauthClient, + Profile, + Report, + Status, + User +}; +use DB, Cache; use Carbon\Carbon; use Illuminate\Http\Request; use Jackiedo\DotenvEditor\DotenvEditor; -use App\Http\Controllers\Admin\AdminReportController; +use App\Http\Controllers\Admin\{ + AdminInstanceController, + AdminReportController, + AdminMediaController, + AdminSettingsController +}; use App\Util\Lexer\PrettyNumber; class AdminController extends Controller { - use AdminReportController; + use AdminReportController, + AdminMediaController, + AdminSettingsController, + AdminInstanceController; public function __construct() { @@ -26,7 +41,55 @@ class AdminController extends Controller public function home() { - return view('admin.home'); + $data = Cache::remember('admin:dashboard:home:data', 1, function() { + return [ + 'failedjobs' => [ + 'count' => PrettyNumber::convert(FailedJob::where('failed_at', '>=', \Carbon\Carbon::now()->subDay())->count()), + 'graph' => FailedJob::selectRaw('count(*) as count, day(failed_at) as d')->groupBy('d')->whereBetween('failed_at',[now()->subDays(24), now()])->orderBy('d')->pluck('count') + ], + 'reports' => [ + 'count' => PrettyNumber::convert(Report::whereNull('admin_seen')->count()), + 'graph' => Report::selectRaw('count(*) as count, day(created_at) as day')->whereBetween('created_at',[now()->subDays(14), now()])->groupBy('day')->orderBy('day')->pluck('count') + ], + 'statuses' => [ + 'count' => PrettyNumber::convert(Status::whereNull('in_reply_to_id')->whereNull('reblog_of_id')->count()), + 'graph' => Status::selectRaw('count(*) as count, day(created_at) as day')->whereBetween('created_at',[now()->subDays(14), now()])->groupBy('day')->orderBy('day')->pluck('count') + ], + 'replies' => [ + 'count' => PrettyNumber::convert(Status::whereNotNull('in_reply_to_id')->count()), + 'graph' => Status::whereNotNull('in_reply_to_id')->selectRaw('count(*) as count, day(created_at) as day')->whereBetween('created_at',[now()->subDays(14), now()])->groupBy('day')->orderBy('day')->pluck('count') + ], + 'shares' => [ + 'count' => PrettyNumber::convert(Status::whereNotNull('reblog_of_id')->count()), + 'graph' => Status::whereNotNull('reblog_of_id')->selectRaw('count(*) as count, day(created_at) as day')->whereBetween('created_at',[now()->subDays(14), now()])->groupBy('day')->orderBy('day')->pluck('count') + ], + 'likes' => [ + 'count' => PrettyNumber::convert(Like::count()), + 'graph' => Like::selectRaw('count(*) as count, day(created_at) as day')->whereBetween('created_at',[now()->subDays(14), now()])->groupBy('day')->orderBy('day')->pluck('count') + ], + 'profiles' => [ + 'count' => PrettyNumber::convert(Profile::count()), + 'graph' => Profile::selectRaw('count(*) as count, day(created_at) as day')->whereBetween('created_at',[now()->subDays(14), now()])->groupBy('day')->orderBy('day')->pluck('count') + ], + 'users' => [ + 'count' => PrettyNumber::convert(User::count()), + 'graph' => User::selectRaw('count(*) as count, day(created_at) as day')->whereBetween('created_at',[now()->subDays(14), now()])->groupBy('day')->orderBy('day')->pluck('count') + ], + 'instances' => [ + 'count' => PrettyNumber::convert(Instance::count()), + 'graph' => Instance::selectRaw('count(*) as count, day(created_at) as day')->whereBetween('created_at',[now()->subDays(28), now()])->groupBy('day')->orderBy('day')->pluck('count') + ], + 'media' => [ + 'count' => PrettyNumber::convert(Media::count()), + 'graph' => Media::selectRaw('count(*) as count, day(created_at) as day')->whereBetween('created_at',[now()->subDays(14), now()])->groupBy('day')->orderBy('day')->pluck('count') + ], + 'storage' => [ + 'count' => Media::sum('size'), + 'graph' => Media::selectRaw('sum(size) as count, day(created_at) as day')->whereBetween('created_at',[now()->subDays(14), now()])->groupBy('day')->orderBy('day')->pluck('count') + ] + ]; + }); + return view('admin.home', compact('data')); } public function users(Request $request) @@ -59,16 +122,23 @@ class AdminController extends Controller return view('admin.statuses.show', compact('status')); } - public function media(Request $request) - { - $media = Status::whereHas('media')->orderby('id', 'desc')->paginate(12); - - return view('admin.media.home', compact('media')); - } - public function reports(Request $request) { - $reports = Report::orderBy('created_at','desc')->paginate(12); + $filter = $request->input('filter'); + if(in_array($filter, ['open', 'closed'])) { + if($filter == 'open') { + $reports = Report::orderBy('created_at','desc') + ->whereNotNull('admin_seen') + ->paginate(10); + } else { + $reports = Report::orderBy('created_at','desc') + ->whereNull('admin_seen') + ->paginate(10); + } + } else { + $reports = Report::orderBy('created_at','desc') + ->paginate(10); + } return view('admin.reports.home', compact('reports')); } @@ -78,7 +148,6 @@ class AdminController extends Controller return view('admin.reports.show', compact('report')); } - protected function collectUserStats($request) { $total_duration = $request->query('total_duration') ?? '30'; @@ -106,4 +175,35 @@ class AdminController extends Controller return $stats; } + + public function profiles(Request $request) + { + $profiles = Profile::orderBy('id','desc')->paginate(10); + return view('admin.profiles.home', compact('profiles')); + } + + public function appsHome(Request $request) + { + $filter = $request->input('filter'); + if(in_array($filter, ['revoked'])) { + $apps = OauthClient::with('user') + ->whereNotNull('user_id') + ->whereRevoked(true) + ->orderByDesc('id') + ->paginate(10); + } else { + $apps = OauthClient::with('user') + ->whereNotNull('user_id') + ->orderByDesc('id') + ->paginate(10); + } + return view('admin.apps.home', compact('apps')); + } + + public function hashtagsHome(Request $request) + { + $hashtags = Hashtag::orderByDesc('id')->paginate(10); + return view('admin.hashtags.home', compact('hashtags')); + } + }