From: Martyn Taylor <mtaylor(a)redhat.com>
---
.../controllers/resources/instances_controller.rb | 34 ++++++++++++++------
src/app/models/instance.rb | 9 +++++
2 files changed, 33 insertions(+), 10 deletions(-)
diff --git a/src/app/controllers/resources/instances_controller.rb
b/src/app/controllers/resources/instances_controller.rb
index 3bd0c45..1bbe878 100644
--- a/src/app/controllers/resources/instances_controller.rb
+++ b/src/app/controllers/resources/instances_controller.rb
@@ -1,7 +1,21 @@
class Resources::InstancesController < ApplicationController
before_filter :require_user
before_filter :load_instance, :only => [:show, :remove_failed, :key, :stop]
- before_filter :load_instances, :only => [:show, :index]
+ before_filter :set_view_vars, :only => [:show, :index]
+
+ def index
+ @params = params
+ @search_term = params[:q]
+ if @search_term.blank?
+ load_instances
+ return
+ end
+
+ search = Instance.search do
+ keywords(params[:q])
+ end
+ @instances = search.results
+ end
def new
@instance = Instance.new(params[:instance])
@@ -64,6 +78,7 @@ class Resources::InstancesController < ApplicationController
end
def show
+ load_instances
@url_params = params.clone
@tab_captions = ['Properties', 'History', 'Permissions']
@details_tab = params[:details_tab].blank? ? 'properties' :
params[:details_tab]
@@ -78,9 +93,6 @@ class Resources::InstancesController < ApplicationController
end
end
- def index
- end
-
def key
unless @instance.instance_key.nil?
send_data @instance.instance_key.pem,
@@ -135,7 +147,7 @@ class Resources::InstancesController < ApplicationController
)
end
- def load_instances
+ def set_view_vars
@header = [
{:name => 'VM NAME', :sort_attr => 'name'},
{:name => 'STATUS', :sortable => false},
@@ -145,11 +157,13 @@ class Resources::InstancesController < ApplicationController
{:name => 'CREATED BY', :sort_attr => 'users.last_name'},
]
- 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')
+ @pools = Pool.list_for_user(@current_user, Privilege::INSTANCE_MODIFY)
+ end
+
+ def load_instances
+ @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/models/instance.rb b/src/app/models/instance.rb
index e7757e3..8fa00d1 100644
--- a/src/app/models/instance.rb
+++ b/src/app/models/instance.rb
@@ -19,10 +19,19 @@
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
+require 'sunspot_rails'
class Instance < ActiveRecord::Base
include SearchFilter
include PermissionedObject
+ searchable do
+ text :name, :as => :code_substring
+ text :external_key, :as => :code_substring
+ text :public_addresses, :as => :code_substring
+ text :private_addresses, :as => :code_substring
+ text :state, :as => :code_substring
+ end
+
cattr_reader :per_page
@@per_page = 15
--
1.7.2.3
_______________________________________________
aeolus-devel mailing list
aeolus-devel(a)lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/aeolus-devel