>From e31c42fcf845b783f884774b6e747dc3ce5ffc63 Mon Sep 17 00:00:00 2001 From: jenik Date: Thu, 3 Jun 2010 22:56:58 +0200 Subject: [PATCH] key indicators portlet displays summary about instances, accounts/pools/providers counts --- src/app/controllers/dashboard_controller.rb | 2 + src/app/models/instance.rb | 22 ++++++++++++++++++ src/app/views/dashboard/summary.haml | 24 +++++++++++++++++++ src/public/stylesheets/components.css | 33 +++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 0 deletions(-) diff --git a/src/app/controllers/dashboard_controller.rb b/src/app/controllers/dashboard_controller.rb index 5061284..adc83d2 100644 --- a/src/app/controllers/dashboard_controller.rb +++ b/src/app/controllers/dashboard_controller.rb @@ -42,6 +42,8 @@ class DashboardController < ApplicationController @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..ffefc7b 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,25 @@ 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 f3d6ab6..8be2ccf 100644 --- a/src/app/views/dashboard/summary.haml +++ b/src/app/views/dashboard/summary.haml @@ -44,6 +44,30 @@ %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 + #service_quality_dashboard_section - if @is_admin %h2 diff --git a/src/public/stylesheets/components.css b/src/public/stylesheets/components.css index b61fbc9..1391fc5 100644 --- a/src/public/stylesheets/components.css +++ b/src/public/stylesheets/components.css @@ -175,3 +175,36 @@ ul.nav li.selected { height: 15px; padding: 20px 0 24px 0; } + +#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; +} -- 1.6.6.1