Commit 9351997f authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Move roles statistic to separate page

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent e5d3d06a
...@@ -23,8 +23,9 @@ ...@@ -23,8 +23,9 @@
%h3.text-center %h3.text-center
Users: Users:
= number_with_delimiter(User.count) = number_with_delimiter(User.count)
.text-center
= link_to 'Users statistics', admin_dashboard_stats_path
%hr %hr
= render "admin/dashboard/roles_stats"
= link_to 'New user', new_admin_user_path, class: "btn btn-new" = link_to 'New user', new_admin_user_path, class: "btn btn-new"
.col-sm-4 .col-sm-4
.info-well.dark-well .info-well.dark-well
......
...@@ -138,6 +138,8 @@ namespace :admin do ...@@ -138,6 +138,8 @@ namespace :admin do
get :status get :status
end end
end end
get '/dashboard/stats', to: 'dashboard#stats'
## EE-specific ## EE-specific
resources :labels resources :labels
......
...@@ -4,13 +4,7 @@ module EE ...@@ -4,13 +4,7 @@ module EE
module DashboardController module DashboardController
extend ActiveSupport::Concern extend ActiveSupport::Concern
prepended do def stats
before_action :set_roles_count, only: [:index]
end
private
def set_roles_count
@admin_count = ::User.admins.count @admin_count = ::User.admins.count
@roles_count = ::ProjectAuthorization.roles_stats @roles_count = ::ProjectAuthorization.roles_stats
end end
......
- if @admin_count
%p
Admin users
%span.light.pull-right
= @admin_count
- if @roles_count
- @roles_count.each do |row|
%p
Users with highest role
%strong
= row['kind']
%span.light.pull-right
= row['amount']
%h3 Users statistics
%table.table
%tr
%td Users total
%td
= User.count
- if @admin_count
%tr
%td Admin users
%td
= @admin_count
- if @roles_count
- @roles_count.each do |row|
%tr
%td
Users with highest role
%strong
= row['kind']
%td
= row['amount']
require 'spec_helper' require 'spec_helper'
describe "Admin Dashboard" do describe 'Admin Dashboard' do
before do describe 'Users statistic' do
3.times do before do
project = create(:project) 3.times do
user = create(:user) project = create(:project)
project.add_reporter(user) user = create(:user)
end project.add_reporter(user)
end
2.times do 2.times do
project = create(:project) project = create(:project)
user = create(:user) user = create(:user)
project.add_developer(user) project.add_developer(user)
end end
# Add same user as Reporter and Developer to different projects # Add same user as Reporter and Developer to different projects
# and expect it to be counted once for the stats # and expect it to be counted once for the stats
user = create(:user) user = create(:user)
project1 = Project.first project1 = Project.first
project2 = Project.last project2 = Project.last
project1.add_reporter(user) project1.add_reporter(user)
project2.add_developer(user) project2.add_developer(user)
sign_in(create(:admin)) sign_in(create(:admin))
end end
describe 'Roles stats' do describe 'Roles stats' do
it 'show correct amount of users per role' do it 'show correct amount of users per role' do
visit admin_root_path visit admin_dashboard_stats_path
expect(page).to have_content('Admin users 1') expect(page).to have_content('Admin users 1')
expect(page).to have_content('Users with highest role developer 3') expect(page).to have_content('Users with highest role developer 3')
expect(page).to have_content('Users with highest role reporter 3') expect(page).to have_content('Users with highest role reporter 3')
end
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment