Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #51 from elia/sorting

Add sorting
  • Loading branch information...
commit aa057b549903456065ec46a2e62d097730191c04 2 parents fffdcfb + 0ab0890
@elia authored
View
24 lib/active_admin/mongoid/document.rb
@@ -5,14 +5,6 @@ module ActiveAdmin::Mongoid::Document
extend ActiveSupport::Concern
- # INSTANCE METHODS
-
- # Returns the column object for the named attribute.
- def column_for_attribute(name)
- self.class.columns_hash[name.to_s]
- end
-
-
# PROXY CLASSES
@@ -45,6 +37,8 @@ def quote_column_name name
# CLASS METHODS
included do
+ include MetaSearch::Searches::Mongoid
+
unless respond_to? :primary_key
class << self
attr_accessor :primary_key
@@ -60,11 +54,11 @@ module ClassMethods
# Metasearch
def joins_values *args
- scoped
+ criteria
end
- def group_by *args
- scoped
+ def group_by *args, &block
+ criteria
end
def ransack *args
@@ -119,8 +113,12 @@ def columns_hash
- def reorder *args
- scoped
+ def reorder sorting
+ return unscoped if sorting.blank?
+ options = sorting.split(/ |\./)
+ options.shift if options.count == 3
+ field, order = *options
+ unscoped.order_by(field => order)
end
def connection
View
19 lib/meta_search/searches/mongoid.rb
@@ -22,17 +22,17 @@ def build
when :does_not_equal, :ne, :not_eq
@relation = relation.where(field.to_sym.ne => value)
when :contains, :like, :matches
- @relation = relation.where(field => /#{value}/)
+ @relation = relation.where(field => /#{value}/i)
when :does_not_contain, :nlike, :not_matches
- @relation = relation.where(field.to_sym.not => /#{value}/)
+ @relation = relation.where(field.to_sym.not => /#{value}/i)
when :starts_with, :sw
- @relation = relation.where(field.to_sym => /\A#{Regexp.quote(value)}/)
+ @relation = relation.where(field.to_sym => /\A#{Regexp.quote(value)}/i)
when :does_not_start_with, :dnsw
- @relation = relation.where(field.to_sym.not => /\A#{Regexp.quote(value)}/)
+ @relation = relation.where(field.to_sym.not => /\A#{Regexp.quote(value)}/i)
when :ends_with, :ew
- @relation = relation.where(field.to_sym => /#{Regexp.quote(value)}\z/)
+ @relation = relation.where(field.to_sym => /#{Regexp.quote(value)}\z/i)
when :does_not_end_with, :dnew
- @relation = relation.where(field.to_sym.not => /#{Regexp.quote(value)}\z/)
+ @relation = relation.where(field.to_sym.not => /#{Regexp.quote(value)}\z/i)
when :greater_than, :gt
@relation = relation.where(field.to_sym.gt => value)
when :less_than, :lt
@@ -92,9 +92,7 @@ def method_missing name, *args, &block
end
def metasearch_regexp
- # field_names = klass.content_columns.map(&:name)
field_names = klass.fields.map(&:second).map(&:name)
-
conditions = MetaSearch::DEFAULT_WHERES.map {|condition| condition[0...-1]} # pop tail options
/\A(#{field_names.join('|')})_(#{conditions.join('|')})\z/
@@ -109,10 +107,7 @@ module ClassMethods
def metasearch(params = nil, options = nil)
options ||= {}
params ||= {}
- MongoidSearchBuilder.new(self, params, options).build
- # @metasearch_query
- # raise [params, options].inspect unless [options, params].all?(&:empty?)
- # scoped
+ MongoidSearchBuilder.new(criteria, params, options).build
end
alias_method :search, :metasearch unless respond_to?(:search)
end
Please sign in to comment.
Something went wrong with that request. Please try again.