FEATURE: allow plugins to add custom admin reports

This commit is contained in:
Régis Hanol
2015-06-25 02:42:08 +02:00
parent 28a8b886c0
commit 18f887772d
5 changed files with 58 additions and 46 deletions

View File

@ -2,25 +2,34 @@ require_dependency 'mem_info'
class AdminDashboardData
REPORTS = [
GLOBAL_REPORTS ||= [
'visits',
'signups',
'topics',
'posts',
'time_to_first_response',
'topics_with_no_response',
'flags',
'users_by_trust_level',
'likes',
'flags',
'bookmarks',
'emails',
]
PAGE_VIEW_REPORTS ||= ['page_view_total_reqs'] + ApplicationRequest.req_types.keys.select { |r| r =~ /^page_view_/ }.map { |r| r + "_reqs" }
PRIVATE_MESSAGE_REPORTS ||= [
'user_to_user_private_messages',
'system_private_messages',
'moderator_warning_private_messages',
'notify_moderators_private_messages',
'notify_user_private_messages',
'page_view_total_reqs'
] + ApplicationRequest.req_types.keys.map{|r| r + "_reqs"}
'moderator_warning_private_messages',
]
HTTP_REPORTS ||= ApplicationRequest.req_types.keys.select { |r| r =~ /^http_/ }.map { |r| r + "_reqs" }.sort
USER_REPORTS ||= ['users_by_trust_level']
# TODO: MOBILE_REPORTS
def problems
[ rails_env_check,
@ -50,11 +59,13 @@ class AdminDashboardData
def self.fetch_stats
AdminDashboardData.new
end
def self.fetch_cached_stats
# The DashboardStats job is responsible for generating and caching this.
stats = $redis.get(stats_cache_key)
stats ? JSON.parse(stats) : nil
end
def self.stats_cache_key
'dash-stats'
end
@ -65,7 +76,11 @@ class AdminDashboardData
def as_json(_options = nil)
@json ||= {
reports: REPORTS.map { |type| Report.find(type).as_json },
global_reports: AdminDashboardData.reports(GLOBAL_REPORTS),
page_view_reports: AdminDashboardData.reports(PAGE_VIEW_REPORTS),
private_message_reports: AdminDashboardData.reports(PRIVATE_MESSAGE_REPORTS),
http_reports: AdminDashboardData.reports(HTTP_REPORTS),
user_reports: AdminDashboardData.reports(USER_REPORTS),
admins: User.admins.count,
moderators: User.moderators.count,
suspended: User.suspended.count,
@ -77,8 +92,12 @@ class AdminDashboardData
}
end
def self.reports(source)
source.map { |type| Report.find(type).as_json }
end
# Could be configurable, multisite need to support it.
def self.recalculate_interval
# Could be configurable, multisite need to support it.
30 # minutes
end