Show current user count for now, not at different points in time

This commit is contained in:
Neil Lalonde 2013-03-15 16:17:19 -04:00
parent 3ba567eba0
commit 8983df9856
7 changed files with 21 additions and 36 deletions

View File

@ -26,6 +26,7 @@ Discourse.AdminDashboardRoute = Discourse.Route.extend({
d.reports.each(function(report){ d.reports.each(function(report){
c.set(report.type, Discourse.Report.create(report)); c.set(report.type, Discourse.Report.create(report));
}); });
c.set('totalUsers', d.total_users);
c.set('loading', false); c.set('loading', false);
}); });
} }

View File

@ -38,6 +38,15 @@
</p> </p>
</div> </div>
<div class="dashboard-stats totals">
<table class="table table-condensed table-hover">
<tr>
<td class="title">{{i18n admin.dashboard.total_users}}</td>
<td class="value">{{#unless loading}}{{ totalUsers }}{{/unless}}</td>
</tr>
</table>
</div>
<div class="dashboard-stats"> <div class="dashboard-stats">
<table class="table table-condensed table-hover"> <table class="table table-condensed table-hover">
<thead> <thead>
@ -70,7 +79,6 @@
</tr> </tr>
</thead> </thead>
{{#unless loading}} {{#unless loading}}
{{ render 'admin_report_total_users' total_users }}
{{ render 'admin_report_visits' visits }} {{ render 'admin_report_visits' visits }}
{{/unless}} {{/unless}}
</table> </table>

View File

@ -324,6 +324,14 @@ table {
text-align: center; text-align: center;
} }
} }
&.totals {
width: 160px;
table tr:first-child td {
border-top: none;
}
}
} }

View File

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

View File

@ -69,17 +69,6 @@ class Report
end end
end end
def self.report_total_users(report)
report.data = []
fetch report do
(0..30).to_a.reverse.each do |i|
if (count = User.where('created_at < ?', i.days.ago).count) > 0
report.data << {x: i.days.ago.to_date.to_s, y: count}
end
end
end
end
def self.report_flags(report) def self.report_flags(report)
report.data = [] report.data = []
fetch report do fetch report do

View File

@ -690,6 +690,7 @@ en:
please_upgrade: "Please upgrade!" please_upgrade: "Please upgrade!"
latest_version: "Latest version" latest_version: "Latest version"
update_often: 'Please update often!' update_often: 'Please update often!'
total_users: "Total Users"
reports: reports:
today: "Today" today: "Today"

View File

@ -58,29 +58,6 @@ describe Report do
end end
end end
describe "total_users report" do
let(:report) { Report.find("total_users", cache: false) }
context "no total_users" do
it 'returns an empty report' do
report.data.should be_blank
end
end
context "with users" do
before do
Fabricate(:user, created_at: 25.hours.ago)
Fabricate(:user, created_at: 1.hours.ago)
Fabricate(:user, created_at: 1.hours.ago)
end
it 'returns correct data' do
report.data[0][:y].should == 1
report.data[1][:y].should == 3
end
end
end
describe '#fetch' do describe '#fetch' do
context 'signups' do context 'signups' do
let(:report) { Report.find('signups', cache: true) } let(:report) { Report.find('signups', cache: true) }