parent
d270680ffb
commit
7b69860aa9
@ -0,0 +1,66 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
if ($('body.admins-dashboards-index-page').length > 0) {
|
||||
// 月新增用户
|
||||
var monthChart = echarts.init(document.getElementById('month-active-user'));
|
||||
monthChart.setOption({
|
||||
tooltip: {
|
||||
show: "true",
|
||||
trigger: 'item',
|
||||
formatter: '{c0}',
|
||||
backgroundColor: 'rgba(0,0,0,0.7)', // 背景
|
||||
padding: [8, 10], //内边距
|
||||
extraCssText: 'box-shadow: 0 0 3px rgba(255, 255, 255, 0.4);', //添加阴影
|
||||
axisPointer: { // 坐标轴指示器,坐标轴触发有效
|
||||
type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
|
||||
}
|
||||
},
|
||||
series : [
|
||||
{
|
||||
name: '访问来源',
|
||||
type: 'pie',
|
||||
radius: '55%',
|
||||
data: []
|
||||
}
|
||||
]
|
||||
});
|
||||
monthChart.showLoading();
|
||||
$.get('/admins/dashboards/month_active_user.json').done(function(data){
|
||||
monthChart.setOption({
|
||||
series: [
|
||||
{ data: data.data }
|
||||
]
|
||||
});
|
||||
|
||||
monthChart.hideLoading();
|
||||
});
|
||||
|
||||
|
||||
// 近七天评测次数
|
||||
var evaluateChart = echarts.init(document.getElementById('evaluate-pie'));
|
||||
evaluateChart.setOption({
|
||||
tooltip: {
|
||||
show: "true",
|
||||
trigger: 'item',
|
||||
formatter: '{c0}',
|
||||
backgroundColor: 'rgba(0,0,0,0.7)', // 背景
|
||||
padding: [8, 10], //内边距
|
||||
extraCssText: 'box-shadow: 0 0 3px rgba(255, 255, 255, 0.4);', //添加阴影
|
||||
axisPointer: { // 坐标轴指示器,坐标轴触发有效
|
||||
type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
|
||||
}
|
||||
},
|
||||
xAxis: { type: 'category', data: [] },
|
||||
yAxis: { type: 'value' },
|
||||
series: [{ data: [], type: 'line' }]
|
||||
});
|
||||
evaluateChart.showLoading();
|
||||
$.get('/admins/dashboards/evaluate.json').done(function(data){
|
||||
evaluateChart.setOption({
|
||||
xAxis: { data: data.names },
|
||||
series: [{ data: data.data }]
|
||||
});
|
||||
|
||||
evaluateChart.hideLoading();
|
||||
});
|
||||
}
|
||||
});
|
@ -0,0 +1,7 @@
|
||||
.admins-dashboards-index-page {
|
||||
.pie-statistic {
|
||||
.pie {
|
||||
height: 300px;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,50 @@
|
||||
class Admins::DashboardsController < Admins::BaseController
|
||||
def index
|
||||
@active_user_count = User.where(last_login_on: today).count
|
||||
@weekly_active_user_count = User.where(last_login_on: current_week).count
|
||||
@month_active_user_count = User.where(last_login_on: current_month).count
|
||||
|
||||
@new_user_count = User.where(created_on: current_month).count
|
||||
end
|
||||
|
||||
def month_active_user
|
||||
count = UserExtension.where(created_at: current_month).group(:identity).count
|
||||
|
||||
data = [
|
||||
{ value: count['teacher'].to_i, name: '老师' },
|
||||
{ value: count['student'].to_i, name: '学生' },
|
||||
{ value: count['professional'].to_i, name: '专业人士' }
|
||||
]
|
||||
|
||||
render_ok(data: data)
|
||||
end
|
||||
|
||||
def evaluate
|
||||
names = []
|
||||
data = []
|
||||
|
||||
7.times do |i|
|
||||
date = i.days.ago
|
||||
names.unshift(date.strftime('%Y-%m-%d'))
|
||||
|
||||
count = Output.where(created_at: date.beginning_of_day..date.end_of_day).count
|
||||
data.unshift(count)
|
||||
end
|
||||
|
||||
render_ok(names: names, data: data)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def today
|
||||
Time.now.beginning_of_day..Time.now.end_of_day
|
||||
end
|
||||
|
||||
def current_week
|
||||
7.days.ago.beginning_of_day..Time.now.end_of_day
|
||||
end
|
||||
|
||||
def current_month
|
||||
30.days.ago.beginning_of_day..Time.now.end_of_day
|
||||
end
|
||||
end
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Loading…
Reference in new issue