From: Tomas Sedovic<tsedovic(a)redhat.com>
https://www.aeolusproject.org/redmine/issues/2246
---
src/app/models/deployment.rb | 22 ++++++++++++++++++
src/app/models/pool.rb | 18 ++++++++++++++
src/app/views/deployments/_list.haml | 17 ++++++++++++++
src/app/views/pools/_list.haml | 19 ++++++++++++++-
src/public/javascripts/backbone/models.js | 11 +++++++++
src/public/javascripts/backbone/routers.js | 26 ++++++++++++++++++++-
src/public/javascripts/backbone/views.js | 34 ++++++++++++++++++++++++++++
7 files changed, 144 insertions(+), 3 deletions(-)
diff --git a/src/app/models/deployment.rb b/src/app/models/deployment.rb
index acd195f..aa96855 100644
--- a/src/app/models/deployment.rb
+++ b/src/app/models/deployment.rb
@@ -282,4 +282,26 @@ class Deployment< ActiveRecord::Base
events.find_by_status_code(:all_stopped).event_time -
events.find_by_status_code(:all_running).event_time
end
end
+
+ def as_json(options={})
+ json = super(options).merge({
+ :owner => owner.name,
+ :deployable_xml_name => deployable_xml.name,
+ :instances_count => instances.count,
+ :href => Rails.application.routes.url_helpers.deployment_path(id),
+ :pool => {
+ :name => pool.name,
+ :href => Rails.application.routes.url_helpers.pool_path(pool.id),
+ },
+ })
+
+ if provider
+ json[:provider] = {
+ :name => provider.provider_type.name,
+ :href => Rails.application.routes.url_helpers.provider_path(provider.id),
+ }
+ end
+
+ json
+ end
end
diff --git a/src/app/models/pool.rb b/src/app/models/pool.rb
index 76516b7..1e980c2 100644
--- a/src/app/models/pool.rb
+++ b/src/app/models/pool.rb
@@ -37,6 +37,7 @@
class Pool< ActiveRecord::Base
include PermissionedObject
+ include ActionView::Helpers::NumberHelper
has_many :instances, :dependent => :destroy
belongs_to :quota, :autosave => true, :dependent => :destroy
belongs_to :pool_family
@@ -87,10 +88,14 @@ class Pool< ActiveRecord::Base
{
:cloud_providers => instances.collect{|i| i.provider_account}.uniq.count,
:deployments => deployments.count,
+ :total_instances => (instances.deployed.count +
+ instances.pending.count + instances.failed.count),
:instances_deployed => instances.deployed.count,
:instances_pending => instances.pending.count,
:instances_failed => instances.failed.count,
:used_quota => quota.running_instances,
+ :quota_percent => number_to_percentage(quota.percentage_used,
+ :precision => 0),
:available_quota => quota.maximum_running_instances
}
#end
@@ -101,4 +106,17 @@ class Pool< ActiveRecord::Base
:order => (order_field || 'name') +' '+ (order_dir ||
'asc'))
end
+ def as_json(options={})
+ super(options).merge({
+ :statistics => statistics,
+ :deployments_count => deployments.count,
+ :href => Rails.application.routes.url_helpers.pool_path(id),
+ :pool_family => {
+ :name => pool_family.name,
+ :href =>
Rails.application.routes.url_helpers.pool_family_path(pool_family.id),
+ },
+
+ })
+ end
+
end
diff --git a/src/app/views/deployments/_list.haml b/src/app/views/deployments/_list.haml
index 0b4dba6..c474218 100644
--- a/src/app/views/deployments/_list.haml
+++ b/src/app/views/deployments/_list.haml
@@ -32,3 +32,20 @@
'#{url_for(:action => :show, :details_tab => 'deployments',
:view => 'filter' )}',
'#{url_for(:action => :show, :details_tab => 'deployments',
:view => 'pretty' )}'
);
+
+%script#deploymentTemplate{ :type => 'text/x-jquery-tmpl' }
+ :plain
+<tr>
+<td><input type="checkbox" id="deployment_checkbox_${id}"
+ name="deployments_selected[]"
value="${id}"></td>
+<td />
+<td><a href="${href}">${name}</a></td>
+<td>${created_at}</td>
+<td>${deployable_xml_name}</td>
+<td>${instances_count}</td>
+<td><a href="${pool.href}">${pool.name}</a></td>
+<td>${owner}</td>
+ {{if provider}}
+<td><a
href="${provider.href}">${provider.name}</a></td>
+ {{/if}}
+</tr>
diff --git a/src/app/views/pools/_list.haml b/src/app/views/pools/_list.haml
index fe5ef20..f691c87 100644
--- a/src/app/views/pools/_list.haml
+++ b/src/app/views/pools/_list.haml
@@ -15,12 +15,27 @@
%td
= pool.deployments.count
%td
- = (pool.statistics[:instances_deployed] + pool.statistics[:instances_pending] +
pool.statistics[:instances_failed])
+ = pool.statistics[:total_instances]
%td
= pool.statistics[:instances_pending]
%td
= pool.statistics[:instances_failed]
%td
- = number_to_percentage(pool.quota.percentage_used, :precision => 0)
+ = pool.statistics[:quota_percent]
%td
= link_to(pool.pool_family.name, pool.pool_family)
+
+%script#poolTemplate{ :type => 'text/x-jquery-tmpl' }
+ :plain
+<tr>
+<td><input type="checkbox" id="pool_checkbox_${id}"
+ name="pools_selected[]"
value="${id}"></td>
+<td />
+<td><a href="${href}">${name}</a></td>
+<td>${deployments_count}</td>
+<td>${statistics.total_instances}</td>
+<td>${statistics.instances_pending}</td>
+<td>${statistics.instances_failed}</td>
+<td>${statistics.quota_percent}</td>
+<td><a
href="${pool_family.href}">${pool_family.name}</a></td>
+</tr>
diff --git a/src/public/javascripts/backbone/models.js
b/src/public/javascripts/backbone/models.js
index 1d48502..7c48778 100644
--- a/src/public/javascripts/backbone/models.js
+++ b/src/public/javascripts/backbone/models.js
@@ -5,6 +5,11 @@ Conductor.Models.Pool = Backbone.Model.extend({
urlRoot: Conductor.prefixedPath('/pools'),
});
+Conductor.Models.Pools = Backbone.Collection.extend({
+ model: Backbone.Model.Pool,
+ url: Conductor.prefixedPath('/pools'),
+});
+
Conductor.Models.Instance = Backbone.Model.extend({
urlRoot: Conductor.prefixedPath('/instances'),
@@ -12,6 +17,7 @@ Conductor.Models.Instance = Backbone.Model.extend({
Conductor.Models.Instances = Backbone.Collection.extend({
model: Backbone.Model.Instance,
+ url: Conductor.prefixedPath('/instances'),
});
Conductor.Models.Deployment = Backbone.Model.extend({
@@ -23,3 +29,8 @@ Conductor.Models.Deployment = Backbone.Model.extend({
},
});
+
+Conductor.Models.Deployments = Backbone.Collection.extend({
+ model: Backbone.Model.Deployment,
+ url: Conductor.prefixedPath('/deployments'),
+});
diff --git a/src/public/javascripts/backbone/routers.js
b/src/public/javascripts/backbone/routers.js
index 46c7f71..62de835 100644
--- a/src/public/javascripts/backbone/routers.js
+++ b/src/public/javascripts/backbone/routers.js
@@ -4,11 +4,35 @@ Conductor.Routers = Conductor.Routers || {}
Conductor.Routers.Pools = Backbone.Router.extend({
routes: {
'': 'index',
- 'pools': 'index',
+ 'pools:query': 'index',
'pools/:id': 'show',
},
index: function() {
+ setInterval(function() {
+ var view = new Conductor.Views.PoolsIndex();
+
+ switch(view.currentTab()) {
+ case 'pools':
+ view.collection = new Conductor.Models.Pools();
+ break;
+ case 'deployments':
+ view.collection = new Conductor.Models.Deployments();
+ break;
+ case 'instances':
+ view.collection = new Conductor.Models.Instances();
+ break;
+ default:
+ return;
+ }
+
+ view.collection.bind('change', function() { view.render() });
+
+ view.collection.fetch({ success: function() {
+ view.collection.trigger('change')
+ }})
+
+ }, Conductor.AJAX_REFRESH_INTERVAL);
},
show: function(id) {
diff --git a/src/public/javascripts/backbone/views.js
b/src/public/javascripts/backbone/views.js
index a96da46..f456a85 100644
--- a/src/public/javascripts/backbone/views.js
+++ b/src/public/javascripts/backbone/views.js
@@ -1,6 +1,40 @@
Conductor.Views = Conductor.Views || {}
+Conductor.Views.PoolsIndex = Backbone.View.extend({
+ el: '#content',
+
+ currentTab: function() {
+ if($('#details_pools.active').length> 0) {
+ return 'pools';
+ }
+ else if ($('#details_deployments.active').length> 0) {
+ return 'deployments';
+ }
+ else if ($('#details_instances.active').length> 0) {
+ return 'instances';
+ }
+ },
+
+ template: function() {
+ switch(this.currentTab()) {
+ case 'pools': return $('#poolTemplate');
+ case 'deployments': return $('#deploymentTemplate');
+ case 'instances': return $('#instanceTemplate');
+ }
+ },
+
+ render: function() {
+ var $template = this.template();
+ var $table = this.$('table.checkbox_table> tbody');
+ if($table.length === 0 || $template.length === 0) return;
+
+ var checkboxes = Conductor.saveCheckboxes('td :checkbox', $table);
+ $table.empty().append($template.tmpl(this.collection.toJSON()))
+ Conductor.restoreCheckboxes(checkboxes, 'td :checkbox', $table);
+ },
+});
+
Conductor.Views.PoolsShow = Backbone.View.extend({
el: '#content',