From: Tomas Sedovic <[email protected]>
---
.../admin/hardware_profiles_controller.rb | 37 +++++++++++---------
src/app/controllers/resources/pools_controller.rb | 20 +++++++++--
src/app/models/hardware_profile.rb | 12 ++++++
src/app/models/pool.rb | 4 ++
src/app/views/admin/hardware_profiles/_list.haml | 2 -
src/app/views/layouts/newui.haml | 3 ++
6 files changed, 56 insertions(+), 22 deletions(-)
diff --git a/src/app/controllers/admin/hardware_profiles_controller.rb
b/src/app/controllers/admin/hardware_profiles_controller.rb
index 67c655d..92edab0 100644
--- a/src/app/controllers/admin/hardware_profiles_controller.rb
+++ b/src/app/controllers/admin/hardware_profiles_controller.rb
@@ -1,11 +1,25 @@
class Admin::HardwareProfilesController < ApplicationController
before_filter :require_user
- before_filter :load_hardware_profiles, :only => [:index, :show]
- before_filter :load_hardware_profile, :only => [:show]
+ before_filter :set_params_and_header, :only => [:index, :show]
+ before_filter :load_hardware_profiles, :only => [:show]
+
def index
+ @params = params
+ @search_term = params[:q]
+ if @search_term.blank?
+ load_hardware_profiles
+ return
+ end
+
+ search = HardwareProfile.search do
+ keywords(params[:q])
+ with(:frontend, true)
+ end
+ @hardware_profiles = search.results
end
def show
+ @hardware_profile = HardwareProfile.find((params[:id] || []).first)
@tab_captions = ['Properties', 'History', 'Matching Provider Hardware
Profiles']
@details_tab = params[:details_tab].blank? ? 'properties' :
params[:details_tab]
case @details_tab
@@ -25,15 +39,6 @@ class Admin::HardwareProfilesController <
ApplicationController
end
end
- def new
- end
-
- def create
- end
-
- def delete
- end
-
private
def properties
@properties_header = [
@@ -62,8 +67,7 @@ class Admin::HardwareProfilesController <
ApplicationController
:conditions => {:hardware_profile_map
=> { :aggregator_hardware_profile_id => params[:id] }})
end
- def load_hardware_profiles
- @hardware_profiles = HardwareProfile.all(:conditions => 'provider_id IS
NULL')
+ def set_params_and_header
@url_params = params
@header = [
{ :name => "Hardware Profile Name", :sort_attr => :name },
@@ -74,8 +78,7 @@ class Admin::HardwareProfilesController <
ApplicationController
]
end
- def load_hardware_profile
- @hardware_profile = HardwareProfile.find((params[:id] || []).first)
+ def load_hardware_profiles
+ @hardware_profiles = HardwareProfile.all(:conditions => 'provider_id IS
NULL')
end
-
-end
\ No newline at end of file
+end
diff --git a/src/app/controllers/resources/pools_controller.rb
b/src/app/controllers/resources/pools_controller.rb
index 4e627be..ffd1f55 100644
--- a/src/app/controllers/resources/pools_controller.rb
+++ b/src/app/controllers/resources/pools_controller.rb
@@ -1,8 +1,19 @@
class Resources::PoolsController < ApplicationController
before_filter :require_user
- before_filter :load_pools, :only => [:index, :show]
+ before_filter :set_params_and_header, :only => [:index, :show]
+ before_filter :load_pools, :only => [:show]
def index
+ @search_term = params[:q]
+ if @search_term.blank?
+ load_pools
+ return
+ end
+
+ search = Pool.search() do
+ keywords(params[:q])
+ end
+ @pools = search.results
end
def show
@@ -68,17 +79,20 @@ class Resources::PoolsController < ApplicationController
protected
- def load_pools
+ def set_params_and_header
+ @url_params = params.clone
@header = [
{ :name => "Pool name", :sort_attr => :name },
{ :name => "Quota (Instances)", :sort_attr => "quotas.total_instances"},
{ :name => "% Quota used", :sortable => false },
{ :name => "Pool Family", :sort_attr => "pool_families.name" }
]
+ end
+
+ def load_pools
@pools = Pool.paginate(:all, :include => [ :quota, :pool_family ],
:page => params[:page] || 1,
:order => (params[:order_field] || 'name') +' '+ (params[:order_dir] ||
'asc')
)
- @url_params = params.clone
end
end
diff --git a/src/app/models/hardware_profile.rb
b/src/app/models/hardware_profile.rb
index d7ae995..5e6e9e8 100644
--- a/src/app/models/hardware_profile.rb
+++ b/src/app/models/hardware_profile.rb
@@ -19,7 +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 HardwareProfile < ActiveRecord::Base
+ searchable do
+ text :name, :as => :code_substring
+ text(:architecture) { architecture.try :value }
+ text(:memory) { memory.try :value }
+ text(:storage) { storage.try :value }
+ text(:cpu) { cpu.try :value }
+ boolean :frontend do
+ provider_id.nil?
+ end
+ end
+
has_many :instances
named_scope :frontend, :conditions => { :provider_id => nil }
has_many :provider_instances, :class_name => "Instance",
diff --git a/src/app/models/pool.rb b/src/app/models/pool.rb
index d35f578..550ca79 100644
--- a/src/app/models/pool.rb
+++ b/src/app/models/pool.rb
@@ -19,8 +19,12 @@
# 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 Pool < ActiveRecord::Base
include PermissionedObject
+ searchable do
+ text :name, :as => :code_substring
+ end
has_many :instances, :dependent => :destroy
belongs_to :quota
belongs_to :pool_family
diff --git a/src/app/views/admin/hardware_profiles/_list.haml
b/src/app/views/admin/hardware_profiles/_list.haml
index 7399549..1001db3 100644
--- a/src/app/views/admin/hardware_profiles/_list.haml
+++ b/src/app/views/admin/hardware_profiles/_list.haml
@@ -1,7 +1,5 @@
- form_tag do
#object-actions
- = restful_submit_tag "Create", "create", admin_hardware_profiles_path,
"PUT"
- = restful_submit_tag "Delete", "delete", admin_hardware_profiles_path,
"DELETE"
#selections
%p
diff --git a/src/app/views/layouts/newui.haml b/src/app/views/layouts/newui.haml
index 1ac1073..5be5886 100644
--- a/src/app/views/layouts/newui.haml
+++ b/src/app/views/layouts/newui.haml
@@ -42,6 +42,9 @@
Saved searches
- details = !(yield :details).blank?
#list-view{ :class => details ? 'part' : 'full'}
+ - form_tag({:action => 'index'}, :method => :get) do
+ = text_field_tag :q, @search_term
+ = submit_tag "Search"
= render :partial => '/layouts/notification'
= (yield :list or yield)
#details-view.ui-tabs.ui-widget.ui-widget-content.ui-corner-all{
:class => ('hidden' unless details)}
--
1.7.3.4
_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel