Add flag counts to admin dashboard

This commit is contained in:
Neil Lalonde 2013-03-12 14:19:01 -04:00
parent 9422adfe66
commit 40c27ff3cf
7 changed files with 32 additions and 5 deletions

View File

@ -31,7 +31,7 @@ Discourse.AdminDashboardRoute = Discourse.Route.extend({
if( !c.get('reportsCheckedAt') || Date.create('1 hour ago') > c.get('reportsCheckedAt') ) {
// TODO: use one request to get all reports, or maybe one request for all dashboard data including version check.
c.set('reportsCheckedAt', new Date());
['visits', 'signups', 'topics', 'posts', 'total_users'].each(function(reportType){
['visits', 'signups', 'topics', 'posts', 'total_users', 'flags'].each(function(reportType){
c.set(reportType, Discourse.Report.find(reportType));
});
}

View File

@ -57,6 +57,7 @@
{{ render 'admin_report_signups' signups }}
{{ render 'admin_report_topics' topics }}
{{ render 'admin_report_posts' posts }}
{{ render 'admin_report_flags' flags }}
</table>
</div>

View File

@ -0,0 +1,4 @@
Discourse.AdminReportFlagsView = Discourse.View.extend({
templateName: 'admin/templates/reports/summed_counts_report',
tagName: 'tbody'
});

View File

@ -72,7 +72,7 @@ class Report
def self.report_total_users(report)
report.data = []
fetch report do
(0..30).each do |i|
(0..30).to_a.reverse.each do |i|
if (count = User.where('created_at < ?', i.days.ago).count) > 0
report.data << {x: i.days.ago.to_date.to_s, y: count}
end
@ -80,6 +80,17 @@ class Report
end
end
def self.report_flags(report)
report.data = []
fetch report do
(0..30).to_a.reverse.each do |i|
if (count = PostAction.where('date(created_at) = ?', i.days.ago.to_date).where(post_action_type_id: PostActionType.flag_types.values).count) > 0
report.data << {x: i.days.ago.to_date.to_s, y: count}
end
end
end
end
private

View File

@ -261,6 +261,12 @@ en:
yaxis: "Number of new posts"
total_users:
title: "Total Users"
xaxis: "Day"
yaxis: "Total number of users"
flags:
title: "Flags"
xaxis: "Day"
yaxis: "Number of flags"
site_settings:
default_locale: "The default language of this Discourse instance (ISO 639-1 Code)"

View File

@ -0,0 +1,5 @@
Fabricator(:flag, from: :post_action) do
user
post
post_action_type_id PostActionType.types[:spam]
end

View File

@ -30,7 +30,7 @@ describe Report do
end
[:signup, :topic, :post].each do |arg|
[:signup, :topic, :post, :flag].each do |arg|
describe "#{arg} report" do
pluralized = arg.to_s.pluralize
@ -75,8 +75,8 @@ describe Report do
end
it 'returns correct data' do
report.data[0][:y].should == 3
report.data[1][:y].should == 1
report.data[0][:y].should == 1
report.data[1][:y].should == 3
end
end
end