From: Imre Farkas ifarkas@redhat.com
--- src/app/controllers/pools_controller.rb | 2 +- src/app/helpers/mustache_helper.rb | 6 +++ .../views/instances/_instance_row.html.mustache | 17 ++++++++++ src/app/views/instances/_list.html.haml | 34 +++++-------------- src/public/javascripts/backbone/views.js | 2 +- 5 files changed, 34 insertions(+), 27 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 4a3a9d8..ae00567 100644 --- a/src/app/controllers/pools_controller.rb +++ b/src/app/controllers/pools_controller.rb @@ -80,7 +80,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 b13ef67..16464f1 100644 --- a/src/app/helpers/mustache_helper.rb +++ b/src/app/helpers/mustache_helper.rb @@ -27,11 +27,17 @@ module MustacheHelper :name => instance.name, :path => instance_path(instance), :uptime => count_uptime(instance.uptime), + :failed => instance.failed?, :translated_state => t("instances.states.#{instance.state}"), :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), + :owner => instance.owner.present? ? instance.owner.name : nil, + + :provider => { + :name => instance.provider_account.present? ? instance.provider_account.provider.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..8d9dd17 --- /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}}', false, :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>{{translated_state}}</td> + <td>{{provider.name}}</td> + <td>{{owner}}</td> +</tr> diff --git a/src/app/views/instances/_list.html.haml b/src/app/views/instances/_list.html.haml index dac5d69..b551c43 100644 --- a/src/app/views/instances/_list.html.haml +++ b/src/app/views/instances/_list.html.haml @@ -29,34 +29,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= t("instances.states.#{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', :page => params[:page])}', '#{url_for(:action => :show, :details_tab => 'instances', :view => 'pretty', :page => params[:page])}');
-%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>${translated_state}</td> - <td>${provider}</td> - <td>${owner}</td> - </tr> +:javascript + $(document).ready(function(){ + $('tr:odd').addClass('stripe'); + $('tr:even').addClass('nostripe'); + }); + +%script#instanceRowTemplate{ :type => 'text/html' } + = render :partial => 'instances/instance_row' diff --git a/src/public/javascripts/backbone/views.js b/src/public/javascripts/backbone/views.js index 4535ac5..055202a 100644 --- a/src/public/javascripts/backbone/views.js +++ b/src/public/javascripts/backbone/views.js @@ -33,7 +33,7 @@ Conductor.Views.PoolsIndex = Backbone.View.extend({ switch(this.currentTab()) { case 'pools': return $('#poolRowTemplate'); case 'deployments': return $('#deploymentRowTemplate'); - case 'instances': return $('#instanceTemplate'); + case 'instances': return $('#instanceRowTemplate'); } } else if (this.currentView() == 'pretty') {