Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add searching to Refinery Settings

  • Loading branch information...
commit b37d039fe52cc966e5d1bc57ae1e0a67c2692518 1 parent fc840af
Matt authored September 16, 2010
37  vendor/refinerycms/settings/app/controllers/admin/refinery_settings_controller.rb
@@ -9,6 +9,12 @@ class Admin::RefinerySettingsController < Admin::BaseController
9 9
   before_filter :sanitise_params, :only => [:create, :update]
10 10
   after_filter :fire_setting_callback, :only => [:update]
11 11
 
  12
+  def index
  13
+    search_all_refinery_settings if searching?
  14
+
  15
+    paginate_all_refinery_settings
  16
+  end
  17
+
12 18
   def edit
13 19
     @refinery_setting = RefinerySetting.find(params[:id])
14 20
 
@@ -16,19 +22,30 @@ def edit
16 22
   end
17 23
 
18 24
   def find_all_refinery_settings
19  
-    @refinery_settings = RefinerySetting.find(:all,
20  
-    {
21  
-      :order => "name ASC",
22  
-      :conditions => (["restricted <> ?", true] unless current_user.has_role?(:superuser))
23  
-    })
  25
+    @refinery_settings = RefinerySetting.order('name ASC')
  26
+
  27
+    unless current_user.has_role?(:superuser)
  28
+      @refinery_settings = @refinery_settings.where("restricted <> ? ", true)
  29
+    end
  30
+
  31
+    @refinery_settings
  32
+  end
  33
+
  34
+  def search_all_refinery_settings
  35
+    # search for settings that begin with keyword
  36
+    term = "^" + params[:search].to_s.downcase.gsub(' ', '_')
  37
+
  38
+    # First find normal results.
  39
+    find_all_refinery_settings
  40
+
  41
+    # Now get weighted results by running the query against the results already found.
  42
+    @refinery_settings = @refinery_settings.with_query(term)
24 43
   end
25 44
 
26 45
   def paginate_all_refinery_settings
27  
-    @refinery_settings = RefinerySetting.paginate({
28  
-      :page => params[:page],
29  
-      :order => "name ASC",
30  
-      :conditions => (["restricted <> ?", true] unless current_user.has_role?(:superuser))
31  
-    })
  46
+    find_all_refinery_settings if @refinery_settings.nil?
  47
+
  48
+    @refinery_settings = @refinery_settings.paginate(:page => params[:page], :per_page => RefinerySetting.per_page)
32 49
   end
33 50
 
34 51
 private
3  vendor/refinerycms/settings/app/models/refinery_setting.rb
@@ -5,6 +5,9 @@ class RefinerySetting < ActiveRecord::Base
5 5
   serialize :value # stores into YAML format
6 6
   serialize :callback_proc_as_string
7 7
 
  8
+  # Docs for acts_as_indexed http://github.com/dougal/acts_as_indexed
  9
+  acts_as_indexed :fields => [:name]
  10
+
8 11
   before_save do |setting|
9 12
     setting.restricted = false if setting.restricted.nil?
10 13
   end
6  vendor/refinerycms/settings/app/views/admin/refinery_settings/index.html.erb
... ...
@@ -1,6 +1,12 @@
1 1
 <div id='actions'>
2 2
   <ul>
3 3
     <li>
  4
+      <%= render :partial => "/shared/admin/search",
  5
+                 :locals => {
  6
+                   :url => admin_refinery_settings_url
  7
+                 } %>
  8
+    </li>
  9
+    <li>
4 10
       <%= link_to t('.new'), new_admin_refinery_setting_url(:dialog => true, :width => 725, :height => 475), :class => "add_icon" %>
5 11
     </li>
6 12
   </ul>

0 notes on commit b37d039

Please sign in to comment.
Something went wrong with that request. Please try again.