[PATCH conductor] Autoupdating deployments list on Pools#index

ifarkas at redhat.com ifarkas at redhat.com
Tue Dec 13 12:33:54 UTC 2011


From: Imre Farkas <ifarkas at redhat.com>

---
 src/app/models/deployment.rb               |    1 +
 src/app/views/pools/_deployments.html.haml |   24 ++++++++++++++-
 src/public/javascripts/backbone/routers.js |   27 ++++++++++-------
 src/public/javascripts/backbone/views.js   |   44 +++++++++++++++++++---------
 4 files changed, 70 insertions(+), 26 deletions(-)

diff --git a/src/app/models/deployment.rb b/src/app/models/deployment.rb
index 1a799b8..7b5ce76 100644
--- a/src/app/models/deployment.rb
+++ b/src/app/models/deployment.rb
@@ -398,6 +398,7 @@ class Deployment < ActiveRecord::Base
       :deployment_state => deployment_state,
       :instances_count => instances.count,
       :uptime => ApplicationHelper.count_uptime(uptime_1st_instance),
+      :global_uptime => ApplicationHelper.count_uptime(uptime_all),
       :pool => {
         :name => pool.name,
         :id => pool.id,
diff --git a/src/app/views/pools/_deployments.html.haml b/src/app/views/pools/_deployments.html.haml
index 70cfea0..af0b8b8 100644
--- a/src/app/views/pools/_deployments.html.haml
+++ b/src/app/views/pools/_deployments.html.haml
@@ -14,4 +14,26 @@
 
             %li.left
               %dt=t :uptime
-              %dd= count_uptime(deployment.uptime_1st_instance)
\ No newline at end of file
+              %dd= count_uptime(deployment.uptime_1st_instance)
+
+%script#deploymentPrettyTemplate{ :type => 'text/x-jquery-tmpl' }
+  :plain
+    <li class="deployment">
+      <h3 class="name">
+        <a href="#{deployment_path('replace_id').sub('replace_id', '${id}')}">${name}</a>
+        #{t 'pools.index.global_uptime'}
+        ${global_uptime}
+      </h3>
+      <dl class="statistics">
+        <ul>
+          <li class="right">
+            <dt class="instances count">#{t 'instances.instances'}</dt>
+            <dd>${instances_count}</dd>
+          </li>
+          <li class="left">
+            <dt>#{t :uptime}</dt>
+            <dd>${uptime}</dd>
+          </li>
+        </ul>
+      </dl>
+    </li>
diff --git a/src/public/javascripts/backbone/routers.js b/src/public/javascripts/backbone/routers.js
index c92ea3d..cb55730 100644
--- a/src/public/javascripts/backbone/routers.js
+++ b/src/public/javascripts/backbone/routers.js
@@ -12,18 +12,23 @@ Conductor.Routers.Pools = Backbone.Router.extend({
     setInterval(function() {
       var view = new Conductor.Views.PoolsIndex();
 
-      switch(view.currentTab()) {
-      case 'pools':
-        view.collection = new Conductor.Models.Pools();
-        break;
-      case 'deployments':
+      if (view.currentView() == 'table') {
+        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;
+        }
+      }
+      else if (view.currentView() == 'pretty') {
         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() });
diff --git a/src/public/javascripts/backbone/views.js b/src/public/javascripts/backbone/views.js
index 488d083..3e2776d 100644
--- a/src/public/javascripts/backbone/views.js
+++ b/src/public/javascripts/backbone/views.js
@@ -4,6 +4,15 @@ Conductor.Views = Conductor.Views || {}
 Conductor.Views.PoolsIndex = Backbone.View.extend({
   el: '#content',
 
+  currentView: function() {
+    if ($('form.filterable-data').length > 0) {
+      return 'table'
+    }
+    else if ($('.deployment-array').length > 0) {
+      return 'pretty'
+    }
+  },
+
   currentTab: function() {
     if($('#details_pools.active').length > 0) {
       return 'pools';
@@ -17,21 +26,33 @@ Conductor.Views.PoolsIndex = Backbone.View.extend({
   },
 
   template: function() {
-    switch(this.currentTab()) {
-      case 'pools': return $('#poolTemplate');
-      case 'deployments': return $('#deploymentTemplate');
-      case 'instances': return $('#instanceTemplate');
+    if (this.currentView() == 'table') {
+      switch(this.currentTab()) {
+        case 'pools': return $('#poolTemplate');
+        case 'deployments': return $('#deploymentTemplate');
+        case 'instances': return $('#instanceTemplate');
+      }
+    }
+    else if (this.currentView() == 'pretty') {
+      return $('#deploymentPrettyTemplate');
     }
   },
 
   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);
+    if (this.currentView() == 'table') {
+      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);
+    }
+    else if (this.currentView() == 'pretty') {
+      $deployments = this.$('ul.deployment-array');
+      var $template = this.template();
+      $deployments.empty().append($template.tmpl(this.collection.toJSON()))
+    }
   },
 });
 
@@ -81,11 +102,6 @@ Conductor.Views.DeploymentsShow = Backbone.View.extend({
 
   el: '#content',
 
-  currentTab: function() {
-    if($('#details_instances.active').length > 0) {
-      return 'instances';
-    }
-  },
   render: function() {
     var $instances = this.$('ul.instances-array');
     if($instances.length === 0) {
-- 
1.7.6.4




More information about the aeolus-devel mailing list