[PATCH conductor 7/7] Mustachifying instances/_list

ifarkas at redhat.com ifarkas at redhat.com
Tue Feb 28 14:53:29 UTC 2012


From: Imre Farkas <ifarkas at redhat.com>

---
 src/app/controllers/pools_controller.rb            |    2 +-
 src/app/helpers/mustache_helper.rb                 |    3 ++
 .../views/instances/_instance_row.html.mustache    |   17 ++++++++++
 src/app/views/instances/_list.html.haml            |   34 +++++--------------
 4 files changed, 30 insertions(+), 26 deletions(-)
 create mode 100644 src/app/views/instances/_instance_row.html.mustache

diff --git a/src/app/controllers/pools_controller.rb b/src/app/controllers/pools_controller.rb
index e381aed..677d301 100644
--- a/src/app/controllers/pools_controller.rb
+++ b/src/app/controllers/pools_controller.rb
@@ -71,7 +71,7 @@ class PoolsController < ApplicationController
         when 'pools'
           render :json => @pools.map{ |pool| view_context.pool_for_mustache(pool) }
         when 'instances'
-          render :json => @instances
+          render :json => @instances.map{ |instance| view_context.instance_for_mustache(instance) }
         when 'deployments'
           render :json => @deployments.map{ |deployment| view_context.deployment_for_mustache(deployment) }
         end
diff --git a/src/app/helpers/mustache_helper.rb b/src/app/helpers/mustache_helper.rb
index f16f26e..2af6384 100644
--- a/src/app/helpers/mustache_helper.rb
+++ b/src/app/helpers/mustache_helper.rb
@@ -28,10 +28,13 @@ module MustacheHelper
       :path     => instance_path(instance),
       :uptime   => count_uptime(instance.uptime),
       :state    => instance.state,
+      :failed   => instance.failed?,
       :public_addresses     => instance.public_addresses.present? ? instance.public_addresses : I18n.t('deployments.pretty_view_show.no_ip_address'),
       :instance_key_present => instance.instance_key.present?,
       :stop_enabled         => available_actions.include?(InstanceTask::ACTION_STOP),
       :reboot_enabled       => available_actions.include?(InstanceTask::ACTION_REBOOT),
+      :provider             => instance.provider_account.present? ? instance.provider_account.provider.name : nil,
+      :owner                => instance.owner.present? ? instance.owner.name : nil,
     }
   end
 
diff --git a/src/app/views/instances/_instance_row.html.mustache b/src/app/views/instances/_instance_row.html.mustache
new file mode 100644
index 0000000..847a972
--- /dev/null
+++ b/src/app/views/instances/_instance_row.html.mustache
@@ -0,0 +1,17 @@
+<tr>
+  <td class="checkbox">
+    <%= check_box_tag("instances_selected[]", '{{id}}', :id => "instance_checkbox_{{id}}") %>
+  </td>
+  <td class="alert">
+    {{#failed}}
+      <%= image_tag("sb_icon_instance_failure.png") %>
+    {{/failed}}
+  </td>
+  <td>
+    <%= link_to('{{name}}', '{{path}}') %>
+  </td>
+  <td>{{public_addresses}}</td>
+  <td>{{state}}</td>
+  <td>{{provider}}</td>
+  <td>{{owner}}</td>
+</tr>
diff --git a/src/app/views/instances/_list.html.haml b/src/app/views/instances/_list.html.haml
index 675efc2..e7d2e8d 100644
--- a/src/app/views/instances/_list.html.haml
+++ b/src/app/views/instances/_list.html.haml
@@ -25,34 +25,18 @@
     });
 
 = filter_table(instances_header, @instances) do |instance|
-  %tr{ :class => cycle('nostripe', 'stripe') }
-    %td{:class => 'checkbox'}
-      - selected = params[:select] == 'all'
-      = check_box_tag "instance_selected[]", instance.id, selected, :id => "instance_checkbox_#{instance.id}"
-    %td{:class => 'alert'}= instance.failed? ? image_tag("sb_icon_instance_failure.png") : ""
-    %td= link_to instance.name, instance_path(instance)
-    %td= instance.public_addresses
-    %td= instance.state
-    %td= instance.provider_account ? instance.provider_account.provider.name : ''
-    %td= owner_name(instance)
+  = render :partial => 'instances/instance_row', :mustache => instance_for_mustache(instance)
 
 :javascript
   Conductor.setupPrettyFilterURL(
             '#{url_for(:action => :show, :details_tab => 'instances', :view => 'filter' )}',
             '#{url_for(:action => :show, :details_tab => 'instances', :view => 'pretty' )}');
 
-%script#instanceTemplate{ :type => 'text/x-jquery-tmpl' }
-  :plain
-    <tr>
-      <td class="checkbox"><input type="checkbox" id="instance_checkbox_${id}" name="instance_selected[]" value="${id}"></td>
-      <td class="alert">
-        {{if is_failed == true}}
-          #{image_tag("sb_icon_instance_failure.png")}
-        {{/if}}
-      </td>
-      <td><a href="#{instance_path('replace_id').sub('replace_id', '${id}')}">${name}</a></td>
-      <td>${public_addresses}</td>
-      <td>${state}</td>
-      <td>${provider}</td>
-      <td>${owner}</td>
-    </tr>
+:javascript
+  $(document).ready(function(){
+    $('tr:odd').addClass('stripe');
+    $('tr:even').addClass('nostripe');
+  });
+
+%script#instanceTemplate{ :type => 'text/html' }
+  = render :partial => 'instances/instance_row'
-- 
1.7.6.5




More information about the aeolus-devel mailing list