From: Jan Provaznik <[email protected]>
This patch creates index view and controller placeholders for instances.
---
.../controllers/resources/instances_controller.rb | 28 +++++++++++++++++
src/app/helpers/resources/instances_helper.rb | 33 ++++++++++++++++++++
src/app/views/resources/instances/_list.haml | 23 ++++++++++++++
src/app/views/resources/instances/index.haml | 3 +-
src/config/routes.rb | 3 +-
5 files changed, 88 insertions(+), 2 deletions(-)
create mode 100644 src/app/helpers/resources/instances_helper.rb
create mode 100644 src/app/views/resources/instances/_list.haml
diff --git a/src/app/controllers/resources/instances_controller.rb
b/src/app/controllers/resources/instances_controller.rb
index 2746d12..bb08c69 100644
--- a/src/app/controllers/resources/instances_controller.rb
+++ b/src/app/controllers/resources/instances_controller.rb
@@ -1,6 +1,34 @@
class Resources::InstancesController < ApplicationController
before_filter :require_user
+ def new
+ end
+
+ def edit
+ end
+
+ def start
+ end
+
+ def stop
+ end
+
def index
+ @header = [
+ {:name => 'VM NAME', :sort_attr => 'name'},
+ {:name => 'STATUS', :sortable => false},
+ {:name => 'TEMPLATE', :sort_attr => 'templates.name'},
+ {:name => 'PUBLIC ADDRESS', :sort_attr => 'public_addresses'},
+ {:name => 'PROVIDER', :sortable => false},
+ {:name => 'CREATED BY', :sort_attr => 'users.last_name'},
+ {:name => '', :sortable => false},
+ ]
+
+ pools = Pool.list_for_user(@current_user, Privilege::INSTANCE_MODIFY)
+ @instances = Instance.all(
+ :include => [:template, :owner],
+ :conditions => {:pool_id => pools},
+ :order => (params[:order_field] || 'name') +' '+ (params[:order_dir] ||
'asc')
+ )
end
end
diff --git a/src/app/helpers/resources/instances_helper.rb
b/src/app/helpers/resources/instances_helper.rb
new file mode 100644
index 0000000..91474ad
--- /dev/null
+++ b/src/app/helpers/resources/instances_helper.rb
@@ -0,0 +1,33 @@
+#
+# Copyright (C) 2009 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+# Filters added to this controller apply to all controllers in the application.
+# Likewise, all the methods added will be available for all controllers.
+
+module Resources::InstancesHelper
+ def owner_name(inst)
+ return '' unless inst.owner
+ # if last_name is set, use full name,
+ # else use login
+ if inst.owner.last_name.blank?
+ inst.owner.login
+ else
+ "#{inst.owner.first_name} #{inst.owner.last_name}"
+ end
+ end
+end
diff --git a/src/app/views/resources/instances/_list.haml
b/src/app/views/resources/instances/_list.haml
new file mode 100644
index 0000000..b49b99d
--- /dev/null
+++ b/src/app/views/resources/instances/_list.haml
@@ -0,0 +1,23 @@
+- form_tag do
+ = restful_submit_tag 'Start', 'start', start_resources_instances_path, 'GET'
+ = restful_submit_tag 'Stop', 'start', stop_resources_instances_path, 'GET'
+ = restful_submit_tag 'Create', 'new', new_resources_instance_path, 'GET'
+
+ %p
+ Select:
+ = link_to "All", params.merge(:select => 'all')
+ %span> ,
+ = link_to "None", params.merge(:select => 'none')
+ %table
+ = sortable_table_header @header
+ - @instances.each do |inst|
+ %tr
+ %td
+ - selected = params[:select] == 'all'
+ %input{:checked => selected, :name => 'ids', :type => 'checkbox',
:value => inst.id, :id => "inst_ids_#{inst.id}" }
+ = link_to inst.name, resources_instance_path(inst)
+ %td= inst.template.name
+ %td= inst.public_addresses
+ %td= inst.cloud_account ? inst.cloud_account.provider.name : ''
+ %td= owner_name(inst)
+ %td= link_to 'edit', edit_resources_instance_path(inst)
diff --git a/src/app/views/resources/instances/index.haml
b/src/app/views/resources/instances/index.haml
index 0354016..62ccbc6 100644
--- a/src/app/views/resources/instances/index.haml
+++ b/src/app/views/resources/instances/index.haml
@@ -1 +1,2 @@
-resources/instances/index.haml
+- content_for :list do
+ = render :partial => 'list'
diff --git a/src/config/routes.rb b/src/config/routes.rb
index 5dd6560..699ee25 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -33,7 +33,8 @@ ActionController::Routing::Routes.draw do |map|
# -- just remember to delete public/index.html.
map.namespace 'resources' do |r|
- r.resources :pools, :instances, :deployments
+ r.resources :pools, :deployments
+ r.resources :instances, :collection => {:start => :get, :stop => :get}
end
map.namespace 'image_factory' do |r|
--
1.7.2.3
_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel