activeadmin-mongoid 0.0.2.jpmckinney.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -4
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +27 -1
- data/README.md +0 -5
- data/Rakefile +6 -1
- data/activeadmin-mongoid.gemspec +8 -4
- data/lib/active_admin/mongoid.rb +26 -17
- data/lib/active_admin/mongoid/adaptor.rb +65 -0
- data/lib/active_admin/mongoid/comments.rb +12 -5
- data/lib/active_admin/mongoid/criteria.rb +10 -0
- data/lib/active_admin/mongoid/document.rb +43 -2
- data/lib/active_admin/mongoid/filter_form_builder.rb +31 -0
- data/lib/active_admin/mongoid/generators/install.rb +7 -0
- data/lib/active_admin/mongoid/helpers/collection.rb +10 -0
- data/lib/active_admin/mongoid/resource.rb +51 -33
- data/lib/active_admin/mongoid/version.rb +1 -1
- data/lib/tasks/activeadmin-mongoid_tasks.rake +4 -0
- data/spec/features/smoke_spec.rb +60 -0
- data/spec/spec_helper.rb +42 -0
- data/spec/support/capybara.rb +1 -0
- data/tasks/js.rake +32 -0
- data/tasks/test.rake +75 -0
- data/test_app/.gitignore +15 -0
- data/test_app/.rspec +1 -0
- data/test_app/README.rdoc +261 -0
- data/test_app/Rakefile +7 -0
- data/test_app/app/admin/admin_users.rb +20 -0
- data/test_app/app/admin/dashboard.rb +33 -0
- data/test_app/app/admin/posts.rb +3 -0
- data/test_app/app/assets/images/rails.png +0 -0
- data/test_app/app/assets/javascripts/active_admin.js +1 -0
- data/test_app/app/assets/javascripts/application.js +15 -0
- data/test_app/app/assets/stylesheets/active_admin.css.scss +29 -0
- data/test_app/app/assets/stylesheets/application.css +13 -0
- data/test_app/app/controllers/application_controller.rb +3 -0
- data/test_app/app/helpers/application_helper.rb +2 -0
- data/test_app/app/mailers/.gitkeep +0 -0
- data/test_app/app/models/.gitkeep +0 -0
- data/test_app/app/models/admin_user.rb +40 -0
- data/test_app/app/models/post.rb +6 -0
- data/test_app/app/views/layouts/application.html.erb +14 -0
- data/test_app/config.ru +4 -0
- data/test_app/config/_link_mongoid_config.rb +7 -0
- data/test_app/config/application.rb +70 -0
- data/test_app/config/boot.rb +6 -0
- data/test_app/config/database.yml +25 -0
- data/test_app/config/environment.rb +5 -0
- data/test_app/config/environments/development.rb +31 -0
- data/test_app/config/environments/production.rb +64 -0
- data/test_app/config/environments/test.rb +35 -0
- data/test_app/config/initializers/active_admin.rb +210 -0
- data/test_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test_app/config/initializers/devise.rb +246 -0
- data/test_app/config/initializers/inflections.rb +15 -0
- data/test_app/config/initializers/mime_types.rb +5 -0
- data/test_app/config/initializers/secret_token.rb +7 -0
- data/test_app/config/initializers/session_store.rb +8 -0
- data/test_app/config/initializers/wrap_parameters.rb +10 -0
- data/test_app/config/locales/devise.en.yml +59 -0
- data/test_app/config/locales/en.yml +5 -0
- data/test_app/config/mongoid.2.yml +20 -0
- data/test_app/config/mongoid.3.yml +96 -0
- data/test_app/config/routes.rb +4 -0
- data/test_app/db/migrate/20130514223107_create_admin_notes.rb +17 -0
- data/test_app/db/migrate/20130514223108_move_admin_notes_to_comments.rb +26 -0
- data/test_app/db/seeds.rb +7 -0
- data/test_app/lib/assets/.gitkeep +0 -0
- data/test_app/lib/tasks/.gitkeep +0 -0
- data/test_app/log/.gitkeep +0 -0
- data/test_app/public/404.html +26 -0
- data/test_app/public/422.html +26 -0
- data/test_app/public/500.html +25 -0
- data/test_app/public/favicon.ico +0 -0
- data/test_app/public/index.html +241 -0
- data/test_app/public/robots.txt +5 -0
- data/test_app/script/rails +6 -0
- data/test_app/spec/models/admin_user_spec.rb +5 -0
- data/test_app/test/fixtures/.gitkeep +0 -0
- data/test_app/test/functional/.gitkeep +0 -0
- data/test_app/test/integration/.gitkeep +0 -0
- data/test_app/test/performance/browsing_test.rb +12 -0
- data/test_app/test/test_helper.rb +7 -0
- data/test_app/test/unit/.gitkeep +0 -0
- data/test_app/vendor/assets/javascripts/.gitkeep +0 -0
- data/test_app/vendor/assets/stylesheets/.gitkeep +0 -0
- data/test_app/vendor/plugins/.gitkeep +0 -0
- metadata +136 -29
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2f4ee2f7bcc78891d91481ee20bdaa7ab082fba8
|
4
|
+
data.tar.gz: eb4fdbb0600638727f75187488434b6377ef44a1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 15256821b3a1a2ce7fde50128a55690b4f1e004772ba0a0b273cd77c70f3fd54a9f789934b9825f36f6bbb0fe6441c1f77c672f04b82894baf73cb3ee3c0e3e5
|
7
|
+
data.tar.gz: 500cf07724202dd9f078334c893d7788ff0540a2771580e9fa52edf726ac9d8b4be848012e0446820cdc8033f08039e4a8e6bc1b339ff2f49d3e4e202ec97565
|
data/.gitignore
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
*.gem
|
2
2
|
*.rbc
|
3
|
-
.bundle
|
4
3
|
.config
|
5
4
|
.yardoc
|
6
5
|
Gemfile.lock
|
@@ -12,6 +11,14 @@ lib/bundler/man
|
|
12
11
|
pkg
|
13
12
|
rdoc
|
14
13
|
spec/reports
|
15
|
-
|
16
|
-
|
17
|
-
tmp
|
14
|
+
/spec/tmp
|
15
|
+
/spec/version_tmp
|
16
|
+
/tmp
|
17
|
+
/.bundle
|
18
|
+
/log/*.log
|
19
|
+
/test_app/db/*.sqlite3
|
20
|
+
/test_app/log/*.log
|
21
|
+
/test_app/tmp/
|
22
|
+
/test_app/.sass-cache
|
23
|
+
/test_app/config/mongoid.yml
|
24
|
+
/spec/rails
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -1,4 +1,30 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
#
|
3
|
+
# Declare your gem's dependencies in activeadmin-mongoid.gemspec.
|
4
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
5
|
+
# development dependencies will be added by default to the :development group.
|
4
6
|
gemspec
|
7
|
+
|
8
|
+
|
9
|
+
# Test app stuff
|
10
|
+
|
11
|
+
gem 'rails', '~> 3.2.6'
|
12
|
+
|
13
|
+
# Gems used only for assets and not required
|
14
|
+
# in production environments by default.
|
15
|
+
group :assets do
|
16
|
+
gem 'sass-rails', '~> 3.2.3'
|
17
|
+
gem 'coffee-rails', '~> 3.2.1'
|
18
|
+
|
19
|
+
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
|
20
|
+
# gem 'therubyracer', :platforms => :ruby
|
21
|
+
gem 'uglifier', '>= 1.0.3'
|
22
|
+
end
|
23
|
+
|
24
|
+
gem 'jquery-rails'
|
25
|
+
gem 'jslint'
|
26
|
+
|
27
|
+
group :test do
|
28
|
+
gem 'capybara'
|
29
|
+
gem 'launchy'
|
30
|
+
end
|
data/README.md
CHANGED
@@ -4,7 +4,6 @@ ActiveAdmin hacks to support Mongoid.
|
|
4
4
|
Some ActiveAdmin features are disabled:
|
5
5
|
|
6
6
|
- comments
|
7
|
-
- sidebar filters
|
8
7
|
|
9
8
|
For more on Mongoid support in ActiveAdmin see [this issue](https://github.com/gregbell/active_admin/issues/26).
|
10
9
|
|
@@ -15,11 +14,7 @@ Add the following gems to your application's Gemfile:
|
|
15
14
|
|
16
15
|
```ruby
|
17
16
|
gem 'activeadmin-mongoid'
|
18
|
-
gem 'devise'
|
19
17
|
```
|
20
|
-
Devise is the gem used to managed admin authentication.
|
21
|
-
The gem is required to force itself ORM configuration.
|
22
|
-
Else the gem will try to use by default ActiveRecord ORM.
|
23
18
|
|
24
19
|
You can safely remove the following lines, since are already activeadmin-mongoid dependencies:
|
25
20
|
|
data/Rakefile
CHANGED
data/activeadmin-mongoid.gemspec
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'active_admin/mongoid/version'
|
3
5
|
|
4
6
|
Gem::Specification.new do |gem|
|
5
7
|
gem.authors = ['Elia Schito']
|
@@ -15,9 +17,11 @@ Gem::Specification.new do |gem|
|
|
15
17
|
gem.require_paths = ['lib']
|
16
18
|
gem.version = ActiveAdmin::Mongoid::VERSION
|
17
19
|
gem.license = 'MIT'
|
18
|
-
|
19
|
-
gem.add_runtime_dependency 'mongoid', '
|
20
|
-
gem.add_runtime_dependency 'activeadmin', '~> 0.
|
20
|
+
|
21
|
+
gem.add_runtime_dependency 'mongoid', '~> 3.0'
|
22
|
+
gem.add_runtime_dependency 'activeadmin', '~> 0.6'
|
21
23
|
gem.add_runtime_dependency 'meta_search', '>= 1.1.0.pre'
|
22
24
|
gem.add_runtime_dependency 'sass-rails', ['~> 3.1', '>= 3.1.4']
|
25
|
+
|
26
|
+
gem.add_development_dependency 'rspec-rails', '~> 2.7'
|
23
27
|
end
|
data/lib/active_admin/mongoid.rb
CHANGED
@@ -1,20 +1,29 @@
|
|
1
|
+
require 'active_admin/mongoid/version'
|
2
|
+
# require 'active_admin/mongoid/engine'
|
1
3
|
require 'active_admin'
|
4
|
+
require 'devise'
|
5
|
+
require 'rails'
|
2
6
|
require 'mongoid'
|
3
7
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
8
|
+
require 'active_admin/mongoid/comments'
|
9
|
+
require 'active_admin/mongoid/adaptor'
|
10
|
+
require 'active_admin/mongoid/filter_form_builder'
|
11
|
+
require 'active_admin/mongoid/resource'
|
12
|
+
require 'active_admin/mongoid/document'
|
13
|
+
require 'active_admin/mongoid/helpers/collection'
|
14
|
+
require 'active_admin/mongoid/criteria'
|
15
|
+
|
16
|
+
# module ActiveAdmin
|
17
|
+
# module Mongoid
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# class << self
|
21
|
+
# alias setup_without_mongoid setup
|
22
|
+
#
|
23
|
+
# # Load monkey patches *after* the setup process
|
24
|
+
# def setup *args, &block
|
25
|
+
# setup_without_mongoid *args, &block
|
26
|
+
#
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
# end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
module Mongoid
|
3
|
+
class Search
|
4
|
+
attr_reader :base, :query, :query_hash, :search_params
|
5
|
+
|
6
|
+
def initialize(object, search_params = {}, per_page = 30, page = 1)
|
7
|
+
@base = object
|
8
|
+
@search_params = search_params
|
9
|
+
@query_hash = get_query_hash(search_params)
|
10
|
+
vpage = page.to_i > 0 ? page.to_i : 1
|
11
|
+
@query = @base.where(@query_hash).limit(per_page).skip(per_page * (vpage - 1))
|
12
|
+
end
|
13
|
+
|
14
|
+
def respond_to?(method_id)
|
15
|
+
@query.send(:respond_to?, method_id)
|
16
|
+
end
|
17
|
+
|
18
|
+
def method_missing(method_id, *args, &block)
|
19
|
+
if is_query(method_id)
|
20
|
+
@search_params[method_id.to_s]
|
21
|
+
else
|
22
|
+
@query.send(method_id, *args, &block)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def is_query(method_id)
|
29
|
+
method_id.to_s =~ /_(contains|eq|in|gt|lt|gte|lte)$/
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_query_hash(search_params)
|
33
|
+
searches = search_params.map do|k, v|
|
34
|
+
mongoidify_search(k,v)
|
35
|
+
end
|
36
|
+
Hash[searches]
|
37
|
+
end
|
38
|
+
|
39
|
+
def mongoidify_search(k, v)
|
40
|
+
case k
|
41
|
+
when /_contains$/
|
42
|
+
[get_attribute(k, '_contains'), Regexp.new(Regexp.escape("#{v}"), Regexp::IGNORECASE)]
|
43
|
+
when /_eq$/
|
44
|
+
[get_attribute(k, '_eq'), v]
|
45
|
+
when /_in$/
|
46
|
+
[get_attribute(k, '_in').to_sym.in, v]
|
47
|
+
when /_gt$/
|
48
|
+
[get_attribute(k, "_gt").to_sym.gt, v]
|
49
|
+
when /_lt$/
|
50
|
+
[get_attribute(k, "_lt").to_sym.lt, v]
|
51
|
+
when /_gte$/
|
52
|
+
[get_attribute(k, "_gte").to_sym.gte, v]
|
53
|
+
when /_lte$/
|
54
|
+
[get_attribute(k, "_lte").to_sym.lte, v]
|
55
|
+
else
|
56
|
+
[k, v]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_attribute(k, postfix)
|
61
|
+
k.match(/^(.*)#{postfix}$/)[1]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -1,7 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
require 'active_admin/comments/namespace_helper'
|
2
|
+
# ActiveAdmin::Application.allow_comments = false
|
3
|
+
|
4
|
+
module ActiveAdmin
|
5
|
+
module Comments
|
6
|
+
|
7
|
+
module NamespaceHelper
|
8
|
+
def comments?
|
9
|
+
false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
6
13
|
end
|
7
14
|
end
|
@@ -1,18 +1,59 @@
|
|
1
1
|
module ActiveAdmin::Mongoid::Document
|
2
2
|
extend ActiveSupport::Concern
|
3
|
-
|
3
|
+
|
4
|
+
included do
|
5
|
+
unless respond_to? :primary_key
|
6
|
+
class << self
|
7
|
+
attr_accessor :primary_key
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
self.primary_key ||= [:_id]
|
12
|
+
end
|
13
|
+
|
14
|
+
class Connection
|
15
|
+
def initialize model
|
16
|
+
@model = model
|
17
|
+
end
|
18
|
+
|
19
|
+
def quote_column_name name
|
20
|
+
name
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
4
24
|
module ClassMethods
|
5
25
|
def content_columns
|
6
26
|
@content_columns ||= fields.map(&:second).select {|f| f.name !~ /(^_|^(created|updated)_at)/}
|
7
27
|
end
|
8
28
|
|
29
|
+
def metasearch *args, &block
|
30
|
+
scoped
|
31
|
+
end
|
32
|
+
|
9
33
|
def columns
|
10
34
|
@columns ||= fields.map(&:second)
|
11
35
|
end
|
12
|
-
|
36
|
+
|
37
|
+
def column_names
|
38
|
+
@column_names ||= fields.map(&:first)
|
39
|
+
end
|
40
|
+
|
13
41
|
def reorder *args
|
14
42
|
scoped
|
15
43
|
end
|
44
|
+
|
45
|
+
def connection
|
46
|
+
@connection ||= Connection.new(self)
|
47
|
+
end
|
48
|
+
|
49
|
+
def find_by_id id
|
50
|
+
find_by(:_id => id)
|
51
|
+
end
|
52
|
+
|
53
|
+
def quoted_table_name
|
54
|
+
collection_name.to_s.inspect
|
55
|
+
end
|
56
|
+
|
16
57
|
end
|
17
58
|
end
|
18
59
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class ActiveAdmin::FilterFormBuilder
|
2
|
+
def default_input_type(method, options = {})
|
3
|
+
if column = column_for(method)
|
4
|
+
case column.type.name.downcase.to_sym
|
5
|
+
when :date, :datetime, :time; :date_range
|
6
|
+
when :string, :text, :objectl; :string
|
7
|
+
when :float, :decimal; :numeric
|
8
|
+
when :integer
|
9
|
+
return :select if reflection_for(method.to_s.gsub('_id','').to_sym)
|
10
|
+
return :numeric
|
11
|
+
end
|
12
|
+
elsif is_association?(method)
|
13
|
+
return :select
|
14
|
+
else
|
15
|
+
# dirty but allows to create filters for hashes
|
16
|
+
return :string
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def is_association?(method)
|
21
|
+
@object.klass.associations.to_a.map(&:first).include?(method.to_s)
|
22
|
+
end
|
23
|
+
|
24
|
+
def column_for(method)
|
25
|
+
@object.klass.fields[method.to_s] if @object.klass.respond_to?(:fields)
|
26
|
+
end
|
27
|
+
|
28
|
+
def reflection_for(method)
|
29
|
+
@object.klass.reflect_on_association(method) if @object.klass.respond_to?(:reflect_on_association)
|
30
|
+
end
|
31
|
+
end
|
@@ -1,34 +1,52 @@
|
|
1
|
-
|
2
|
-
class
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
# module ActiveAdmin
|
2
|
+
# class Resource
|
3
|
+
#
|
4
|
+
# module Naming
|
5
|
+
#
|
6
|
+
# # Returns a name used to uniquely identify this resource
|
7
|
+
# # this should be an instance of ActiveAdmin:Resource::Name, which responds to
|
8
|
+
# # #singular, #plural, #route_key, #human etc.
|
9
|
+
# def resource_name
|
10
|
+
# custom_name = @options[:as] && @options[:as].gsub(/\s/,'')
|
11
|
+
# @resource_name ||= if custom_name || !resource_class.respond_to?(:model_name)
|
12
|
+
# Resource::Name.new(resource_class, custom_name)
|
13
|
+
# else
|
14
|
+
# Resource::Name.new(resource_class)
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# end
|
21
|
+
# end
|
7
22
|
|
8
|
-
ActiveAdmin::
|
9
|
-
class ActiveAdmin::
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
23
|
+
# ActiveAdmin::Resource # autoload
|
24
|
+
# class ActiveAdmin::Resource
|
25
|
+
# def resource_table_name
|
26
|
+
# resource_class.collection_name
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# def mongoid_per_page
|
30
|
+
# per_page
|
31
|
+
# end
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# ActiveAdmin::ResourceController # autoload
|
35
|
+
# class ActiveAdmin::ResourceController
|
36
|
+
#
|
37
|
+
# protected
|
38
|
+
#
|
39
|
+
# # Use #desc and #asc for sorting.
|
40
|
+
# def sort_order(chain)
|
41
|
+
# params[:order] ||= active_admin_config.sort_order
|
42
|
+
# if params[:order] && params[:order] =~ /^([\w\_\.]+)_(desc|asc)$/
|
43
|
+
# chain.send($2, $1)
|
44
|
+
# else
|
45
|
+
# chain # just return the chain
|
46
|
+
# end
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
# def search(chain)
|
50
|
+
# @search = ActiveAdmin::Mongoid::Search.new(chain, clean_search_params(params[:q]), active_admin_config.mongoid_per_page, params[:page])
|
51
|
+
# end
|
52
|
+
# end
|