--- src/app/controllers/dashboard_controller.rb | 2 + src/app/models/instance.rb | 23 ++++++++++++++++++ src/app/views/dashboard/summary.haml | 24 +++++++++++++++++++ src/public/stylesheets/components.css | 33 +++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 0 deletions(-)
diff --git a/src/app/controllers/dashboard_controller.rb b/src/app/controllers/dashboard_controller.rb index ef89d95..540f3c7 100644 --- a/src/app/controllers/dashboard_controller.rb +++ b/src/app/controllers/dashboard_controller.rb @@ -34,6 +34,8 @@ class DashboardController < ApplicationController def index @hide_getting_started = cookies["#{@current_user.login}_hide_getting_started"] @current_users_pool = Pool.find(:first, :conditions => ['name = ?', @current_user.login]) + @cloud_accounts = CloudAccount.list_for_user(@current_user, Privilege::ACCOUNT_VIEW) + @stats = Instance.get_user_instances_stats(@current_user) render :action => :summary end
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb index 21a5cef..c3f4063 100644 --- a/src/app/models/instance.rb +++ b/src/app/models/instance.rb @@ -21,6 +21,7 @@
class Instance < ActiveRecord::Base include SearchFilter + include PermissionedObject
cattr_reader :per_page @@per_page = 15 @@ -162,4 +163,26 @@ class Instance < ActiveRecord::Base end end
+ def self.get_user_instances_stats(user) + stats = { + :running_instances => 0, + :stopped_instances => 0, + } + + instances = Instance.with_hardware_profile.list_for_user(user, Privilege::INSTANCE_VIEW) + instances.each do |i| + if i.state == Instance::STATE_RUNNING + stats[:running_instances] += 1 + elsif i.state == Instance::STATE_STOPPED + stats[:stopped_instances] += 1 + end + end + stats[:total_instances] = instances.size + return stats + end + + named_scope :with_hardware_profile, lambda { + {:include => :hardware_profile} + } + end diff --git a/src/app/views/dashboard/summary.haml b/src/app/views/dashboard/summary.haml index 4eeb58b..03bef61 100644 --- a/src/app/views/dashboard/summary.haml +++ b/src/app/views/dashboard/summary.haml @@ -43,6 +43,30 @@ Launch Instances %a{:href => url_for(:controller => "", :action => "")} Enter a help ticket +#key_indicators_dashboard_section + %h2 + Key indicators + %ul + %li + Providers + .count= @providers.size + %li + Accounts + .count= @cloud_accounts.size + %li + Pools + .count= @pools.size + %li + Running instances + .count= @stats[:running_instances] + %li + Stopped instances + .count= @stats[:stopped_instances] + %li + Total instances + .count= @stats[:total_instances] + .instance_graph #instance_graph +
:javascript $("#hide_getting_started").click(function(){ diff --git a/src/public/stylesheets/components.css b/src/public/stylesheets/components.css index 5b25cd4..75f503e 100644 --- a/src/public/stylesheets/components.css +++ b/src/public/stylesheets/components.css @@ -136,3 +136,36 @@ ul.nav li.selected { color: blue; text-decoration: underline; } + +#key_indicators_dashboard_section { + width: 390px; + height: 220px; + border: 1px solid black; + background: #F2F2F2; + padding: 5px 0 5px 15px; + margin: 10px 0px 10px 5px; + -moz-border-radius: 5px; + -webkit-border-radius: 5px; +} + +#key_indicators_dashboard_section ul { + float: left !important; + width: 50%; + margin: 0; + padding: 0; + list-style: none; +} + +#key_indicators_dashboard_section ul li { + width: 80%; + margin: 0; + padding-bottom: 10px; +} + +#key_indicators_dashboard_section .count { + float: right; +} + +#key_indicators_dashboard_section .instance_graph { + float: left; +}