activeadmin-mongoidv3 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,11 +4,12 @@ module ActiveAdmin
|
|
4
4
|
class Search
|
5
5
|
attr_reader :base, :query, :query_hash, :search_params
|
6
6
|
|
7
|
-
def initialize(object, search_params = {})
|
7
|
+
def initialize(object, search_params = {}, per_page = 30, page = 1)
|
8
8
|
@base = object
|
9
9
|
@search_params = search_params
|
10
10
|
@query_hash = get_query_hash(search_params)
|
11
|
-
|
11
|
+
vpage = page.to_i > 0 ? page.to_i : 1
|
12
|
+
@query = @base.where(@query_hash).limit(per_page).skip(per_page * (vpage - 1))
|
12
13
|
end
|
13
14
|
|
14
15
|
def respond_to?(method_id)
|
@@ -26,7 +27,7 @@ module ActiveAdmin
|
|
26
27
|
private
|
27
28
|
|
28
29
|
def is_query(method_id)
|
29
|
-
method_id.to_s =~ /_(contains|eq|gt|lt|gte|lte)$/
|
30
|
+
method_id.to_s =~ /_(contains|eq|in|gt|lt|gte|lte)$/
|
30
31
|
end
|
31
32
|
|
32
33
|
def get_query_hash(search_params)
|
@@ -42,6 +43,8 @@ module ActiveAdmin
|
|
42
43
|
[get_attribute(k, '_contains'), Regexp.new(Regexp.escape("#{v}"), Regexp::IGNORECASE)]
|
43
44
|
when /_eq$/
|
44
45
|
[get_attribute(k, '_eq'), v]
|
46
|
+
when /_in$/
|
47
|
+
[get_attribute(k, '_in').to_sym.in, v]
|
45
48
|
when /_gt$/
|
46
49
|
[get_attribute(k, "_gt").to_sym.gt, v]
|
47
50
|
when /_lt$/
|
@@ -4,7 +4,7 @@ class ActiveAdmin::FilterFormBuilder
|
|
4
4
|
case column.type.name.downcase.to_sym
|
5
5
|
when :date, :datetime, :time
|
6
6
|
return :date_range
|
7
|
-
when :string, :text
|
7
|
+
when :string, :text, :object
|
8
8
|
return :string
|
9
9
|
when :integer
|
10
10
|
return :select if reflection_for(method.to_s.gsub('_id','').to_sym)
|
@@ -6,10 +6,17 @@ class ActiveAdmin::Resource
|
|
6
6
|
def resource_table_name
|
7
7
|
resource_class.collection_name
|
8
8
|
end
|
9
|
+
|
10
|
+
def mongoid_per_page
|
11
|
+
per_page
|
12
|
+
end
|
9
13
|
end
|
10
14
|
|
11
15
|
ActiveAdmin::ResourceController # autoload
|
12
16
|
class ActiveAdmin::ResourceController
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
13
20
|
# Use #desc and #asc for sorting.
|
14
21
|
def sort_order(chain)
|
15
22
|
params[:order] ||= active_admin_config.sort_order
|
@@ -22,7 +29,6 @@ class ActiveAdmin::ResourceController
|
|
22
29
|
end
|
23
30
|
|
24
31
|
def search(chain)
|
25
|
-
@search = ActiveAdmin::Mongoid::Adaptor::Search.new(chain, clean_search_params(params[:q]))
|
32
|
+
@search = ActiveAdmin::Mongoid::Adaptor::Search.new(chain, clean_search_params(params[:q]), active_admin_config.mongoid_per_page, params[:page])
|
26
33
|
end
|
27
|
-
|
28
34
|
end
|