Dashboard: split out private messages from topic and post counts; re-enable report_spec because I think I fixed it...
This commit is contained in:
parent
738789f336
commit
bb18b6cb9b
|
@ -113,6 +113,7 @@
|
|||
{{ render 'admin_report_counts' likes }}
|
||||
{{ render 'admin_report_counts' flags }}
|
||||
{{ render 'admin_report_counts' emails }}
|
||||
{{ render 'admin_report_counts' private_messages }}
|
||||
{{/unless}}
|
||||
</table>
|
||||
</div>
|
||||
|
|
|
@ -2,7 +2,7 @@ require_dependency 'mem_info'
|
|||
|
||||
class AdminDashboardData
|
||||
|
||||
REPORTS = ['visits', 'signups', 'topics', 'posts', 'flags', 'users_by_trust_level', 'likes', 'emails']
|
||||
REPORTS = ['visits', 'signups', 'topics', 'posts', 'flags', 'users_by_trust_level', 'likes', 'emails', 'private_messages']
|
||||
|
||||
def self.fetch_all
|
||||
AdminDashboardData.new
|
||||
|
|
|
@ -8,7 +8,7 @@ class EmailLog < ActiveRecord::Base
|
|||
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
|
||||
def self.count_per_day(sinceDaysAgo = 30)
|
||||
where('created_at > ?', sinceDaysAgo.days.ago).group('date(created_at)').order('date(created_at)').count
|
||||
end
|
||||
end
|
||||
|
|
|
@ -390,7 +390,11 @@ class Post < ActiveRecord::Base
|
|||
Jobs.enqueue(:process_post, args)
|
||||
end
|
||||
|
||||
def self.count_per_day(since=30.days.ago)
|
||||
where('created_at > ?', since).group('date(created_at)').order('date(created_at)').count
|
||||
def self.public_posts_count_per_day(sinceDaysAgo=30)
|
||||
joins(:topic).where('topics.archetype <> ?', [Archetype.private_message]).where('posts.created_at > ?', sinceDaysAgo.days.ago).group('date(posts.created_at)').order('date(posts.created_at)').count
|
||||
end
|
||||
|
||||
def self.private_messages_count_per_day(sinceDaysAgo=30)
|
||||
joins(:topic).where('topics.archetype = ?', Archetype.private_message).where('posts.created_at > ?', sinceDaysAgo.days.ago).group('date(posts.created_at)').order('date(posts.created_at)').count
|
||||
end
|
||||
end
|
||||
|
|
|
@ -50,8 +50,8 @@ 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
|
||||
def self.count_likes_per_day(sinceDaysAgo = 30)
|
||||
where(post_action_type_id: PostActionType.types[:like]).where('created_at > ?', sinceDaysAgo.days.ago).group('date(created_at)').order('date(created_at)').count
|
||||
end
|
||||
|
||||
def self.clear_flags!(post, moderator_id, action_type_id = nil)
|
||||
|
|
|
@ -40,11 +40,15 @@ class Report
|
|||
end
|
||||
|
||||
def self.report_topics(report)
|
||||
report_about report, Topic
|
||||
report_about report, Topic, :listable_count_per_day
|
||||
end
|
||||
|
||||
def self.report_posts(report)
|
||||
report_about report, Post
|
||||
report_about report, Post, :public_posts_count_per_day
|
||||
end
|
||||
|
||||
def self.report_private_messages(report)
|
||||
report_about report, Post, :private_messages_count_per_day
|
||||
end
|
||||
|
||||
def self.report_emails(report)
|
||||
|
@ -58,7 +62,7 @@ class Report
|
|||
|
||||
def self.basic_report_about(report, subject_class, report_method)
|
||||
report.data = []
|
||||
subject_class.send(report_method, 30.days.ago).each do |date, count|
|
||||
subject_class.send(report_method, 30).each do |date, count|
|
||||
report.data << {x: date, y: count}
|
||||
end
|
||||
end
|
||||
|
@ -89,7 +93,7 @@ class Report
|
|||
|
||||
def self.report_likes(report)
|
||||
report.data = []
|
||||
PostAction.count_likes_per_day(30.days.ago).each do |date, count|
|
||||
PostAction.count_likes_per_day(30).each do |date, count|
|
||||
report.data << {x: date, y: count}
|
||||
end
|
||||
likesQuery = PostAction.where(post_action_type_id: PostActionType.types[:like])
|
||||
|
|
|
@ -192,8 +192,8 @@ class Topic < ActiveRecord::Base
|
|||
where("created_at > ?", time_ago)
|
||||
end
|
||||
|
||||
def self.count_per_day(since=30.days.ago)
|
||||
where('created_at > ?', since).group('date(created_at)').order('date(created_at)').count
|
||||
def self.listable_count_per_day(sinceDaysAgo=30)
|
||||
listable_topics.where('created_at > ?', sinceDaysAgo.days.ago).group('date(created_at)').order('date(created_at)').count
|
||||
end
|
||||
|
||||
def private_message?
|
||||
|
|
|
@ -479,8 +479,8 @@ class User < ActiveRecord::Base
|
|||
Summarize.new(bio_cooked).summary
|
||||
end
|
||||
|
||||
def self.count_by_signup_date(since=30.days.ago)
|
||||
where('created_at > ?', since).group('date(created_at)').order('date(created_at)').count
|
||||
def self.count_by_signup_date(sinceDaysAgo=30)
|
||||
where('created_at > ?', sinceDaysAgo.days.ago).group('date(created_at)').order('date(created_at)').count
|
||||
end
|
||||
|
||||
def self.counts_by_trust_level
|
||||
|
|
|
@ -2,7 +2,7 @@ class UserVisit < ActiveRecord::Base
|
|||
attr_accessible :visited_at, :user_id
|
||||
|
||||
# A list of visits in the last month by day
|
||||
def self.by_day(since=30.days.ago)
|
||||
where("visited_at >= ?", since).group(:visited_at).order(:visited_at).count
|
||||
def self.by_day(sinceDaysAgo=30)
|
||||
where("visited_at >= ?", sinceDaysAgo.days.ago).group(:visited_at).order(:visited_at).count
|
||||
end
|
||||
end
|
||||
|
|
|
@ -294,6 +294,10 @@ en:
|
|||
title: "Emails Sent"
|
||||
xaxis: "Day"
|
||||
yaxis: "Number of Emails"
|
||||
private_messages:
|
||||
title: "Private Messages"
|
||||
xaxis: "Day"
|
||||
yaxis: "Number of private messages"
|
||||
|
||||
dashboard:
|
||||
rails_env_warning: "Your server is running in %{env} mode."
|
||||
|
|
|
@ -61,3 +61,18 @@ And a markdown link: [forumwarz](http://forumwarz.com)
|
|||
And a markdown link with a period after it [codinghorror](http://www.codinghorror.com/blog).
|
||||
"
|
||||
end
|
||||
|
||||
Fabricator(:private_message_post, from: :post) do
|
||||
user
|
||||
topic do |attrs|
|
||||
Fabricate( :private_message_topic,
|
||||
user: attrs[:user],
|
||||
created_at: attrs[:created_at],
|
||||
topic_allowed_users: [
|
||||
Fabricate.build(:topic_allowed_user, user_id: attrs[:user].id),
|
||||
Fabricate.build(:topic_allowed_user, user_id: Fabricate(:user).id)
|
||||
]
|
||||
)
|
||||
end
|
||||
raw "Ssshh! This is our secret conversation!"
|
||||
end
|
|
@ -2,66 +2,121 @@ require 'spec_helper'
|
|||
|
||||
describe Report do
|
||||
|
||||
# describe 'visits report' do
|
||||
# let(:report) { Report.find('visits', cache: false) }
|
||||
describe 'visits report' do
|
||||
let(:report) { Report.find('visits') }
|
||||
|
||||
# context "no visits" do
|
||||
# it "returns an empty report" do
|
||||
# report.data.should be_blank
|
||||
# end
|
||||
# end
|
||||
context "no visits" do
|
||||
it "returns an empty report" do
|
||||
report.data.should be_blank
|
||||
end
|
||||
end
|
||||
|
||||
# context "with visits" do
|
||||
# let(:user) { Fabricate(:user) }
|
||||
context "with visits" do
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
# before do
|
||||
# user.user_visits.create(visited_at: 1.day.ago)
|
||||
# user.user_visits.create(visited_at: 2.days.ago)
|
||||
# end
|
||||
before do
|
||||
user.user_visits.create(visited_at: 1.day.ago)
|
||||
user.user_visits.create(visited_at: 2.days.ago)
|
||||
end
|
||||
|
||||
# it "returns a report with data" do
|
||||
# report.data.should be_present
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
it "returns a report with data" do
|
||||
report.data.should be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# [:signup, :topic, :post, :flag, :like, :email].each do |arg|
|
||||
# describe "#{arg} report" do
|
||||
# pluralized = arg.to_s.pluralize
|
||||
[:signup, :topic, :post, :flag, :like, :email].each do |arg|
|
||||
describe "#{arg} report" do
|
||||
pluralized = arg.to_s.pluralize
|
||||
|
||||
# let(:report) { Report.find(pluralized, cache: false) }
|
||||
let(:report) { Report.find(pluralized) }
|
||||
|
||||
# context "no #{pluralized}" do
|
||||
# it 'returns an empty report' do
|
||||
# report.data.should be_blank
|
||||
# end
|
||||
# end
|
||||
context "no #{pluralized}" do
|
||||
it 'returns an empty report' do
|
||||
report.data.should be_blank
|
||||
end
|
||||
end
|
||||
|
||||
# context "with #{pluralized}" do
|
||||
# before do
|
||||
# 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)
|
||||
# end
|
||||
context "with #{pluralized}" do
|
||||
before do
|
||||
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)
|
||||
end
|
||||
|
||||
# it 'returns correct data' do
|
||||
# report.data[0][:y].should == 1
|
||||
# report.data[1][:y].should == 2
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
it 'returns correct data' do
|
||||
report.data[0][:y].should == 1
|
||||
report.data[1][:y].should == 2
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'private messages' do
|
||||
let(:report) { Report.find('private_messages') }
|
||||
|
||||
it 'topic report should not include private messages' do
|
||||
Fabricate(:private_message_topic, created_at: 1.hour.ago)
|
||||
Fabricate(:topic, created_at: 1.hour.ago)
|
||||
report = Report.find('topics')
|
||||
report.data[0][:y].should == 1
|
||||
end
|
||||
|
||||
it 'post report should not include private messages' do
|
||||
Fabricate(:private_message_post, created_at: 1.hour.ago)
|
||||
Fabricate(:post)
|
||||
report = Report.find('posts')
|
||||
report.data[0][:y].should == 1
|
||||
end
|
||||
|
||||
context 'no private messages' do
|
||||
it 'returns an empty report' do
|
||||
report.data.should be_blank
|
||||
end
|
||||
|
||||
context 'some public posts' do
|
||||
it 'returns an empty report' do
|
||||
Fabricate(:post); Fabricate(:post)
|
||||
report.data.should be_blank
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'some private messages' do
|
||||
before do
|
||||
Fabricate(:private_message_post, created_at: 25.hours.ago)
|
||||
Fabricate(:private_message_post, created_at: 1.hour.ago)
|
||||
Fabricate(:private_message_post, created_at: 1.hour.ago)
|
||||
end
|
||||
|
||||
it 'returns correct data' do
|
||||
report.data[0][:y].should == 1
|
||||
report.data[1][:y].should == 2
|
||||
end
|
||||
|
||||
context 'and some public posts' do
|
||||
before do
|
||||
Fabricate(:post); Fabricate(:post)
|
||||
end
|
||||
|
||||
it 'returns correct data' do
|
||||
report.data[0][:y].should == 1
|
||||
report.data[1][:y].should == 2
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'users by trust level report' do
|
||||
let(:report) { Report.find('users_by_trust_level', cache: false) }
|
||||
let(:report) { Report.find('users_by_trust_level') }
|
||||
|
||||
context "no users" do
|
||||
it "returns an empty report" do
|
||||
|
|
Loading…
Reference in New Issue