mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-04-29 15:35:23 -04:00
Add bookmarks and favorites to dashboard stats
This commit is contained in:
parent
75cfcbfa4f
commit
5cd6c85e8b
6 changed files with 47 additions and 12 deletions
app
assets/javascripts/admin/templates
models
config/locales
|
@ -129,6 +129,8 @@
|
||||||
{{ render 'admin_report_counts' posts }}
|
{{ render 'admin_report_counts' posts }}
|
||||||
{{ render 'admin_report_counts' likes }}
|
{{ render 'admin_report_counts' likes }}
|
||||||
{{ render 'admin_report_counts' flags }}
|
{{ render 'admin_report_counts' flags }}
|
||||||
|
{{ render 'admin_report_counts' bookmarks }}
|
||||||
|
{{ render 'admin_report_counts' favorites }}
|
||||||
{{ render 'admin_report_counts' emails }}
|
{{ render 'admin_report_counts' emails }}
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -10,6 +10,8 @@ class AdminDashboardData
|
||||||
'flags',
|
'flags',
|
||||||
'users_by_trust_level',
|
'users_by_trust_level',
|
||||||
'likes',
|
'likes',
|
||||||
|
'bookmarks',
|
||||||
|
'favorites',
|
||||||
'emails',
|
'emails',
|
||||||
'user_to_user_private_messages',
|
'user_to_user_private_messages',
|
||||||
'system_private_messages',
|
'system_private_messages',
|
||||||
|
|
|
@ -50,8 +50,8 @@ class PostAction < ActiveRecord::Base
|
||||||
user_actions
|
user_actions
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.count_likes_per_day(sinceDaysAgo = 30)
|
def self.count_per_day_for_type(sinceDaysAgo = 30, post_action_type)
|
||||||
where(post_action_type_id: PostActionType.types[:like]).where('created_at > ?', sinceDaysAgo.days.ago).group('date(created_at)').order('date(created_at)').count
|
where(post_action_type_id: post_action_type).where('created_at > ?', sinceDaysAgo.days.ago).group('date(created_at)').order('date(created_at)').count
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.clear_flags!(post, moderator_id, action_type_id = nil)
|
def self.clear_flags!(post, moderator_id, action_type_id = nil)
|
||||||
|
|
|
@ -74,6 +74,22 @@ class Report
|
||||||
report.prev30Days = subject_class.where('created_at > ? and created_at < ?', 60.days.ago, 30.days.ago).count
|
report.prev30Days = subject_class.where('created_at > ? and created_at < ?', 60.days.ago, 30.days.ago).count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.report_users_by_trust_level(report)
|
||||||
|
report.data = []
|
||||||
|
User.counts_by_trust_level.each do |level, count|
|
||||||
|
report.data << {x: level.to_i, y: count}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.report_favorites(report)
|
||||||
|
basic_report_about report, Topic, :starred_counts_per_day
|
||||||
|
query = TopicUser.where(starred: true)
|
||||||
|
report.total = query.count
|
||||||
|
report.prev30Days = query.where('starred_at > ? and starred_at < ?', 60.days.ago, 30.days.ago).count
|
||||||
|
end
|
||||||
|
|
||||||
|
# Post action counts:
|
||||||
|
|
||||||
def self.report_flags(report)
|
def self.report_flags(report)
|
||||||
report.data = []
|
report.data = []
|
||||||
(0..30).to_a.reverse.each do |i|
|
(0..30).to_a.reverse.each do |i|
|
||||||
|
@ -89,23 +105,26 @@ class Report
|
||||||
report.prev30Days = flagsQuery.where('created_at > ? and created_at < ?', 60.days.ago, 30.days.ago).count
|
report.prev30Days = flagsQuery.where('created_at > ? and created_at < ?', 60.days.ago, 30.days.ago).count
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.report_users_by_trust_level(report)
|
def self.report_likes(report)
|
||||||
report.data = []
|
post_action_report report, PostActionType.types[:like]
|
||||||
User.counts_by_trust_level.each do |level, count|
|
|
||||||
report.data << {x: level.to_i, y: count}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.report_likes(report)
|
def self.report_bookmarks(report)
|
||||||
|
post_action_report report, PostActionType.types[:bookmark]
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.post_action_report(report, post_action_type)
|
||||||
report.data = []
|
report.data = []
|
||||||
PostAction.count_likes_per_day(30).each do |date, count|
|
PostAction.count_per_day_for_type(30, post_action_type).each do |date, count|
|
||||||
report.data << {x: date, y: count}
|
report.data << {x: date, y: count}
|
||||||
end
|
end
|
||||||
likesQuery = PostAction.where(post_action_type_id: PostActionType.types[:like])
|
query = PostAction.where(post_action_type_id: post_action_type)
|
||||||
report.total = likesQuery.count
|
report.total = query.count
|
||||||
report.prev30Days = likesQuery.where('created_at > ? and created_at < ?', 60.days.ago, 30.days.ago).count
|
report.prev30Days = query.where('created_at > ? and created_at < ?', 60.days.ago, 30.days.ago).count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Private messages counts:
|
||||||
|
|
||||||
def self.private_messages_report(report, topic_subtype)
|
def self.private_messages_report(report, topic_subtype)
|
||||||
basic_report_about report, Post, :private_messages_count_per_day, topic_subtype
|
basic_report_about report, Post, :private_messages_count_per_day, topic_subtype
|
||||||
report.total = Post.private_posts.with_topic_subtype(topic_subtype).count
|
report.total = Post.private_posts.with_topic_subtype(topic_subtype).count
|
||||||
|
|
|
@ -583,6 +583,10 @@ class Topic < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.starred_counts_per_day(sinceDaysAgo=30)
|
||||||
|
TopicUser.where('starred_at > ?', sinceDaysAgo.days.ago).group('date(starred_at)').order('date(starred_at)').count
|
||||||
|
end
|
||||||
|
|
||||||
# Enable/disable the mute on the topic
|
# Enable/disable the mute on the topic
|
||||||
def toggle_mute(user, muted)
|
def toggle_mute(user, muted)
|
||||||
TopicUser.change(user, self.id, notification_level: muted?(user) ? TopicUser.notification_levels[:regular] : TopicUser.notification_levels[:muted] )
|
TopicUser.change(user, self.id, notification_level: muted?(user) ? TopicUser.notification_levels[:regular] : TopicUser.notification_levels[:muted] )
|
||||||
|
|
|
@ -298,6 +298,14 @@ en:
|
||||||
title: "Flags"
|
title: "Flags"
|
||||||
xaxis: "Day"
|
xaxis: "Day"
|
||||||
yaxis: "Number of flags"
|
yaxis: "Number of flags"
|
||||||
|
bookmarks:
|
||||||
|
title: "Bookmarks"
|
||||||
|
xaxis: "Day"
|
||||||
|
yaxis: "Number of new bookmarks"
|
||||||
|
favorites:
|
||||||
|
title: "Favorites"
|
||||||
|
xaxis: "Day"
|
||||||
|
yaxis: "Number of new favorites"
|
||||||
users_by_trust_level:
|
users_by_trust_level:
|
||||||
title: "Users per Trust Level"
|
title: "Users per Trust Level"
|
||||||
xaxis: "Trust Level"
|
xaxis: "Trust Level"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue