Add likes to admin dashboard

This commit is contained in:
Neil Lalonde 2013-03-17 13:53:00 -04:00
parent 2665617271
commit 6a99d12784
8 changed files with 30 additions and 3 deletions

View File

@ -77,6 +77,7 @@
{{ render 'admin_report_signups' signups }}
{{ render 'admin_report_topics' topics }}
{{ render 'admin_report_posts' posts }}
{{ render 'admin_report_likes' likes }}
{{ render 'admin_report_flags' flags }}
{{/unless}}
</table>

View File

@ -0,0 +1,4 @@
Discourse.AdminReportLikesView = 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'].map { |type| Report.find(type) },
reports: ['visits', 'signups', 'topics', 'posts', 'flags', 'users_by_trust_level', 'likes'].map { |type| Report.find(type) },
total_users: User.count
}.merge(
SiteSetting.version_checks? ? {version_check: DiscourseUpdates.check_version} : {}

View File

@ -50,6 +50,10 @@ class PostAction < ActiveRecord::Base
user_actions
end
def self.count_likes_per_day(since = 30.days.ago)
where(post_action_type_id: PostActionType.types[:like]).where('created_at > ?', since).group('date(created_at)').order('date(created_at)').count
end
def self.clear_flags!(post, moderator_id, action_type_id = nil)
# -1 is the automatic system cleary
actions = if action_type_id

View File

@ -89,6 +89,15 @@ class Report
end
end
def self.report_likes(report)
report.data = []
fetch report do
PostAction.count_likes_per_day(30.days.ago).each do |date, count|
report.data << {x: date, y: count}
end
end
end
private

View File

@ -263,12 +263,16 @@ en:
title: "New Posts"
xaxis: "Day"
yaxis: "Number of new posts"
likes:
title: "New Likes"
xaxis: "Day"
yaxis: "Number of new likes"
total_users:
title: "Total Users"
xaxis: "Day"
yaxis: "Total number of users"
flags:
title: "Flags"
title: "New Flags"
xaxis: "Day"
yaxis: "Number of flags"
users_by_trust_level:

View File

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

View File

@ -26,7 +26,7 @@
# end
# end
# [:signup, :topic, :post, :flag].each do |arg|
# [:signup, :topic, :post, :flag, :like].each do |arg|
# describe "#{arg} report" do
# pluralized = arg.to_s.pluralize