activeadmin-mongoid 0.9.0 → 2.0.0
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.
- checksums.yaml +4 -4
- data/.github/workflows/codecheck.yml +18 -0
- data/.github/workflows/tests.yml +45 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +104 -0
- data/CHANGELOG.md +28 -0
- data/Gemfile +11 -8
- data/README.md +21 -6
- data/activeadmin-mongoid.gemspec +10 -10
- data/lib/active_admin/mongoid/association/relatable.rb +20 -0
- data/lib/active_admin/mongoid/controllers/resource_controller.rb +9 -10
- data/lib/active_admin/mongoid/criteria.rb +0 -1
- data/lib/active_admin/mongoid/csv_builder.rb +11 -6
- data/lib/active_admin/mongoid/document.rb +5 -17
- data/lib/active_admin/mongoid/filter_form_builder.rb +5 -5
- data/lib/active_admin/mongoid/filters/resource_extension.rb +5 -3
- data/lib/active_admin/mongoid/helpers/collection.rb +3 -1
- data/lib/active_admin/mongoid/inputs/filters/select_input.rb +15 -6
- data/lib/active_admin/mongoid/resource/attributes.rb +2 -3
- data/lib/active_admin/mongoid/resource.rb +1 -1
- data/lib/active_admin/mongoid/version.rb +1 -1
- data/lib/active_admin/mongoid.rb +1 -0
- data/lib/activeadmin-mongoid.rb +26 -0
- data/lib/meta_search/searches/mongoid.rb +4 -4
- data/spec/features/smoke_spec.rb +20 -7
- data/spec/lib/active_admin/mongoid/filter_form_builder_spec.rb +5 -7
- data/spec/lib/active_admin/mongoid/filters/resource_extension_spec.rb +19 -0
- data/spec/spec_helper.rb +3 -5
- data/spec/support/capybara.rb +0 -2
- data/spec/support/debug.rb +2 -2
- data/spec/support/mongoid.rb +2 -2
- data/tasks/js.rake +0 -2
- data/tasks/test.rake +2 -6
- data/test_app/Rakefile +1 -1
- data/test_app/app/admin/admin_users.rb +0 -1
- data/test_app/app/admin/dashboard.rb +4 -5
- data/test_app/app/admin/posts.rb +1 -1
- data/test_app/app/assets/config/manifest.js +1 -0
- data/test_app/app/models/admin_user.rb +11 -11
- data/test_app/app/models/post.rb +2 -0
- data/test_app/bin/rails +4 -0
- data/test_app/bin/rake +4 -0
- data/test_app/bin/setup +25 -0
- data/test_app/config/application.rb +2 -1
- data/test_app/config/boot.rb +4 -5
- data/test_app/config/environment.rb +3 -3
- data/test_app/config/environments/development.rb +2 -1
- data/test_app/config/environments/production.rb +0 -1
- data/test_app/config/environments/test.rb +3 -2
- data/test_app/config/initializers/active_admin.rb +0 -13
- data/test_app/config/initializers/inflections.rb +6 -5
- data/test_app/config/initializers/wrap_parameters.rb +0 -1
- data/test_app/config/{mongoid.6.yml → mongoid.7.yml} +2 -3
- data/test_app/config/mongoid.8.yml +13 -0
- data/test_app/config.ru +1 -1
- data/test_app/db/migrate/20130514223107_create_admin_notes.rb +3 -3
- data/test_app/db/migrate/20130514223108_move_admin_notes_to_comments.rb +2 -2
- data/test_app/script/rails +2 -2
- data/test_app/test/test_helper.rb +1 -1
- metadata +48 -23
- data/.travis.yml +0 -11
- data/Gemfile.lock +0 -295
- data/test_app/config/mongoid.2.yml +0 -20
- data/test_app/config/mongoid.3.yml +0 -96
- data/test_app/config/mongoid.4.yml +0 -87
- data/test_app/config/mongoid.5.yml +0 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6e88a5c57c831a91f2d9359ad41814f85685f33d9312ac4d98c9b8240b310555
|
|
4
|
+
data.tar.gz: 89803e894a8fef6d88f48bef7778b2199e14d51c714e75c0b6997cc46b128ac8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: aba3dc5070f97ef7f015a546b4be222be5561bef3a1a86b011390ba634453f95c1fc973d9c37a76eecc3b9c76d97680851c90f162f761d9ced6eb299df8d0ff7
|
|
7
|
+
data.tar.gz: b34d932081070a55f7c6a344e4bc0683665685304cf7f7616e2bedec7bad7b2427495b24d741d3aaa5b762067c5690c9c6c70c88fb515b767a1153f0cd792ebd
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
name: Codecheck
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches:
|
|
5
|
+
- master
|
|
6
|
+
pull_request:
|
|
7
|
+
branches:
|
|
8
|
+
- master
|
|
9
|
+
jobs:
|
|
10
|
+
codecheck:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
- uses: ruby/setup-ruby@v1
|
|
15
|
+
with:
|
|
16
|
+
ruby-version: 3.3
|
|
17
|
+
bundler-cache: true
|
|
18
|
+
- run: bundle exec rubocop
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
name: Tests
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches:
|
|
5
|
+
- master
|
|
6
|
+
pull_request:
|
|
7
|
+
branches:
|
|
8
|
+
- master
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
strategy:
|
|
12
|
+
fail-fast: false
|
|
13
|
+
matrix:
|
|
14
|
+
ruby: ['3.1', '3.2', '3.3', '3.4', '4.0']
|
|
15
|
+
rails: ['6.1', '7.0']
|
|
16
|
+
mongoid: ['7.5', '8.1']
|
|
17
|
+
exclude:
|
|
18
|
+
# Rails 6.1 doesn't support Ruby 3.4 or later.
|
|
19
|
+
- ruby: '3.4'
|
|
20
|
+
rails: '6.1'
|
|
21
|
+
- ruby: '4.0'
|
|
22
|
+
rails: '6.1'
|
|
23
|
+
# ubuntu-latest (26.04) can't compile native extensions against Ruby 3.2's headers.
|
|
24
|
+
runs-on: ubuntu-24.04
|
|
25
|
+
name: Ruby ${{ matrix.ruby }}, Rails ${{ matrix.rails }}, Mongoid ${{ matrix.mongoid }}
|
|
26
|
+
env:
|
|
27
|
+
RAILS_VERSION: ${{ matrix.rails }}
|
|
28
|
+
MONGOID_VERSION: ${{ matrix.mongoid }}
|
|
29
|
+
|
|
30
|
+
services:
|
|
31
|
+
mongodb:
|
|
32
|
+
image: mongo:7
|
|
33
|
+
ports:
|
|
34
|
+
- 27017:27017
|
|
35
|
+
|
|
36
|
+
steps:
|
|
37
|
+
- uses: actions/checkout@v4
|
|
38
|
+
- uses: ruby/setup-ruby@v1
|
|
39
|
+
with:
|
|
40
|
+
ruby-version: ${{ matrix.ruby }}
|
|
41
|
+
# Not setup-ruby's bundler-cache: it locks the Gemfile without this job's RAILS_VERSION and
|
|
42
|
+
# MONGOID_VERSION. setup-ruby still writes that default lockfile, and moving it to this job's
|
|
43
|
+
# versions can fail to resolve, so resolve from scratch.
|
|
44
|
+
- run: rm -f Gemfile.lock && bundle install
|
|
45
|
+
- run: bundle exec rake
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
DisabledByDefault: true
|
|
3
|
+
TargetRubyVersion: 2.4
|
|
4
|
+
|
|
5
|
+
DisplayCopNames: true
|
|
6
|
+
|
|
7
|
+
StyleGuideCopsOnly: false
|
|
8
|
+
|
|
9
|
+
Layout/EndAlignment:
|
|
10
|
+
Enabled: true
|
|
11
|
+
|
|
12
|
+
Lint/ParenthesesAsGroupedExpression:
|
|
13
|
+
Enabled: true
|
|
14
|
+
|
|
15
|
+
Layout/AccessModifierIndentation:
|
|
16
|
+
Enabled: true
|
|
17
|
+
|
|
18
|
+
Layout/CaseIndentation:
|
|
19
|
+
Enabled: true
|
|
20
|
+
|
|
21
|
+
Layout/CommentIndentation:
|
|
22
|
+
Enabled: true
|
|
23
|
+
|
|
24
|
+
Layout/ElseAlignment:
|
|
25
|
+
Enabled: true
|
|
26
|
+
|
|
27
|
+
Layout/EmptyLines:
|
|
28
|
+
Enabled: true
|
|
29
|
+
|
|
30
|
+
Layout/EmptyLinesAroundBlockBody:
|
|
31
|
+
Enabled: true
|
|
32
|
+
|
|
33
|
+
Layout/EndOfLine:
|
|
34
|
+
Enabled: true
|
|
35
|
+
|
|
36
|
+
Layout/ExtraSpacing:
|
|
37
|
+
Enabled: true
|
|
38
|
+
|
|
39
|
+
Style/Dir:
|
|
40
|
+
Enabled: true
|
|
41
|
+
|
|
42
|
+
Style/Encoding:
|
|
43
|
+
Enabled: true
|
|
44
|
+
|
|
45
|
+
Style/ExpandPathArguments:
|
|
46
|
+
Enabled: true
|
|
47
|
+
|
|
48
|
+
Style/FrozenStringLiteralComment:
|
|
49
|
+
Enabled: true
|
|
50
|
+
EnforcedStyle: never
|
|
51
|
+
|
|
52
|
+
Style/HashSyntax:
|
|
53
|
+
Enabled: true
|
|
54
|
+
|
|
55
|
+
Style/ParallelAssignment:
|
|
56
|
+
Enabled: true
|
|
57
|
+
|
|
58
|
+
Layout/IndentationConsistency:
|
|
59
|
+
Enabled: true
|
|
60
|
+
|
|
61
|
+
Layout/IndentationWidth:
|
|
62
|
+
Enabled: true
|
|
63
|
+
|
|
64
|
+
Naming/PredicateName:
|
|
65
|
+
Enabled: true
|
|
66
|
+
|
|
67
|
+
ForbiddenPrefixes:
|
|
68
|
+
- is_
|
|
69
|
+
- have_
|
|
70
|
+
|
|
71
|
+
AllowedMethods:
|
|
72
|
+
- has_many
|
|
73
|
+
- has_many_actions
|
|
74
|
+
- is_association?
|
|
75
|
+
|
|
76
|
+
Style/TrailingCommaInArguments:
|
|
77
|
+
Enabled: true
|
|
78
|
+
|
|
79
|
+
Layout/TrailingEmptyLines:
|
|
80
|
+
Enabled: true
|
|
81
|
+
|
|
82
|
+
Layout/TrailingWhitespace:
|
|
83
|
+
Enabled: true
|
|
84
|
+
|
|
85
|
+
Layout/SpaceAfterComma:
|
|
86
|
+
Enabled: true
|
|
87
|
+
|
|
88
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
|
89
|
+
Enabled: true
|
|
90
|
+
|
|
91
|
+
Layout/SpaceAroundOperators:
|
|
92
|
+
Enabled: true
|
|
93
|
+
|
|
94
|
+
Layout/SpaceBeforeBlockBraces:
|
|
95
|
+
Enabled: true
|
|
96
|
+
|
|
97
|
+
Layout/SpaceInsideBlockBraces:
|
|
98
|
+
Enabled: true
|
|
99
|
+
|
|
100
|
+
Layout/SpaceInsideHashLiteralBraces:
|
|
101
|
+
Enabled: true
|
|
102
|
+
|
|
103
|
+
Layout/SpaceInsideParens:
|
|
104
|
+
Enabled: true
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 2.0.0
|
|
4
|
+
|
|
5
|
+
Supports Ruby 3.1+, Rails 6.1 and 7.0, Mongoid 7 and 8, and ActiveAdmin 2.x. Use 1.0.0 for older
|
|
6
|
+
versions.
|
|
7
|
+
|
|
8
|
+
### Breaking changes
|
|
9
|
+
|
|
10
|
+
* Requires Ruby 3.1 or later, Mongoid 7.0 or later, and ActiveAdmin 2.x.
|
|
11
|
+
* `build_new_resource` no longer passes `resource_params` to the build method. ActiveAdmin assigns
|
|
12
|
+
them right after building, so they were being assigned twice.
|
|
13
|
+
|
|
14
|
+
### Fixes
|
|
15
|
+
|
|
16
|
+
* Rails 7.0: the resource controller patch is applied in `to_prepare`, since Rails 7 doesn't autoload
|
|
17
|
+
during initialization.
|
|
18
|
+
* ActiveAdmin 2.14: CSV export no longer goes through `in_paginated_batches`, which needs
|
|
19
|
+
ActiveRecord. Like it, the export skips the query cache.
|
|
20
|
+
* Ruby 3: CSV options are passed as keyword arguments.
|
|
21
|
+
* Select filters search the key the document stores, so filters on `belongs_to` and
|
|
22
|
+
`has_and_belongs_to_many` associations work.
|
|
23
|
+
* `has_many` and `has_one` associations are no longer default filters, since their keys are in the
|
|
24
|
+
related documents. Declaring one explicitly raises an error that says so.
|
|
25
|
+
* The index page's "Displaying X - Y" counts the current page in the database instead of loading
|
|
26
|
+
documents (and no longer counts the whole collection).
|
|
27
|
+
* `primary_key` works for subclasses of a document.
|
|
28
|
+
* Declares the `csv` dependency, which Ruby 3.4 no longer installs by default.
|
data/Gemfile
CHANGED
|
@@ -2,21 +2,24 @@ source 'https://rubygems.org'
|
|
|
2
2
|
|
|
3
3
|
gemspec
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
# ransack-mongoid 0.x was never released to RubyGems. Pinned to the last commit that supports
|
|
6
|
+
# ransack 2.x, which ActiveAdmin 2 requires.
|
|
7
|
+
gem 'ransack-mongoid', git: 'https://github.com/riverock/ransack-mongoid', ref: 'f83ae55ea67fc0a0bca30158f3e04c49362f4464'
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
gem '
|
|
10
|
-
|
|
11
|
-
gem 'pry-rails'
|
|
9
|
+
# CI picks the versions; see .github/workflows/tests.yml.
|
|
10
|
+
gem 'rails', "~> #{ENV.fetch('RAILS_VERSION', '7.0')}.0"
|
|
11
|
+
gem 'mongoid', "~> #{ENV.fetch('MONGOID_VERSION', '8.1')}.0"
|
|
12
12
|
|
|
13
|
+
gem 'devise', '~> 4.0' # ActiveAdmin 2 requires < 5
|
|
13
14
|
gem 'jquery-rails'
|
|
14
15
|
gem 'jquery-ui-rails'
|
|
15
|
-
gem 'jslint'
|
|
16
16
|
|
|
17
17
|
group :test do
|
|
18
18
|
gem 'capybara'
|
|
19
|
-
gem 'poltergeist'
|
|
20
19
|
gem 'launchy'
|
|
21
20
|
gem 'simplecov', require: false
|
|
22
21
|
end
|
|
22
|
+
|
|
23
|
+
group :lint do
|
|
24
|
+
gem 'rubocop', '0.80.0'
|
|
25
|
+
end
|
data/README.md
CHANGED
|
@@ -1,16 +1,30 @@
|
|
|
1
1
|
# ActiveAdmin-Mongoid
|
|
2
2
|
[![Version ][rubygems_badge]][rubygems]
|
|
3
|
-
|
|
3
|
+

