Add email counts to admin dashboard

This commit is contained in:
Neil Lalonde 2013-03-17 15:08:38 -04:00
parent 6a99d12784
commit 50b04b2209
8 changed files with 36 additions and 3 deletions

View File

@ -79,6 +79,7 @@
{{ render 'admin_report_posts' posts }}
{{ render 'admin_report_likes' likes }}
{{ render 'admin_report_flags' flags }}
{{ render 'admin_report_emails' emails }}
{{/unless}}
</table>
</div>

View File

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

View File

@ -3,7 +3,7 @@ class Admin::DashboardController < Admin::AdminController
def index
render_json_dump({
reports: ['visits', 'signups', 'topics', 'posts', 'flags', 'users_by_trust_level', 'likes'].map { |type| Report.find(type) },
reports: ['visits', 'signups', 'topics', 'posts', 'flags', 'users_by_trust_level', 'likes', 'emails'].map { |type| Report.find(type) },
total_users: User.count
}.merge(
SiteSetting.version_checks? ? {version_check: DiscourseUpdates.check_version} : {}

View File

@ -7,4 +7,8 @@ class EmailLog < ActiveRecord::Base
# Update last_emailed_at if the user_id is present
User.update_all("last_emailed_at = CURRENT_TIMESTAMP", id: user_id) if user_id.present?
end
def self.count_per_day(since = 30.days.ago)
where('created_at > ?', since).group('date(created_at)').order('date(created_at)').count
end
end

View File

@ -98,6 +98,14 @@ class Report
end
end
def self.report_emails(report)
report.data = []
fetch report do
EmailLog.count_per_day(30.days.ago).each do |date, count|
report.data << {x: date, y: count}
end
end
end
private

View File

@ -279,6 +279,10 @@ en:
title: "Users per Trust Level"
xaxis: "Trust Level"
yaxis: "Number of Users"
emails:
title: "Emails Sent"
xaxis: "Day"
yaxis: "Number of Emails"
site_settings:
default_locale: "The default language of this Discourse instance (ISO 639-1 Code)"

View File

@ -0,0 +1,5 @@
Fabricator(:email_log,) do
user
to_address { sequence(:address) { |i| "blah#{i}@example.com" } }
email_type :invite
end

View File

@ -26,7 +26,7 @@
# end
# end
# [:signup, :topic, :post, :flag, :like].each do |arg|
# [:signup, :topic, :post, :flag, :like, :email].each do |arg|
# describe "#{arg} report" do
# pluralized = arg.to_s.pluralize
@ -40,7 +40,14 @@
# context "with #{pluralized}" do
# before do
# fabricator = (arg == :signup ? :user : arg)
# fabricator = case arg
# when :signup
# :user
# when :email
# :email_log
# else
# arg
# end
# Fabricate(fabricator, created_at: 25.hours.ago)
# Fabricate(fabricator, created_at: 1.hours.ago)
# Fabricate(fabricator, created_at: 1.hours.ago)