Hi all,
This patch implements #1072 (a child of #459), showing all Instances in a Pool.
A few notes:
- The mockups show Assembly and Deployment in the table as being links. I added conditional support for making them links when an instance has an assembly or deployable, though currently none do. The links go to the ostensibly-correct place, but neither seems to be implemented yet. (For example, Assemblies#show doesn't even exist yet.) These should come into existence in the coming days, though.
- I did not use a sortable_table_header, even though they'd have been nice. Pools already use sortable_table_header, so we ended up with two on the page. Sorting did not work properly and sometimes threw exceptions, depending on what you sorted. Additionally, the wrong tab is loaded after a sort because the sort goes back to 'show'. I started to try to make it work, but it turned into a great time sink for what I think is a comparatively unimportant feature. This problem also exists in other places, such as "Matching Provider Hardware Profiles," so I think we should try to find a better solution as part of revamping the UI.
-- Matt
--- src/app/controllers/resources/pools_controller.rb | 9 ++++++ src/app/views/resources/pools/_instances.haml | 31 +++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/src/app/controllers/resources/pools_controller.rb b/src/app/controllers/resources/pools_controller.rb index cd4840a..efddfad 100644 --- a/src/app/controllers/resources/pools_controller.rb +++ b/src/app/controllers/resources/pools_controller.rb @@ -20,6 +20,7 @@ class Resources::PoolsController < ApplicationController @pool = Pool.find(params[:id]) require_privilege(Privilege::VIEW, @pool) @url_params = params.clone + load_instances @tab_captions = ['Properties', 'Deployments', 'Instances', 'History', 'Permissions'] @details_tab = params[:details_tab].blank? ? 'properties' : params[:details_tab] respond_to do |format| @@ -112,4 +113,12 @@ class Resources::PoolsController < ApplicationController :order => (params[:order_field] || 'name') +' '+ (params[:order_dir] || 'asc') ) end + + def load_instances + # If state isn't specified at all, show only running instances. + # (But if it's nil, we want to show all instances) + params[:state] = 'running' unless params.keys.include?('state') + conditions = params[:state].present? ? ['state=?', params[:state]] : '' + @instances = @pool.instances.find(:all, :conditions => conditions) + end end diff --git a/src/app/views/resources/pools/_instances.haml b/src/app/views/resources/pools/_instances.haml index 3498757..260a9f8 100644 --- a/src/app/views/resources/pools/_instances.haml +++ b/src/app/views/resources/pools/_instances.haml @@ -1,3 +1,28 @@ -%h3 - Instances for - = @pool.name +- form_tag do + = restful_submit_tag 'Stop', 'stop', multi_stop_resources_instances_path, 'GET' + Show only + = hidden_field_tag 'details_tab', 'instances' + = select '', 'state', Instance::STATES, { :include_blank => true, :selected => params[:state] } + instances + = restful_submit_tag "Filter", 'show', resources_pool_path, 'GET', :id => 'filter_button' + + %table + %thead + %td Name + %td Assembly + %td Deployment + %td Since + %td State + - @instances.each do |instance| + %tr + %td + %input{:name => 'instance_selected[]', :type => 'checkbox', :value => instance.id, :id => "instance_checkbox_#{instance.id}" } + = link_to instance.name, resources_instance_path(instance) + %td + = instance.assembly.present? ? link_to((instance.assembly.name), image_factory_assembly_path(instance.assembly)) : '—' + %td + = instance.deployment.present? ? link_to((instance.deployment.name), resources_deployment_path(instance.deployment)) : '—' + %td + = instance.created_at.to_s + %td + = instance.state \ No newline at end of file
All tests passed, did e2e, everything works as expected. ACK
Jirka
Dne 15.4.2011 20:54, Matt Wagner napsal(a):
src/app/controllers/resources/pools_controller.rb | 9 ++++++ src/app/views/resources/pools/_instances.haml | 31 +++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/src/app/controllers/resources/pools_controller.rb b/src/app/controllers/resources/pools_controller.rb index cd4840a..efddfad 100644 --- a/src/app/controllers/resources/pools_controller.rb +++ b/src/app/controllers/resources/pools_controller.rb @@ -20,6 +20,7 @@ class Resources::PoolsController< ApplicationController @pool = Pool.find(params[:id]) require_privilege(Privilege::VIEW, @pool) @url_params = params.clone
- load_instances @tab_captions = ['Properties', 'Deployments', 'Instances', 'History', 'Permissions'] @details_tab = params[:details_tab].blank? ? 'properties' : params[:details_tab] respond_to do |format|
@@ -112,4 +113,12 @@ class Resources::PoolsController< ApplicationController :order => (params[:order_field] || 'name') +' '+ (params[:order_dir] || 'asc') ) end
- def load_instances
- # If state isn't specified at all, show only running instances.
- # (But if it's nil, we want to show all instances)
- params[:state] = 'running' unless params.keys.include?('state')
- conditions = params[:state].present? ? ['state=?', params[:state]] : ''
- @instances = @pool.instances.find(:all, :conditions => conditions)
- end end
diff --git a/src/app/views/resources/pools/_instances.haml b/src/app/views/resources/pools/_instances.haml index 3498757..260a9f8 100644 --- a/src/app/views/resources/pools/_instances.haml +++ b/src/app/views/resources/pools/_instances.haml @@ -1,3 +1,28 @@ -%h3
- Instances for
- = @pool.name
+- form_tag do
- = restful_submit_tag 'Stop', 'stop', multi_stop_resources_instances_path, 'GET'
- Show only
- = hidden_field_tag 'details_tab', 'instances'
- = select '', 'state', Instance::STATES, { :include_blank => true, :selected => params[:state] }
- instances
- = restful_submit_tag "Filter", 'show', resources_pool_path, 'GET', :id => 'filter_button'
- %table
- %thead
%td Name
%td Assembly
%td Deployment
%td Since
%td State
- @instances.each do |instance|
%tr
%td
%input{:name => 'instance_selected[]', :type => 'checkbox', :value => instance.id, :id => "instance_checkbox_#{instance.id}" }
= link_to instance.name, resources_instance_path(instance)
%td
= instance.assembly.present? ? link_to((instance.assembly.name), image_factory_assembly_path(instance.assembly)) : '—'
%td
= instance.deployment.present? ? link_to((instance.deployment.name), resources_deployment_path(instance.deployment)) : '—'
%td
= instance.created_at.to_s
%td
= instance.state
\ No newline at end of file
aeolus-devel@lists.fedorahosted.org