On Tuesday 27 September 2011 13:35:40 Jiri Tomasek wrote:
---
src/app/controllers/providers_controller.rb | 34
+++++++++++++++++++++++++++ src/app/stylesheets/layout.scss |
2 +-
src/app/views/pools/_scoreboard_show.haml | 2 +-
src/app/views/providers/edit.haml | 28 ++++++++-------------
src/features/provider_account.feature | 24 +++++++++++++++++++
src/public/javascripts/application.js | 6 +++-
6 files changed, 75 insertions(+), 21 deletions(-)
diff --git a/src/app/controllers/providers_controller.rb
b/src/app/controllers/providers_controller.rb index 818c423..e96eda0
100644
--- a/src/app/controllers/providers_controller.rb
+++ b/src/app/controllers/providers_controller.rb
@@ -46,6 +46,8 @@ class ProvidersController < ApplicationController
@provider = Provider.find_by_id(params[:id])
require_privilege(Privilege::MODIFY, @provider)
+ @alerts = provider_alerts(@provider)
+
if params.delete :test_provider
test_connection(@provider)
end
@@ -174,4 +176,36 @@ class ProvidersController < ApplicationController
def load_providers
@providers = Provider.list_for_user(current_user, Privilege::VIEW,
:order => :name) end
+
+ def provider_alerts(provider)
+ alerts = []
+
+ # Quota Alerts
+ provider.provider_accounts.each do |provider_account|
+ unless provider_account.quota.maximum_running_instances == nil
+ if provider_account.quota.maximum_running_instances <
provider_account.quota.running_instances + alerts << {
+ :type => "critical",
+ :subject => "Quota",
+ :alert_type => "Account Quota Exceeded",
+ :path =>
edit_provider_provider_account_path(@provider,provider_account), +
:description => "Quota limit of running instances for
#{provider_account.name} account has been exceeded." + }
+ end
+
+ if (70..100) === provider_account.quota.percentage_used.round
+ alerts << {
+ :type => "warning",
+ :subject => "Quota",
+ :alert_type =>
"#{provider_account.quota.percentage_used.round}% Account Quota Reached",
+ :path =>
provider_provider_account_path(@provider,provider_account), +
:description => "#{provider_account.quota.percentage_used.round}% of Quota
limit for running instances for #{provider_account.name} account has been
reached." + }
+ end
+ end
+ end
+
+ return alerts
+ end
+
end
diff --git a/src/app/stylesheets/layout.scss
b/src/app/stylesheets/layout.scss index 55e87c4..b2724b9 100644
--- a/src/app/stylesheets/layout.scss
+++ b/src/app/stylesheets/layout.scss
@@ -1740,7 +1740,7 @@ dl.alerts{
font-weight: bold;
}
- dt.subject.warn{
+ dt.subject.warning{
padding-left: $alert_padding*2 + 16px;
background: transparent url('../../images/alert_icon_warn.png')
no-repeat $alert_padding 8px; }
diff --git a/src/app/views/pools/_scoreboard_show.haml
b/src/app/views/pools/_scoreboard_show.haml index eb9ec11..ba05cb1 100644
--- a/src/app/views/pools/_scoreboard_show.haml
+++ b/src/app/views/pools/_scoreboard_show.haml
@@ -27,5 +27,5 @@
%dd.fraction.instance
%span.part= @statistics[:used_quota]
%span.divider.label.small.caps of
- %span.total= @statistics[:available_quota] or '∞'
+ %span.total= @statistics[:available_quota] or
'∞'.html_safe -# TODO: Implement alerts and updates
diff --git a/src/app/views/providers/edit.haml
b/src/app/views/providers/edit.haml index cba1317..6491e2c 100644
--- a/src/app/views/providers/edit.haml
+++ b/src/app/views/providers/edit.haml
@@ -6,24 +6,18 @@
%header
%h2.alerts
Alerts
- %span.label.badge.count.alert 3
+ %span.label.badge.count.alert= @alerts.count
.section-controls
- = link_to "Toggle Alerts", "#", :class => 'collapse
alerts'
- .content.collapsible
- %dl.alerts
- %ul
- %li.alert
- %dt.subject.critical Subject
- %dd.type Alert type
- %dd.desc Lorem Ipsum has been the industry's standard dummy
text ever since the 1500s, when an unknown printer [...] -
%li.alert
- %dt.subject.warn Subject
- %dd.type Alert type
- %dd.desc Lorem Ipsum has been the industry's standard dummy
text ever since the 1500s, when an unknown printer [...] -
%li.alert
- %dt.subject.critical Subject
- %dd.type Alert type
- %dd.desc Lorem Ipsum has been the industry's standard dummy
text ever since the 1500s, when an unknown printer [...] + =
link_to "Toggle Alerts", "#", :class => 'collapse alerts'
unless
@alerts.blank? + - unless @alerts.blank?
+ .content.collapsible
+ %dl.alerts
+ %ul
+ - @alerts.each do |alert|
+ %li.alert
+ %dt.subject{ :class => alert[:type] }= alert[:subject]
+ %dd.type= link_to alert[:alert_type], alert[:path]
+ %dd.desc= alert[:description]
%section.admin-content-section.provider
%header
%h2.activity
diff --git a/src/features/provider_account.feature
b/src/features/provider_account.feature index ab1f9d9..c0ad0ba 100644
--- a/src/features/provider_account.feature
+++ b/src/features/provider_account.feature
@@ -111,6 +111,30 @@ Feature: Manage Provider Accounts
And I press "Save"
Then I should see "Provider Account wasn't updated!"
+ Scenario: Display alert when Provider Account Quota is over 70% filled
+ Given there is a provider named "testprovider"
+ And there is a provider account named "testaccount"
+ And the account has an instance associated with it
+ And I am on the testprovider's provider accounts page
+ When I follow "testaccount"
+ And I follow "Edit"
+ And I fill in "quota[maximum_running_instances]" with "1"
+ And I press "save"
+ Then I should be on the testprovider's edit provider page
+ And I should see "Account Quota Reached"
+
+ Scenario: Display alert when Provider Account Quota is exceeded
+ Given there is a provider named "testprovider"
+ And there is a provider account named "testaccount"
+ And the account has an instance associated with it
+ And I am on the testprovider's provider accounts page
+ When I follow "testaccount"
+ And I follow "Edit"
+ And I fill in "quota[maximum_running_instances]" with "0"
+ And I press "save"
+ Then I should be on the testprovider's edit provider page
+ And I should see "Account Quota Exceeded"
+
# Scenario: Search for Provider Accounts
# Given there is a provider named "testprovider"
# And there is a provider account named "testaccount"
diff --git a/src/public/javascripts/application.js
b/src/public/javascripts/application.js index 4159e7d..e6c2208 100644
--- a/src/public/javascripts/application.js
+++ b/src/public/javascripts/application.js
@@ -120,13 +120,15 @@ $.extend(Conductor, {
},
closeNotification: function() {
- $('.control').click(function() {
+ $('.control').click(function(e) {
+ e.preventDefault();
$('#flash-hud').slideUp(100).fadeOut(100);
});
},
toggleCollapsible: function() {
- $('.collapse').click(function() {
+ $('.collapse').click(function(e) {
+ e.preventDefault();
$(this).parents('section').find('.collapsible').slideToggle(80);
});
},
ACK.
--
Jozef Zigmund