[PATCH conductor 6/7] Mustachifying pools/_list
ifarkas at redhat.com
ifarkas at redhat.com
Tue Feb 28 14:53:28 UTC 2012
From: Imre Farkas <ifarkas at redhat.com>
---
src/app/controllers/pools_controller.rb | 4 +-
src/app/helpers/mustache_helper.rb | 20 ++++++++++++
src/app/views/pools/_list.html.haml | 43 ++++++--------------------
src/app/views/pools/_pool_row.html.mustache | 26 ++++++++++++++++
src/public/javascripts/backbone/views.js | 8 ++++-
5 files changed, 65 insertions(+), 36 deletions(-)
create mode 100644 src/app/views/pools/_pool_row.html.mustache
diff --git a/src/app/controllers/pools_controller.rb b/src/app/controllers/pools_controller.rb
index af053f5..e381aed 100644
--- a/src/app/controllers/pools_controller.rb
+++ b/src/app/controllers/pools_controller.rb
@@ -69,11 +69,11 @@ class PoolsController < ApplicationController
format.json do
case @details_tab[:id]
when 'pools'
- render :json => @pools
+ render :json => @pools.map{ |pool| view_context.pool_for_mustache(pool) }
when 'instances'
render :json => @instances
when 'deployments'
- render :json => @deployments
+ render :json => @deployments.map{ |deployment| view_context.deployment_for_mustache(deployment) }
end
end
end
diff --git a/src/app/helpers/mustache_helper.rb b/src/app/helpers/mustache_helper.rb
index db90ed4..f16f26e 100644
--- a/src/app/helpers/mustache_helper.rb
+++ b/src/app/helpers/mustache_helper.rb
@@ -57,4 +57,24 @@ module MustacheHelper
}
end
+ def pool_for_mustache(pool)
+ pool_statistics = pool.statistics
+ pool_family_privilege = check_privilege(Privilege::VIEW, pool.pool_family)
+
+ {
+ :id => pool.id,
+ :name => pool.name,
+ :filter_view_path => pool_path(pool, :view => :filter),
+ :failed_instances_present => pool_statistics[:instances_failed_count] > 0,
+ :deployments_count => pool.deployments.count,
+ :statistics_total_instances => pool_statistics[:total_instances],
+ :statistics_instances_pending => pool_statistics[:instances_pending],
+ :statistics_instances_failed_count => pool_statistics[:instances_failed_count],
+ :statistics_quota_percent => pool_statistics[:quota_percent],
+ :pool_family_privilege => pool_family_privilege,
+ :pool_family_name => pool.pool_family.name,
+ :pool_family_path => pool_family_privilege ? pool_family_path(pool.pool_family) : nil
+ }
+ end
+
end
diff --git a/src/app/views/pools/_list.html.haml b/src/app/views/pools/_list.html.haml
index 5dc5e5d..af6ce76 100644
--- a/src/app/views/pools/_list.html.haml
+++ b/src/app/views/pools/_list.html.haml
@@ -24,36 +24,13 @@
});
= filter_table(@header, @pools) do |pool|
- - pool_stats = pool.statistics
- %tr{:class => cycle('nostripe','stripe')}
- %td{:class => 'checkbox'}
- %input{:name => "pools_selected[]", :type => "checkbox", :value => pool.id, :id => "pool_checkbox_#{pool.id}" }
- %td{:class => 'alert'}= (@statistics[:instances_failed] & pool.instances).present? ? image_tag("sb_icon_instance_failure.png") : ""
- %td= link_to(pool.name, pool_path(pool, :view => :filter))
- %td{:class => 'center'}= pool.deployments.count
- %td{:class => 'center'}= pool_stats[:total_instances]
- %td{:class => 'center'}= pool_stats[:instances_pending]
- %td{:class => 'center'}= pool_stats[:instances_failed_count]
- %td{:class => 'center'}= pool_stats[:quota_percent]
- - if check_privilege(Privilege::VIEW, pool.pool_family)
- %td= link_to(pool.pool_family.name, pool.pool_family)
- - else
- %td= pool.pool_family.name
-%script#poolTemplate{ :type => 'text/x-jquery-tmpl' }
- :plain
- <tr>
- <td class="checkbox"><input type="checkbox" id="pool_checkbox_${id}"
- name="pools_selected[]" value="${id}"></td>
- <td class="alert">
- {{if statistics.instances_failed_count > 0}}
- #{image_tag("sb_icon_instance_failure.png")}
- {{/if}}
- </td>
- <td><a href="#{pool_path('replace_id', :view => :filter).sub('replace_id', '${id}')}">${name}</a></td>
- <td class="center">${deployments_count}</td>
- <td class="center">${statistics.total_instances}</td>
- <td class="center">${statistics.instances_pending}</td>
- <td class="center">${statistics.instances_failed_count}</td>
- <td class="center">${statistics.quota_percent}</td>
- <td><a href="#{pool_family_path('replace_id').sub('replace_id', '${pool_family.id}')}">${pool_family.name}</a></td>
- </tr>
+ = render :partial => 'pool_row', :mustache => pool_for_mustache(pool)
+
+:javascript
+ $(document).ready(function(){
+ $('tr:odd').addClass('stripe');
+ $('tr:even').addClass('nostripe');
+ });
+
+%script#poolTemplate{ :type => 'text/html' }
+ = render :partial => 'pool_row'
diff --git a/src/app/views/pools/_pool_row.html.mustache b/src/app/views/pools/_pool_row.html.mustache
new file mode 100644
index 0000000..62a70b6
--- /dev/null
+++ b/src/app/views/pools/_pool_row.html.mustache
@@ -0,0 +1,26 @@
+<tr>
+ <td class="checkbox">
+ <%= check_box_tag("pools_selected[]", '{{id}}', :id => "pool_checkbox_{{id}}") %>
+ </td>
+ <td class="alert">
+ {{#failed_instances_present}}
+ <%= image_tag("sb_icon_instance_failure.png") %>
+ {{/failed_instances_present}}
+ </td>
+ <td>
+ <%= link_to('{{name}}', '{{filter_view_path}}') %>
+ </td>
+ <td class="center">{{deployments_count}}</td>
+ <td class="center">{{statistics_total_instances}}</td>
+ <td class="center">{{statistics_instances_pending}}</td>
+ <td class="center">{{statistics_instances_failed_count}}</td>
+ <td class="center">{{statistics_quota_percent}}</td>
+ <td>
+ {{#pool_family_privilege}}
+ <%= link_to('{{pool_family_name}}', '{{pool_family_path}}') %>
+ {{/pool_family_privilege}}
+ {{^pool_family_privilege}}
+ {{pool_family_name}}
+ {{/pool_family_privilege}}
+ </td>
+</tr>
diff --git a/src/public/javascripts/backbone/views.js b/src/public/javascripts/backbone/views.js
index 89ba07f..55ae835 100644
--- a/src/public/javascripts/backbone/views.js
+++ b/src/public/javascripts/backbone/views.js
@@ -66,7 +66,13 @@ Conductor.Views.PoolsIndex = Backbone.View.extend({
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()))
+
+ var rowsHtml = '';
+ $.each(this.collection.toJSON(), function(index, value) {
+ rowsHtml += Mustache.to_html($template.html(), value);
+ });
+
+ $table.empty().append(rowsHtml);
Conductor.restoreCheckboxes(checkboxes, 'td :checkbox', $table);
$table.find('tr:even').addClass('nostripe');
$table.find('tr:odd').addClass('stripe');
--
1.7.6.5
More information about the aeolus-devel
mailing list