|
|
4
|
+

|
|
4
5
|
|
|
5
6
|
## Updates
|
|
6
7
|
|
|
7
8
|
ActiveAdmin is holding off on pulling Mongoid support into the core ActiveAdmin application. This repo was pulled into the ActiveAdmin org from previous work done by Elia Schito, and will be maintained by Grzegorz Jakubiak, Nic Boie, JD Guzman, Elia Schito and other ActiveAdmin and community members.
|
|
8
9
|
|
|
9
|
-
### Requirements for version 0.
|
|
10
|
-
* Ruby
|
|
10
|
+
### Requirements for version 2.0.0
|
|
11
|
+
* Ruby 3.1 or greater (Ruby 3.4 and later need Rails 7.0).
|
|
12
|
+
* Rails 6.1 or 7.0
|
|
13
|
+
* Mongoid 7.x or 8.x
|
|
14
|
+
* ActiveAdmin 2.x (tested on 2.14)
|
|
15
|
+
* `ransack-mongoid` - declare it in your Gemfile from GitHub; it has no RubyGems release that supports ransack 2.x or 3.x, which ActiveAdmin 2 requires:
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
gem 'ransack-mongoid', github: 'riverock/ransack-mongoid', ref: 'f83ae55ea67fc0a0bca30158f3e04c49362f4464'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
See [CHANGELOG.md](CHANGELOG.md) for the changes from 1.0.0.
|
|
22
|
+
|
|
23
|
+
### Requirements for version 1.0.0
|
|
24
|
+
* Ruby 2.4.0 or greater.
|
|
11
25
|
* Tested working on Rails 5.2.3
|
|
12
26
|
* Mongoid 6.x (**WARNING**:, using a Mongoid version >= 6.1.x has resulted in a fair amount of errors seen in the wild. Test your upgrade very carefully with any apps in which you're using this gem with Mongoid >= 6.1.x!)
|
|
13
|
-
* ActiveAdmin 1.4.3
|
|
27
|
+
* ActiveAdmin 1.4.3 or greater
|
|
14
28
|
* `ransack-mongoid` - it needs to be explicitly declared in Gemfile, pointing to github's master since it has no releases on rubygems yet.
|
|
15
29
|
|
|
16
30
|
## Previous versions
|
|
@@ -38,8 +52,8 @@ For more on Mongoid support in ActiveAdmin see [this issue](https://github.com/g
|
|
|
38
52
|
Add the following gems to your application's Gemfile, and lock the version:
|
|
39
53
|
|
|
40
54
|
```ruby
|
|
41
|
-
gem 'activeadmin-mongoid', '
|
|
42
|
-
gem 'ransack-mongoid', github: '
|
|
55
|
+
gem 'activeadmin-mongoid', '~> 2.0'
|
|
56
|
+
gem 'ransack-mongoid', github: 'riverock/ransack-mongoid', ref: 'f83ae55ea67fc0a0bca30158f3e04c49362f4464'
|
|
43
57
|
```
|
|
44
58
|
|
|
45
59
|
You can safely remove the following lines, since are already activeadmin-mongoid dependencies:
|
|
@@ -61,6 +75,7 @@ with:
|
|
|
61
75
|
require "action_controller/railtie"
|
|
62
76
|
require "action_mailer/railtie"
|
|
63
77
|
require "active_resource/railtie"
|
|
78
|
+
require "action_view/railtie"
|
|
64
79
|
require "sprockets/railtie"
|
|
65
80
|
require "rails/test_unit/railtie"
|
|
66
81
|
```
|
data/activeadmin-mongoid.gemspec
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
3
|
require 'active_admin/mongoid/version'
|
|
5
4
|
|
|
@@ -8,23 +7,24 @@ Gem::Specification.new do |gem|
|
|
|
8
7
|
gem.email = ['elia@schito.me']
|
|
9
8
|
gem.description = %q{ActiveAdmin hacks to support Mongoid (some ActiveAdmin features are disabled)}
|
|
10
9
|
gem.summary = %q{ActiveAdmin hacks to support Mongoid}
|
|
11
|
-
gem.homepage = ''
|
|
10
|
+
gem.homepage = 'https://github.com/activeadmin/activeadmin-mongoid'
|
|
12
11
|
|
|
13
|
-
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
12
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
|
14
13
|
gem.files = `git ls-files`.split("\n")
|
|
15
14
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
16
15
|
gem.name = 'activeadmin-mongoid'
|
|
17
16
|
gem.require_paths = ['lib']
|
|
18
17
|
gem.version = ActiveAdmin::Mongoid::VERSION
|
|
19
18
|
gem.license = 'MIT'
|
|
20
|
-
|
|
21
|
-
gem.required_ruby_version = '>= 2.3'
|
|
22
19
|
|
|
23
|
-
gem.
|
|
24
|
-
|
|
20
|
+
gem.required_ruby_version = '>= 3.1'
|
|
21
|
+
|
|
22
|
+
gem.add_runtime_dependency 'mongoid', '>= 7.0', '< 9'
|
|
23
|
+
gem.add_runtime_dependency 'activeadmin', '~> 2.0'
|
|
24
|
+
gem.add_runtime_dependency 'csv' # the CSV builder; no longer a default gem from Ruby 3.4
|
|
25
25
|
gem.add_runtime_dependency 'kaminari-mongoid'
|
|
26
26
|
gem.add_runtime_dependency 'jquery-rails'
|
|
27
|
-
gem.add_runtime_dependency 'sass-rails',
|
|
27
|
+
gem.add_runtime_dependency 'sass-rails', ['>= 3.1.4']
|
|
28
28
|
|
|
29
|
-
gem.add_development_dependency 'rspec-rails',
|
|
29
|
+
gem.add_development_dependency 'rspec-rails', '~> 6.1'
|
|
30
30
|
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Mongoid::Association::Relatable.module_eval do
|
|
2
|
+
def macro
|
|
3
|
+
self.class.name.split('::').last.underscore.to_sym
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def embeds?
|
|
7
|
+
[:embeds_one, :embeds_many].include?(macro)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# Whether the association's key is stored in this document, so it can be filtered on.
|
|
11
|
+
# has_many and has_one keep theirs in the related document.
|
|
12
|
+
def key_stored_on_document?
|
|
13
|
+
[:belongs_to, :has_and_belongs_to_many].include?(macro)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def foreign_key
|
|
17
|
+
return if embeds?
|
|
18
|
+
foreign_key.to_sym rescue nil
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
require 'active_admin/engine'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
end
|
|
3
|
+
# to_prepare, not an initializer: ResourceController inherits from InheritedResources::Base,
|
|
4
|
+
# which lives in that gem's app/controllers and can't be autoloaded during initialization
|
|
5
|
+
# on Rails 7.
|
|
6
|
+
ActiveAdmin::Engine.config.to_prepare do
|
|
7
|
+
ActiveAdmin::ResourceController.class_eval do
|
|
8
|
+
# No params: ActiveAdmin assigns resource_params right after building, and passing them here
|
|
9
|
+
# too assigned relation attributes twice.
|
|
10
|
+
def build_new_resource
|
|
11
|
+
scoped_collection.send(method_for_build)
|
|
13
12
|
end
|
|
14
13
|
end
|
|
15
14
|
end
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
module ActiveAdmin
|
|
2
2
|
class CSVBuilder
|
|
3
3
|
def build(controller, csv)
|
|
4
|
-
@collection = controller.send :find_collection, except: :pagination
|
|
5
4
|
columns = exec_columns controller.view_context
|
|
6
5
|
options = ActiveAdmin.application.csv_options.merge self.options
|
|
7
6
|
bom = options.delete :byte_order_mark
|
|
@@ -11,13 +10,19 @@ module ActiveAdmin
|
|
|
11
10
|
csv << bom if bom
|
|
12
11
|
|
|
13
12
|
if column_names
|
|
14
|
-
csv << CSV.generate_line(columns.map{ |c| encode c.name, options }, csv_options)
|
|
13
|
+
csv << CSV.generate_line(columns.map { |c| encode c.name, options }, **csv_options)
|
|
15
14
|
end
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
# Not ActiveAdmin's in_paginated_batches: it wraps the loop in ActiveRecord::Base.uncached,
|
|
17
|
+
# and ActiveRecord isn't loaded in a Mongoid app. Skip Mongo's query cache the same way, so a
|
|
18
|
+
# large export doesn't keep every page cached until the request ends.
|
|
19
|
+
query_cache = defined?(::Mongo::QueryCache) ? ::Mongo::QueryCache : ::Mongoid::QueryCache
|
|
20
|
+
query_cache.uncached do
|
|
21
|
+
(1..controller.send(:paginated_collection).total_pages).each do |page|
|
|
22
|
+
controller.send(:paginated_collection, page).each do |resource|
|
|
23
|
+
resource = controller.send :apply_decorator, resource
|
|
24
|
+
csv << CSV.generate_line(build_row(resource, columns, options), **csv_options)
|
|
25
|
+
end
|
|
21
26
|
end
|
|
22
27
|
end
|
|
23
28
|
|
|
@@ -3,9 +3,6 @@ require 'delegate'
|
|
|
3
3
|
module ActiveAdmin::Mongoid::Document
|
|
4
4
|
extend ActiveSupport::Concern
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
6
|
# PROXY CLASSES
|
|
10
7
|
|
|
11
8
|
class ColumnWrapper < SimpleDelegator
|
|
@@ -30,30 +27,22 @@ module ActiveAdmin::Mongoid::Document
|
|
|
30
27
|
end
|
|
31
28
|
end
|
|
32
29
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
# CLASS METHODS
|
|
37
|
-
|
|
38
30
|
included do
|
|
39
|
-
unless respond_to? :primary_key
|
|
40
|
-
|
|
41
|
-
attr_accessor :primary_key
|
|
42
|
-
end
|
|
31
|
+
unless respond_to?(:primary_key) && respond_to?(:primary_key=)
|
|
32
|
+
class_attribute :primary_key, instance_writer: false
|
|
43
33
|
end
|
|
44
34
|
|
|
45
|
-
self.primary_key
|
|
35
|
+
self.primary_key = :id if primary_key.nil?
|
|
46
36
|
|
|
47
37
|
def column_for_attribute(name)
|
|
48
38
|
self.class.fields[name.to_sym]
|
|
49
39
|
end
|
|
50
|
-
|
|
51
40
|
end
|
|
52
41
|
|
|
53
42
|
module ClassMethods
|
|
54
43
|
def content_columns
|
|
55
44
|
# cannot cache this, since changes in time (while defining fields)
|
|
56
|
-
fields.map(&:second).reject do |f|
|
|
45
|
+
fields.map(&:second).reject! do |f|
|
|
57
46
|
f.name =~ /(^_|^(created|updated)_at)/ or Mongoid::Fields::ForeignKey === f
|
|
58
47
|
end
|
|
59
48
|
end
|
|
@@ -63,7 +52,7 @@ module ActiveAdmin::Mongoid::Document
|
|
|
63
52
|
end
|
|
64
53
|
|
|
65
54
|
def find_by_id id
|
|
66
|
-
find_by(:
|
|
55
|
+
find_by(_id: id)
|
|
67
56
|
end
|
|
68
57
|
|
|
69
58
|
def quoted_table_name
|
|
@@ -74,7 +63,6 @@ module ActiveAdmin::Mongoid::Document
|
|
|
74
63
|
@associations ||= new.associations
|
|
75
64
|
end
|
|
76
65
|
|
|
77
|
-
|
|
78
66
|
def reflections *a
|
|
79
67
|
relations *a
|
|
80
68
|
end
|
|
@@ -9,11 +9,11 @@ class ActiveAdmin::Filters::FormBuilder
|
|
|
9
9
|
def default_input_type(method, options = {})
|
|
10
10
|
if column = column_for(method)
|
|
11
11
|
case column.type.name.downcase.to_sym
|
|
12
|
-
when :date, :datetime, :time;
|
|
13
|
-
when :string, :text, :object;
|
|
14
|
-
when :float, :decimal;
|
|
12
|
+
when :date, :datetime, :time; :date_range
|
|
13
|
+
when :string, :text, :object; :string
|
|
14
|
+
when :float, :decimal; :numeric
|
|
15
15
|
when :integer
|
|
16
|
-
return :select if reflection_for(method.to_s.gsub('_id','').to_sym)
|
|
16
|
+
return :select if reflection_for(method.to_s.gsub('_id', '').to_sym)
|
|
17
17
|
return :numeric
|
|
18
18
|
end
|
|
19
19
|
elsif is_association?(method)
|
|
@@ -25,7 +25,7 @@ class ActiveAdmin::Filters::FormBuilder
|
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
def is_association?(method)
|
|
28
|
-
@object.klass.associations.to_a.map(&:first).include?(method.to_s)
|
|
28
|
+
@object.klass.associations.to_a.map!(&:first).include?(method.to_s)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def column_for(method)
|
|
@@ -3,10 +3,12 @@ require 'active_admin/filters/resource_extension'
|
|
|
3
3
|
module ActiveAdmin::Filters::ResourceExtension
|
|
4
4
|
def default_association_filters
|
|
5
5
|
if resource_class.respond_to?(:reflect_on_all_associations)
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
# Only associations whose key this document stores can be filtered (not embedded ones,
|
|
7
|
+
# has_many or has_one).
|
|
8
|
+
filterable = resource_class.reflect_on_all_associations.select(&:key_stored_on_document?)
|
|
9
|
+
poly, not_poly = filterable.partition { |r| r.macro == :belongs_to && r.options[:polymorphic] }
|
|
8
10
|
|
|
9
|
-
filters = poly.map(&:
|
|
11
|
+
filters = poly.map(&:foreign_key) + not_poly.map(&:name)
|
|
10
12
|
filters.map &:to_sym
|
|
11
13
|
else
|
|
12
14
|
[]
|
|
@@ -8,7 +8,9 @@ module ActiveAdmin
|
|
|
8
8
|
def collection_size(collection = nil)
|
|
9
9
|
collection ||= self.collection
|
|
10
10
|
if collection.is_a?(::Mongoid::Criteria)
|
|
11
|
-
|
|
11
|
+
# Count in the database instead of loading the documents. Mongoid's count ignores the
|
|
12
|
+
# criteria's skip and limit, so pass them to get the size of the current page.
|
|
13
|
+
collection.count(collection.options.slice(:skip, :limit))
|
|
12
14
|
else
|
|
13
15
|
original_collection_size(collection)
|
|
14
16
|
end
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
require 'active_admin/inputs/filters/select_input'
|
|
2
2
|
|
|
3
3
|
class ActiveAdmin::Inputs::Filters::SelectInput
|
|
4
|
+
# ActiveAdmin builds this from reflection.association_primary_key, which Mongoid associations
|
|
5
|
+
# don't have. Filter on the key the document stores instead (belongs_to and
|
|
6
|
+
# has_and_belongs_to_many). has_many and has_one keep their keys in the related documents, so
|
|
7
|
+
# a filter on them can't match anything.
|
|
4
8
|
def searchable_method_name
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
return method unless reflection
|
|
10
|
+
return reflection.key if reflection.key_stored_on_document?
|
|
11
|
+
|
|
12
|
+
raise ArgumentError, "Can't filter #{@object.klass} by #{method}: Mongoid #{reflection.macro} " \
|
|
13
|
+
"associations aren't stored in the document. Remove `filter :#{method}`."
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def input_name
|
|
17
|
+
return method if seems_searchable?
|
|
18
|
+
|
|
19
|
+
searchable_method_name&.to_s + (multiple? ? '_in' : '_eq')
|
|
11
20
|
end
|
|
12
21
|
end
|
|
@@ -6,8 +6,8 @@ module ActiveAdmin
|
|
|
6
6
|
module Attributes
|
|
7
7
|
def foreign_methods
|
|
8
8
|
@foreign_methods ||= resource_class.reflect_on_all_associations.
|
|
9
|
-
select{ |r| r.macro == :belongs_to }.
|
|
10
|
-
index_by{ |r| r.foreign_key.to_sym }
|
|
9
|
+
select { |r| r.macro == :belongs_to }.
|
|
10
|
+
index_by { |r| r.foreign_key.to_sym }
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def primary_col?(c)
|
|
@@ -20,4 +20,3 @@ module ActiveAdmin
|
|
|
20
20
|
end
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
|
-
|
|
@@ -6,7 +6,7 @@ module ActiveAdmin
|
|
|
6
6
|
# another. I'm not going to investigate any deeper, let's just remove the
|
|
7
7
|
# underscore prefixed fields as was the prior behavior
|
|
8
8
|
def default_filters
|
|
9
|
-
super.reject { |filter|
|
|
9
|
+
super.reject { |filter| filter == :_id }
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
module Attributes
|
data/lib/active_admin/mongoid.rb
CHANGED
|
@@ -13,6 +13,7 @@ require 'active_admin/mongoid/document'
|
|
|
13
13
|
require 'active_admin/mongoid/helpers/collection'
|
|
14
14
|
require 'active_admin/mongoid/criteria'
|
|
15
15
|
require 'active_admin/mongoid/order_clause'
|
|
16
|
+
require 'active_admin/mongoid/association/relatable'
|
|
16
17
|
|
|
17
18
|
require 'active_admin/mongoid/inputs/filters/check_boxes_input'
|
|
18
19
|
require 'active_admin/mongoid/inputs/filters/select_input'
|
data/lib/activeadmin-mongoid.rb
CHANGED
|
@@ -1 +1,27 @@
|
|
|
1
1
|
require 'active_admin/mongoid'
|
|
2
|
+
require "rails/generators/actions"
|
|
3
|
+
require "rails/generators/named_base"
|
|
4
|
+
|
|
5
|
+
# Considering the Rails::Generators::NamedBase is one of the nearest ancestor to
|
|
6
|
+
# ActiveAdmin::Generators::InstallGenerator, we can open the class and an empty create_migration
|
|
7
|
+
# to the class(which will overridden by other subclasses). We can specifically focus on the
|
|
8
|
+
# ActiveAdmin::Generators::InstallGenerator class and apply remove_method during the method_added call
|
|
9
|
+
# and thereby pushing ActiveAdmin::Generators::InstallGenerator to use our empty create_migrations method.
|
|
10
|
+
|
|
11
|
+
Rails::Generators::NamedBase.class_eval do
|
|
12
|
+
def create_migrations
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.inherited(klass)
|
|
16
|
+
super
|
|
17
|
+
if klass.name == "ActiveAdmin::Generators::InstallGenerator"
|
|
18
|
+
|
|
19
|
+
klass.class_eval do
|
|
20
|
+
def self.method_added(method_name)
|
|
21
|
+
super
|
|
22
|
+
remove_method method_name if method_name == :create_migrations
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|