dashboard next: adds report for user types
This commit is contained in:
parent
9353ae4b5d
commit
06b6c805d5
|
@ -26,6 +26,7 @@
|
|||
|
||||
<div class="section-columns">
|
||||
<div class="section-column">
|
||||
{{dashboard-mini-table dataSourceName="users_by_types"}}
|
||||
{{dashboard-mini-table dataSourceName="users_by_trust_level"}}
|
||||
</div>
|
||||
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
}
|
||||
|
||||
.dashboard-mini-table {
|
||||
margin-bottom: 1em;
|
||||
|
||||
.table-title {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
|
|
|
@ -243,4 +243,22 @@ class Report
|
|||
.group(:user_agent).sum(:count)
|
||||
.map { |ua, count| { x: ua, y: count } }
|
||||
end
|
||||
|
||||
def self.report_users_by_types(report)
|
||||
report.data = []
|
||||
|
||||
label = Proc.new { |key| I18n.t("reports.users_by_types.xaxis_labels.#{key}") }
|
||||
|
||||
admins = User.real.where(admin: true).count
|
||||
report.data << { x: label.call("admin"), y: admins } if admins > 0
|
||||
|
||||
moderators = User.real.where(moderator: true).count
|
||||
report.data << { x: label.call("moderator"), y: moderators } if moderators > 0
|
||||
|
||||
suspended = User.suspended.count
|
||||
report.data << { x: label.call("suspended"), y: suspended } if suspended > 0
|
||||
|
||||
silenced = User.silenced.count
|
||||
report.data << { x: label.call("silenced"), y: silenced } if silenced > 0
|
||||
end
|
||||
end
|
||||
|
|
|
@ -869,6 +869,15 @@ en:
|
|||
title: "Users per Trust Level"
|
||||
xaxis: "Trust Level"
|
||||
yaxis: "Number of Users"
|
||||
users_by_types:
|
||||
title: "Users per types"
|
||||
xaxis: "Type"
|
||||
yaxis: "Number of Users"
|
||||
xaxis_labels:
|
||||
admin: Admin
|
||||
moderator: Moderator
|
||||
suspended: Suspended
|
||||
silenced: Silenced
|
||||
emails:
|
||||
title: "Emails Sent"
|
||||
xaxis: "Day"
|
||||
|
|
|
@ -250,6 +250,33 @@ describe Report do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'users by types level report' do
|
||||
let(:report) { Report.find('users_by_types') }
|
||||
|
||||
context "no users" do
|
||||
it "returns an empty report" do
|
||||
expect(report.data).to be_blank
|
||||
end
|
||||
end
|
||||
|
||||
context "with users at different trust levels" do
|
||||
before do
|
||||
3.times { Fabricate(:user, admin: true) }
|
||||
2.times { Fabricate(:user, moderator: true) }
|
||||
UserSilencer.silence(Fabricate(:user), Fabricate.build(:admin))
|
||||
Fabricate(:user, suspended_till: 1.week.from_now, suspended_at: 1.day.ago)
|
||||
end
|
||||
|
||||
it "returns a report with data" do
|
||||
expect(report.data).to be_present
|
||||
expect(report.data.find { |d| d[:x] == "admin" }[:y]).to eq 3
|
||||
expect(report.data.find { |d| d[:x] == "moderator" }[:y]).to eq 2
|
||||
expect(report.data.find { |d| d[:x] == "silenced" }[:y]).to eq 1
|
||||
expect(report.data.find { |d| d[:x] == "suspended" }[:y]).to eq 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'posts counts' do
|
||||
it "only counts regular posts" do
|
||||
post = Fabricate(:post)
|
||||
|
|
Loading…
Reference in New Issue