mirror of
https://github.com/discourse/discourse.git
synced 2025-01-21 06:23:01 +08:00
Add user counts for each trust level to admin dashboard
This commit is contained in:
parent
1d9764d8fc
commit
d9cdde9aa7
|
@ -36,3 +36,21 @@ Handlebars.registerHelper('sumLast', function(property, numDays) {
|
|||
return sum;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
Return the count of users at the given trust level.
|
||||
|
||||
@method valueAtTrustLevel
|
||||
@for Handlebars
|
||||
**/
|
||||
Handlebars.registerHelper('valueAtTrustLevel', function(property, trustLevel) {
|
||||
var data = Ember.Handlebars.get(this, property);
|
||||
if( data ) {
|
||||
var item = data.find( function(d, i, arr) { return parseInt(d.x,10) === parseInt(trustLevel,10); } );
|
||||
if( item ) {
|
||||
return item.y;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
});
|
|
@ -38,12 +38,27 @@
|
|||
</p>
|
||||
</div>
|
||||
|
||||
<div class="dashboard-stats totals">
|
||||
|
||||
<div class="dashboard-stats">
|
||||
{{i18n admin.dashboard.total_users}}: <strong>{{#unless loading}}{{ totalUsers }}{{/unless}}</strong><br/>
|
||||
</div>
|
||||
|
||||
<div class="dashboard-stats trust-levels">
|
||||
<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>
|
||||
<thead>
|
||||
<tr>
|
||||
<th> </th>
|
||||
<th>0</th>
|
||||
<th>1</th>
|
||||
<th>2</th>
|
||||
<th>3</th>
|
||||
<th>4</th>
|
||||
<th>5</th>
|
||||
</tr>
|
||||
</thead>
|
||||
{{#unless loading}}
|
||||
{{ render 'admin_report_trust_levels' users_by_trust_level }}
|
||||
{{/unless}}
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
<tr>
|
||||
<td class="title">{{title}}</td>
|
||||
<td class="value">{{valueAtTrustLevel data 0}}</td>
|
||||
<td class="value">{{valueAtTrustLevel data 1}}</td>
|
||||
<td class="value">{{valueAtTrustLevel data 2}}</td>
|
||||
<td class="value">{{valueAtTrustLevel data 3}}</td>
|
||||
<td class="value">{{valueAtTrustLevel data 4}}</td>
|
||||
<td class="value">{{valueAtTrustLevel data 5}}</td>
|
||||
</tr>
|
|
@ -0,0 +1,4 @@
|
|||
Discourse.AdminReportTrustLevelsView = Discourse.View.extend({
|
||||
templateName: 'admin/templates/reports/trust_levels_report',
|
||||
tagName: 'tbody'
|
||||
});
|
|
@ -332,6 +332,10 @@ table {
|
|||
border-top: none;
|
||||
}
|
||||
}
|
||||
|
||||
&.trust-levels {
|
||||
margin-top: 0px;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
|
||||
class Admin::DashboardController < Admin::AdminController
|
||||
|
||||
def index
|
||||
render_json_dump({
|
||||
reports: ['visits', 'signups', 'topics', 'posts', 'flags'].map { |type| Report.find(type) },
|
||||
reports: ['visits', 'signups', 'topics', 'posts', 'flags', 'users_by_trust_level'].map { |type| Report.find(type) },
|
||||
total_users: User.count
|
||||
}.merge(
|
||||
SiteSetting.version_checks? ? {version_check: DiscourseUpdates.check_version} : {}
|
||||
|
|
|
@ -80,6 +80,15 @@ class Report
|
|||
end
|
||||
end
|
||||
|
||||
def self.report_users_by_trust_level(report)
|
||||
report.data = []
|
||||
fetch report do
|
||||
User.counts_by_trust_level.each do |level, count|
|
||||
report.data << {x: level.to_i, y: count}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
|
|
@ -462,6 +462,10 @@ class User < ActiveRecord::Base
|
|||
where('created_at > ?', since).group('date(created_at)').order('date(created_at)').count
|
||||
end
|
||||
|
||||
def self.counts_by_trust_level
|
||||
group('trust_level').count
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def cook
|
||||
|
|
|
@ -271,6 +271,10 @@ en:
|
|||
title: "Flags"
|
||||
xaxis: "Day"
|
||||
yaxis: "Number of flags"
|
||||
users_by_trust_level:
|
||||
title: "Users per Trust Level"
|
||||
xaxis: "Trust Level"
|
||||
yaxis: "Number of Users"
|
||||
|
||||
site_settings:
|
||||
default_locale: "The default language of this Discourse instance (ISO 639-1 Code)"
|
||||
|
|
|
@ -4,7 +4,6 @@ describe Report do
|
|||
|
||||
|
||||
describe 'visits report' do
|
||||
|
||||
let(:report) { Report.find('visits', cache: false) }
|
||||
|
||||
context "no visits" do
|
||||
|
@ -24,10 +23,7 @@ describe Report do
|
|||
it "returns a report with data" do
|
||||
report.data.should be_present
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
[:signup, :topic, :post, :flag].each do |arg|
|
||||
|
@ -58,6 +54,31 @@ describe Report do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'users by trust level report' do
|
||||
let(:report) { Report.find('users_by_trust_level', cache: false) }
|
||||
|
||||
context "no users" do
|
||||
it "returns an empty report" do
|
||||
report.data.should be_blank
|
||||
end
|
||||
end
|
||||
|
||||
context "with users at different trust levels" do
|
||||
before do
|
||||
3.times { Fabricate(:user, trust_level: TrustLevel.levels[:new]) }
|
||||
2.times { Fabricate(:user, trust_level: TrustLevel.levels[:regular]) }
|
||||
Fabricate(:user, trust_level: TrustLevel.levels[:moderator])
|
||||
end
|
||||
|
||||
it "returns a report with data" do
|
||||
report.data.should be_present
|
||||
report.data.find {|d| d[:x] == TrustLevel.levels[:new]} [:y].should == 3
|
||||
report.data.find {|d| d[:x] == TrustLevel.levels[:regular]}[:y].should == 2
|
||||
report.data.find {|d| d[:x] == TrustLevel.levels[:moderator]}[:y].should == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#fetch' do
|
||||
context 'signups' do
|
||||
let(:report) { Report.find('signups', cache: true) }
|
||||
|
|
Loading…
Reference in New Issue
Block a user