Merge pull request #2518 from pixelfed/staging

Update admin dashboard
This commit is contained in:
daniel 2020-12-18 00:54:02 -07:00 committed by GitHub
commit 2c499ac831
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 149 deletions

View File

@ -27,40 +27,10 @@ class AdminStatsService
protected static function recentData()
{
$day = config('database.default') == 'pgsql' ? 'DATE_PART(\'day\',' : 'day(';
return Cache::remember('admin:dashboard:home:data:15min', now()->addMinutes(15), function() use ($day) {
return Cache::remember('admin:dashboard:home:data:v0:15min', now()->addMinutes(15), function() use ($day) {
return [
'contact' => [
'count' => PrettyNumber::convert(Contact::whereNull('read_at')->count()),
'graph' => Contact::selectRaw('count(*) as count, '.$day.'created_at) as d')->groupBy('d')->whereNull('read_at')->whereBetween('created_at',[now()->subDays(14), now()])->orderBy('d')->pluck('count')
],
'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(14), now()])->orderBy('d')->pluck('count')
],
'reports' => [
'count' => PrettyNumber::convert(Report::whereNull('admin_seen')->count()),
'graph' => Report::selectRaw('count(*) as count, '.$day.'created_at) as d')->whereBetween('created_at',[now()->subDays(14), now()])->groupBy('d')->orderBy('d')->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')
],
'contact' => PrettyNumber::convert(Contact::whereNull('read_at')->count()),
'reports' => PrettyNumber::convert(Report::whereNull('admin_seen')->count()),
];
});
}
@ -68,24 +38,15 @@ class AdminStatsService
protected static function additionalData()
{
$day = config('database.default') == 'pgsql' ? 'DATE_PART(\'day\',' : 'day(';
return Cache::remember('admin:dashboard:home:data:24hr', now()->addHours(24), function() use ($day) {
return Cache::remember('admin:dashboard:home:data:v0:24hr', now()->addHours(24), function() use ($day) {
return [
'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')
]
'failedjobs' => PrettyNumber::convert(FailedJob::where('failed_at', '>=', \Carbon\Carbon::now()->subDay())->count()),
'statuses' => PrettyNumber::convert(Status::whereNull('in_reply_to_id')->whereNull('reblog_of_id')->count()),
'profiles' => PrettyNumber::convert(Profile::count()),
'users' => PrettyNumber::convert(User::count()),
'instances' => PrettyNumber::convert(Instance::count()),
'media' => PrettyNumber::convert(Media::count()),
'storage' => Media::sum('size'),
];
});
}

View File

@ -12,9 +12,8 @@
<div class="card shadow-none border" style="min-height:125px">
<div class="card-body">
<p class="small text-uppercase font-weight-bold text-muted">New Messages</p>
<p class="h2 mb-0">{{$data['contact']['count']}}</p>
<p class="h2 mb-0">{{$data['contact']}}</p>
</div>
<canvas width="100" height="10" class="sparkline mb-1" data-chart_values="{{$data['contact']['graph']}}"></canvas>
</div>
</div>
@ -22,9 +21,8 @@
<div class="card shadow-none border" style="min-height:125px">
<div class="card-body">
<p class="small text-uppercase font-weight-bold text-muted">Failed Jobs (24h)</p>
<p class="h2 mb-0">{{$data['failedjobs']['count']}}</p>
<p class="h2 mb-0">{{$data['failedjobs']}}</p>
</div>
<canvas width="100" height="10" class="sparkline mb-1" data-chart_values="{{$data['failedjobs']['graph']}}"></canvas>
</div>
</div>
@ -32,9 +30,8 @@
<div class="card shadow-none border" style="min-height:125px">
<div class="card-body">
<p class="small text-uppercase font-weight-bold text-muted">Reports</p>
<p class="h2 mb-0" title="{{$data['reports']['count']}}" data-toggle="tooltip">{{$data['reports']['count']}}</p>
<p class="h2 mb-0" title="{{$data['reports']}}" data-toggle="tooltip">{{$data['reports']}}</p>
</div>
<canvas width="100" height="10" class="sparkline mb-1" data-chart_values="{{$data['reports']['graph']}}"></canvas>
</div>
</div>
</div>
@ -44,40 +41,8 @@
<div class="card shadow-none border" style="min-height:125px">
<div class="card-body">
<p class="small text-uppercase font-weight-bold text-muted">Statuses</p>
<p class="h2 mb-0" title="{{$data['statuses']['count']}}" data-toggle="tooltip">{{$data['statuses']['count']}}</p>
<p class="h2 mb-0" title="{{$data['statuses']}}" data-toggle="tooltip">{{$data['statuses']}}</p>
</div>
<canvas width="100" height="10" class="sparkline mb-1" data-chart_values="{{$data['statuses']['graph']}}"></canvas>
</div>
</div>
<div class="col-md-4">
<div class="card shadow-none border" style="min-height:125px">
<div class="card-body">
<p class="small text-uppercase font-weight-bold text-muted">Replies</p>
<p class="h2 mb-0" title="{{$data['replies']['count']}}" data-toggle="tooltip">{{$data['replies']['count']}}</p>
</div>
<canvas width="100" height="10" class="sparkline mb-1" data-chart_values="{{$data['replies']['graph']}}""></canvas>
</div>
</div>
<div class="col-md-4">
<div class="card shadow-none border" style="min-height:125px">
<div class="card-body">
<p class="small text-uppercase font-weight-bold text-muted">Shares (Reblogs)</p>
<p class="h2 mb-0">{{$data['shares']['count']}}</p>
</div>
<canvas width="100" height="10" class="sparkline mb-1" data-chart_values="{{$data['shares']['graph']}}"></canvas>
</div>
</div>
</div>
<div class="row mt-4">
<div class="col-md-4">
<div class="card shadow-none border" style="min-height:125px">
<div class="card-body">
<p class="small text-uppercase font-weight-bold text-muted">Likes</p>
<p class="h2 mb-0">{{$data['likes']['count']}}</p>
</div>
<canvas width="100" height="10" class="sparkline mb-1" data-chart_values="{{$data['likes']['graph']}}"></canvas>
</div>
</div>
@ -85,9 +50,8 @@
<div class="card shadow-none border" style="min-height:125px">
<div class="card-body">
<p class="small text-uppercase font-weight-bold text-muted">Profiles</p>
<p class="h2 mb-0">{{$data['profiles']['count']}}</p>
<p class="h2 mb-0">{{$data['profiles']}}</p>
</div>
<canvas width="100" height="10" class="sparkline mb-1" data-chart_values="{{$data['profiles']['graph']}}"></canvas>
</div>
</div>
@ -95,9 +59,8 @@
<div class="card shadow-none border" style="min-height:125px">
<div class="card-body">
<p class="small text-uppercase font-weight-bold text-muted">Users</p>
<p class="h2 mb-0">{{$data['users']['count']}}</p>
<p class="h2 mb-0">{{$data['users']}}</p>
</div>
<canvas width="100" height="10" class="sparkline mb-1" data-chart_values="{{$data['users']['graph']}}"></canvas>
</div>
</div>
</div>
@ -107,9 +70,8 @@
<div class="card shadow-none border" style="min-height:125px">
<div class="card-body">
<p class="small text-uppercase font-weight-bold text-muted">Remote Instances</p>
<p class="h2 mb-0">{{$data['instances']['count']}}</p>
<p class="h2 mb-0">{{$data['instances']}}</p>
</div>
<canvas width="100" height="10" class="sparkline mb-1" data-chart_values="{{$data['instances']['graph']}}"></canvas>
</div>
</div>
@ -117,25 +79,22 @@
<div class="card shadow-none border" style="min-height:125px">
<div class="card-body">
<p class="small text-uppercase font-weight-bold text-muted">Photos Uploaded</p>
<p class="h2 mb-0">{{$data['media']['count']}}</p>
<p class="h2 mb-0">{{$data['media']}}</p>
</div>
<canvas width="100" height="10" class="sparkline mb-1" data-chart_values="{{$data['media']['graph']}}"></canvas>
</div>
</div>
<div class="col-md-4">
<div class="card shadow-none border" style="min-height:125px">
<div class="card-body">
<p class="small text-uppercase font-weight-bold text-muted">Storage Used</p>
<p class="human-size mb-0" data-bytes="{{$data['storage']['count']}}">{{$data['storage']['count']}} bytes</p>
<p class="human-size mb-0" data-bytes="{{$data['storage']}}">{{$data['storage']}} bytes</p>
</div>
<canvas width="100" height="10" class="sparkline mb-1" data-chart_values="{{$data['storage']['graph']}}"></canvas>
</div>
</div>
</div>
@endsection
@push('scripts')
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.min.js" integrity="sha256-oSgtFCCmHWRPQ/JmR4OoZ3Xke1Pw4v50uh6pLcu+fIc=" crossorigin="anonymous"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.human-size').each(function(d,a) {
@ -144,55 +103,6 @@
el.addClass('h2');
el.text(filesize(size, {round: 0}));
});
$('.sparkline').each(function() {
var ctx = $(this).get(0).getContext("2d");
var myNewChart = new Chart(ctx);
var chartData = JSON.parse($(this).attr('data-chart_values'));
var data = {};
var labels = [];
var datasets = {};
for (var i = 0; i < chartData.length; i++) {
labels.push('');
}
datasets['data'] = chartData;
datasets['backgroundColor'] = '#ffffff';
data['labels'] = labels;
data['datasets'] = [datasets];
new Chart(ctx, {
type: 'line',
data: data,
options: {
responsive: true,
legend: {
display: false
},
elements: {
line: {
borderColor: '#08d',
borderWidth: 1
},
point: {
radius: 0
}
},
tooltips: {
enabled: false
},
scales: {
yAxes: [
{
display: false
}
],
xAxes: [
{
display: false
}
]
}
}
});
})
});
</script>
@endpush