From: Tomas Sedovic <[email protected]>
---
.../admin/hardware_profiles_controller.rb | 13 +++++++++++--
src/app/controllers/resources/pools_controller.rb | 10 +++++++++-
src/app/models/hardware_profile.rb | 20 ++++++++++++++++++++
src/app/models/pool.rb | 4 ++++
src/app/views/admin/hardware_profiles/_list.haml | 2 +-
src/app/views/layouts/newui.haml | 3 +++
src/app/views/resources/pools/_list.haml | 2 +-
7 files changed, 49 insertions(+), 5 deletions(-)
diff --git a/src/app/controllers/admin/hardware_profiles_controller.rb
b/src/app/controllers/admin/hardware_profiles_controller.rb
index 67c655d..8a04681 100644
--- a/src/app/controllers/admin/hardware_profiles_controller.rb
+++ b/src/app/controllers/admin/hardware_profiles_controller.rb
@@ -1,6 +1,6 @@
class Admin::HardwareProfilesController < ApplicationController
before_filter :require_user
- before_filter :load_hardware_profiles, :only => [:index, :show]
+ before_filter :load_hardware_profiles, :only => [:index, :show, :search]
before_filter :load_hardware_profile, :only => [:show]
def index
end
@@ -34,6 +34,15 @@ class Admin::HardwareProfilesController <
ApplicationController
def delete
end
+ def search
+ @search_term = params[:q]
+ @search = HardwareProfile.search() do
+ keywords(params[:q])
+ with(:frontend, true)
+ end
+ render 'index'
+ end
+
private
def properties
@properties_header = [
@@ -78,4 +87,4 @@ class Admin::HardwareProfilesController <
ApplicationController
@hardware_profile = HardwareProfile.find((params[:id] || []).first)
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..1abe057 100644
--- a/src/app/controllers/resources/pools_controller.rb
+++ b/src/app/controllers/resources/pools_controller.rb
@@ -1,10 +1,18 @@
class Resources::PoolsController < ApplicationController
before_filter :require_user
- before_filter :load_pools, :only => [:index, :show]
+ before_filter :load_pools, :only => [:index, :show, :search]
def index
end
+ def search
+ @search_term = params[:q]
+ @search = Pool.search() do
+ keywords(params[:q])
+ end
+ render 'index'
+ end
+
def show
@pool = Pool.find(params[:id])
@url_params = params.clone
diff --git a/src/app/models/hardware_profile.rb
b/src/app/models/hardware_profile.rb
index d7ae995..323ed39 100644
--- a/src/app/models/hardware_profile.rb
+++ b/src/app/models/hardware_profile.rb
@@ -19,7 +19,27 @@
# 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 do
+ architecture.value if architecture
+ end
+ text :memory do
+ memory.value if memory
+ end
+ text :storage do
+ storage.value if storage
+ end
+ text :cpu do
+ cpu.value if cpu
+ end
+ 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..c31d906 100644
--- a/src/app/views/admin/hardware_profiles/_list.haml
+++ b/src/app/views/admin/hardware_profiles/_list.haml
@@ -12,7 +12,7 @@
%table
= sortable_table_header @header
- - @hardware_profiles.each do |hwp|
+ - (@search ? @search.results : @hardware_profiles).each do |hwp|
%tr
%td
- selected = @url_params[:select] == 'all'
diff --git a/src/app/views/layouts/newui.haml b/src/app/views/layouts/newui.haml
index 1ac1073..321cc6c 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 => 'search'}, :method => :post) 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)}
diff --git a/src/app/views/resources/pools/_list.haml
b/src/app/views/resources/pools/_list.haml
index 558ff19..5d52021 100644
--- a/src/app/views/resources/pools/_list.haml
+++ b/src/app/views/resources/pools/_list.haml
@@ -8,7 +8,7 @@
= link_to "None", @url_params.merge(:select => 'none')
%table#pools_table
= sortable_table_header @header
- - @pools.each do |pool|
+ - (@search ? @search.results : @pools).each do |pool|
%tr
%td
- selected = @url_params[:select] == 'all'
--
1.7.3.4
_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel