aa_associations 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. data/.gitignore +53 -0
  2. data/Gemfile +10 -0
  3. data/MIT_LICENSE.txt +20 -0
  4. data/README.md +213 -0
  5. data/Rakefile +17 -0
  6. data/aa_associations.gemspec +31 -0
  7. data/app/controllers/autocomplete_controller.rb +37 -0
  8. data/app/helpers/active_admin_associations_helper.rb +77 -0
  9. data/app/views/admin/shared/_add_to_association.html.erb +21 -0
  10. data/app/views/admin/shared/_association_collection_table_actions.html.erb +4 -0
  11. data/app/views/admin/shared/_blank_slate.html.erb +3 -0
  12. data/app/views/admin/shared/_collection_table.html.erb +58 -0
  13. data/app/views/admin/shared/_form.html.erb +7 -0
  14. data/config/routes.rb +7 -0
  15. data/lib/aa_associations.rb +20 -0
  16. data/lib/active_admin_associations/active_admin_extensions.rb +13 -0
  17. data/lib/active_admin_associations/association_actions.rb +43 -0
  18. data/lib/active_admin_associations/association_config.rb +50 -0
  19. data/lib/active_admin_associations/autocompleter.rb +64 -0
  20. data/lib/active_admin_associations/engine.rb +25 -0
  21. data/lib/active_admin_associations/form_config_dsl.rb +15 -0
  22. data/lib/active_admin_associations/redirect_destroy_actions.rb +7 -0
  23. data/lib/active_admin_associations/version.rb +3 -0
  24. data/lib/formtastic/inputs/token_input.rb +43 -0
  25. data/lib/formtastic/token_input_default_for_association.rb +19 -0
  26. data/test/active_admin_associations_test.rb +69 -0
  27. data/test/admin_posts_controller_test.rb +52 -0
  28. data/test/association_config_test.rb +43 -0
  29. data/test/autocomplete_controller_test.rb +27 -0
  30. data/test/autocompleter_test.rb +62 -0
  31. data/test/dummy/README.rdoc +261 -0
  32. data/test/dummy/Rakefile +7 -0
  33. data/test/dummy/app/admin/dashboards.rb +44 -0
  34. data/test/dummy/app/admin/posts.rb +20 -0
  35. data/test/dummy/app/admin/tags.rb +11 -0
  36. data/test/dummy/app/assets/javascripts/active_admin.js +8 -0
  37. data/test/dummy/app/assets/javascripts/application.js +15 -0
  38. data/test/dummy/app/assets/stylesheets/active_admin.css.scss +6 -0
  39. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  40. data/test/dummy/app/controllers/application_controller.rb +3 -0
  41. data/test/dummy/app/helpers/application_helper.rb +2 -0
  42. data/test/dummy/app/mailers/.gitkeep +0 -0
  43. data/test/dummy/app/models/.gitkeep +0 -0
  44. data/test/dummy/app/models/admin_user.rb +10 -0
  45. data/test/dummy/app/models/post.rb +11 -0
  46. data/test/dummy/app/models/tag.rb +15 -0
  47. data/test/dummy/app/models/tagging.rb +7 -0
  48. data/test/dummy/app/models/user.rb +8 -0
  49. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  50. data/test/dummy/config.ru +4 -0
  51. data/test/dummy/config/application.rb +63 -0
  52. data/test/dummy/config/boot.rb +10 -0
  53. data/test/dummy/config/database.yml +19 -0
  54. data/test/dummy/config/environment.rb +5 -0
  55. data/test/dummy/config/environments/development.rb +37 -0
  56. data/test/dummy/config/environments/production.rb +67 -0
  57. data/test/dummy/config/environments/test.rb +37 -0
  58. data/test/dummy/config/initializers/active_admin.rb +129 -0
  59. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  60. data/test/dummy/config/initializers/devise.rb +216 -0
  61. data/test/dummy/config/initializers/inflections.rb +15 -0
  62. data/test/dummy/config/initializers/mime_types.rb +5 -0
  63. data/test/dummy/config/initializers/secret_token.rb +7 -0
  64. data/test/dummy/config/initializers/session_store.rb +8 -0
  65. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  66. data/test/dummy/config/locales/devise.en.yml +57 -0
  67. data/test/dummy/config/locales/en.yml +5 -0
  68. data/test/dummy/config/routes.rb +62 -0
  69. data/test/dummy/db/.gitignore +1 -0
  70. data/test/dummy/db/migrate/20120504220404_devise_create_admin_users.rb +52 -0
  71. data/test/dummy/db/migrate/20120504221534_create_posts.rb +12 -0
  72. data/test/dummy/db/migrate/20120504221936_create_users.rb +9 -0
  73. data/test/dummy/db/migrate/20120504222040_create_tags.rb +8 -0
  74. data/test/dummy/db/migrate/20120504222247_create_taggings.rb +10 -0
  75. data/test/dummy/db/schema.rb +65 -0
  76. data/test/dummy/lib/assets/.gitkeep +0 -0
  77. data/test/dummy/public/404.html +26 -0
  78. data/test/dummy/public/422.html +26 -0
  79. data/test/dummy/public/500.html +25 -0
  80. data/test/dummy/public/favicon.ico +0 -0
  81. data/test/dummy/script/rails +6 -0
  82. data/test/dummy/test/factories/admin_users.rb +9 -0
  83. data/test/dummy/test/factories/posts.rb +11 -0
  84. data/test/dummy/test/factories/taggings.rb +6 -0
  85. data/test/dummy/test/factories/tags.rb +7 -0
  86. data/test/dummy/test/factories/users.rb +8 -0
  87. data/test/dummy/test/unit/admin_user_test.rb +7 -0
  88. data/test/dummy/test/unit/post_test.rb +7 -0
  89. data/test/dummy/test/unit/tag_test.rb +7 -0
  90. data/test/dummy/test/unit/tagging_test.rb +7 -0
  91. data/test/dummy/test/unit/user_test.rb +7 -0
  92. data/test/support/should_change.rb +29 -0
  93. data/test/test_helper.rb +51 -0
  94. data/vendor/assets/javascripts/active_admin_associations.js +14 -0
  95. data/vendor/assets/javascripts/jquery.tokeninput.js +915 -0
  96. data/vendor/assets/stylesheets/active_admin_associations.css.scss +18 -0
  97. data/vendor/assets/stylesheets/token-input-facebook.css +121 -0
  98. metadata +362 -0
@@ -0,0 +1,53 @@
1
+ # rcov generated
2
+ coverage
3
+ coverage.data
4
+
5
+ # rdoc generated
6
+ rdoc
7
+
8
+ # yard generated
9
+ doc
10
+ .yardoc
11
+
12
+ # bundler
13
+ .bundle
14
+
15
+ # jeweler generated
16
+ pkg
17
+
18
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
19
+ #
20
+ # * Create a file at ~/.gitignore
21
+ # * Include files you want ignored
22
+ # * Run: git config --global core.excludesfile ~/.gitignore
23
+ #
24
+ # After doing this, these files will be ignored in all your git projects,
25
+ # saving you from having to 'pollute' every project you touch with them
26
+ #
27
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
28
+ #
29
+ # For MacOS:
30
+ #
31
+ #.DS_Store
32
+
33
+ # For TextMate
34
+ #*.tmproj
35
+ #tmtags
36
+
37
+ # For emacs:
38
+ #*~
39
+ #\#*
40
+ #.\#*
41
+
42
+ # For vim:
43
+ #*.swp
44
+
45
+ # For redcar:
46
+ #.redcar
47
+
48
+ # For rubinius:
49
+ #*.rbc
50
+
51
+ Gemfile.lock
52
+
53
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'meta_search', '>= 1.1.0.pre'
4
+ gem 'kaminari'
5
+ gem 'formtastic', '~> 2.0.2' # Until activeadmin updates for formatastic 2.1+
6
+ gem 'sass-rails', '~> 3.2.3'
7
+ gem 'factory_girl_rails', '~> 1.7'
8
+ gem 'launchy'
9
+
10
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Brian Landau
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,213 @@
1
+ # ActiveAdmin Associations
2
+
3
+ This extends ActiveAdmin to allow for better editing of associations.
4
+
5
+ ## Setup
6
+
7
+ ### Install the gem
8
+
9
+ Add this to your `Gemfile`:
10
+
11
+ gem 'aa_associations'
12
+
13
+ Then run `bundle install`.
14
+
15
+
16
+ ### Autocomplete
17
+
18
+ On many applications you end up with large datasets, trying to select an element from those data sets via a select input (Formtastic's default) is less then ideal for a couple reasons. One, it's hard to navigate a large select list. Two, loading all those records into memory to populate the select list can be time consuming and cause the page to load slowly.
19
+
20
+ So I've packaged [jquery-tokeninput](https://github.com/loopj/jquery-tokeninput), an autocomplete results controller, and an ActiveRecord macro together to help improve this.
21
+
22
+ If you aren't interested in using any of this just add this to your `application.rb` config:
23
+
24
+ config.aa_associations.autocomplete = false
25
+
26
+ If you do want it here's how you set it up:
27
+
28
+ #### Setting up autocomplete
29
+
30
+ First, we'll need to make sure the JS and CSS is setup for the admin part of the site.
31
+
32
+ * Add `//= require active_admin_associations` to the top of your `app/assets/javascripts/active_admin.js` file.
33
+ * Add `autocomplete` statements to models you want to be able to autocomplete in the admin.
34
+ * This first parameter it takes is a column/attribute name like `:title`.
35
+ * The second parameter is an options hash which for now only uses 1 value `:format_label`
36
+ Format Label isn't needed for jquery.tokeninput.js but it is useful when using jQueryUI's autocomplete in other parts of your site. It can allow you to custom format the display label for the autocomplete results displayed by jQueryUI.
37
+ The `:format_label` option should be either a symbol that is a name of a method on an instance of the model, or a proc (or anything that responds to call) that takes 1 parameter which will be the record.
38
+ Example:
39
+ <code><pre>
40
+ autocomplete :name, :format_label => proc {|speaker|
41
+ label = "<span id=\"speaker-#{speaker.id}\">#{speaker.name} <em>("
42
+ label << "#{speaker.position}, " unless speaker.position.blank?
43
+ label << "#{speaker.talk_count} talk#{'s' unless speaker.talk_count == 1})</em></span>"
44
+ label
45
+ }
46
+ </pre></code>
47
+ * Set values for `config.aa_associations.autocomplete_models` in your `config/application.rb`. This should be a list of the models that you have added `autocomplete` statements to:
48
+
49
+ `config.aa_associations.autocomplete_models = %w(post user tag)`
50
+
51
+ If you plan to use other autocomplete JS libraries there are 2 other configs you may want to look at:
52
+
53
+ Different libraries send different param names for the query to the autocomplete endpoint you give it. For instance, jquery.tokeninput uses the `q` parameter while jQueryUI uses the `term` parameter. If no setting is given we will just use the `q` parameter. To configure this you need a statement like this in your `config/application.rb`:
54
+
55
+ config.aa_associations.autocomplete_query_term_param_names = [:q, :term]
56
+
57
+ It might happen that the hash the autocomplete ActiveRecord macro provides for individual results won't play nice with the JS autocomplete plugin you're using. In this case we provide a way to format individual results yourself. Just assign an object that responds to call (like a proc) to `config.aa_associations.autocomplete_result_formatter` in your `config/application.rb` like so:
58
+
59
+ config.aa_associations.autocomplete_result_formatter = proc { |record, autocomplete_attribute, autocomplete_options|
60
+ {:name => record.send(autocomplete_attribute), :id => record.id,
61
+ :another_value => record.send(autocomplete_options[:other_value_method])}
62
+ }
63
+
64
+
65
+ ### Other Configuration
66
+
67
+ We add functionality so that when you do a destroy action you are redirected back to the Referer or the ActiveAdmin Dashboard. If you'd like to remove this functionality you can just put this in your `config/application.rb`:
68
+
69
+ config.aa_associations.destroy_redirect = false
70
+
71
+
72
+ ### Setup your admin resource definitions
73
+
74
+ The main thing this Rails Engine provides is a way to easily configure simple forms that handle `has_many` relationships better then how ActiveAdmin does out of the box. Since we don't override any core ActiveAdmin functionality you can include this in resources you want to use it on and not on others.
75
+
76
+ #### Here's how you get started:
77
+
78
+ Add `association_actions` somewhere inside your ActiveAdmin resource definition block:
79
+
80
+ ActiveAdmin.register Post do
81
+ association_actions
82
+ # ...
83
+ end
84
+
85
+ You then also need to tell it you want to use the form template bundled with this Engine:
86
+
87
+ ActiveAdmin.register Post do
88
+ association_actions
89
+
90
+ form :partial => "admin/shared/form"
91
+ # ...
92
+ end
93
+
94
+ Now you need to define the columns and the `has_many` relationships:
95
+
96
+ ActiveAdmin.register Post do
97
+ association_actions
98
+
99
+ form :partial => "admin/shared/form"
100
+
101
+ form_columns :title, :body, :slug, :author, :published_at, :featured
102
+
103
+ form_associations do
104
+ association :tags, [:name, :post_count]
105
+ association :revisions do
106
+ fields :version_number, :created_at, :update_at
107
+ end
108
+ end
109
+ end
110
+
111
+ #### Defining the columns you want to edit in your form:
112
+
113
+ Pass to the `form_columns` method a list of column that there should be inputs for on the form.
114
+
115
+
116
+ #### Defining associations to manage at the bottom of edit pages:
117
+
118
+ The `form_associations` is used to define the associations you want to manage at the bottom of the edit pages. This method takes a block that is used to define these associations and the columns to display.
119
+
120
+ If you use the `associations` method inside the block then you can define multiple associations at once:
121
+
122
+ form_associations do
123
+ association :tags, :revisions
124
+ end
125
+
126
+ In this case all the `content_columns` for the models will be used as the columns in the association tables. This is probably good for getting started quickly but you'll probably find you quickly outgrow it.
127
+
128
+ You can use individual `association` method calls and pass the list of attributes/methods to use as columns in the table:
129
+
130
+ form_associations do
131
+ association :tags, [:name, :post_count]
132
+ end
133
+
134
+ You can also define the columns inside a block passed to the `association` method with a call to the `fields` method:
135
+
136
+ form_associations do
137
+ association :revisions do
138
+ fields :version_number, :created_at, :update_at
139
+ end
140
+ end
141
+
142
+ Or if you prefer you can use multiple calls to the `field` method:
143
+
144
+ form_associations do
145
+ association :revisions do
146
+ field :version_number
147
+ field :created_at
148
+ field :update_at
149
+ end
150
+ end
151
+
152
+ You are also free to mix and match:
153
+
154
+ form_associations do
155
+ association :revisions, [:version_number] do
156
+ fields :created_at, :another_column
157
+ field :update_at
158
+ end
159
+ end
160
+
161
+
162
+ #### Fine grained control over the form:
163
+
164
+ If you want more control over the main part of the form you can define a `active_association_form` which takes a block with 1 parameter (which is the form object):
165
+
166
+ ActiveAdmin.register Post do
167
+ association_actions
168
+
169
+ form :partial => "admin/shared/form"
170
+
171
+ active_association_form do |f|
172
+ f.inputs do
173
+ f.input :title
174
+ f.input :body
175
+ f.input :slug, :label => "This is the value that will be used in the URL bar for the post."
176
+ end
177
+ f.inputs do
178
+ f.input :author, :as => :select
179
+ f.input :published_at
180
+ end
181
+ end
182
+
183
+ form_associations do
184
+ association :tags, [:name, :post_count]
185
+ association :revisions do
186
+ fields :version_number, :created_at, :update_at
187
+ end
188
+ end
189
+ end
190
+
191
+ #### Overriding the templates
192
+
193
+ If this still doesn't give you the power you're looking for you can override any of the partial templates this engine uses.
194
+
195
+ * `admin/shared/_form.html.erb` – you probably don't want to override this one instead you probably want to use your own `_form.html.erb` template in your `app/views/admin/RESOURCE_NAME` directory and have this in your AA resource config: `form :partial => 'form'`. But if you really want to change how all the aa_associations forms look you can.
196
+ * `admin/shared/_collection_tabe.html.erb` – this is how we generate the tables for the `has_many` relationships below the form. Once again not something I'd recommend editing.
197
+ * `admin/shared/_association_collection_table_actions.html.erb` – this defines the actions that you can do on each related record. The default is "edit" and "unrelate". You may want to override this for instance to define different actions for different models.
198
+ * `admin/shared/_add_to_association.html.erb` – This is the form to relate existing records to the parent record.
199
+
200
+
201
+ ## Contributing to ActiveAdmin Associations
202
+
203
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
204
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
205
+ * Fork the project.
206
+ * Start a feature/bugfix branch.
207
+ * Commit and push until you are happy with your contribution.
208
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
209
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
210
+
211
+ ## Copyright
212
+
213
+ Copyright (c) 2012 Brian Landau (Viget). See MIT_LICENSE.txt for further details.
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ Bundler::GemHelper.install_tasks
9
+
10
+ require 'rake/testtask'
11
+ Rake::TestTask.new(:test) do |test|
12
+ test.libs << 'lib' << 'test'
13
+ test.pattern = 'test/**/*_test.rb'
14
+ test.verbose = true
15
+ end
16
+
17
+ task :default => :test
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "active_admin_associations/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "aa_associations"
7
+ s.version = ActiveAdminAssociations::VERSION
8
+ s.authors = ["Brian Landau"]
9
+ s.email = ["brian.landau@viget.com"]
10
+ s.homepage = "http://github.com/vigetlabs/active_admin_associations"
11
+ s.summary = %q{This extends ActiveAdmin to allow for better editing of associations.}
12
+ s.description = %q{This extends ActiveAdmin to allow for better editing of associations.}
13
+ s.date = '2012-05-03'
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+ s.extra_rdoc_files = ["README.md", "MIT_LICENSE.txt"]
20
+
21
+ s.add_dependency 'activeadmin', '~> 0.4'
22
+ s.add_dependency 'rails', '~> 3.1'
23
+
24
+ s.add_development_dependency 'shoulda'
25
+ s.add_development_dependency 'sqlite3'
26
+ s.add_development_dependency 'mocha'
27
+ s.add_development_dependency 'bundler', '~> 1.0'
28
+ s.add_development_dependency 'capybara'
29
+ s.add_development_dependency 'database_cleaner'
30
+ s.add_development_dependency 'factory_girl_rails', '~> 1.7'
31
+ end
@@ -0,0 +1,37 @@
1
+ class AutocompleteController < ApplicationController
2
+ def index
3
+ respond_to do |format|
4
+ format.json {
5
+ render :json => autocomplete_results
6
+ }
7
+ end
8
+ end
9
+
10
+ private
11
+
12
+ def autocomplete_results
13
+ query_term.present? ? model.autocomplete_results(query_term) : []
14
+ end
15
+
16
+ def model
17
+ params[:model].classify.constantize
18
+ end
19
+
20
+ def query_param_name
21
+ if aa_associations_config.autocomplete_query_term_param_names.present?
22
+ aa_associations_config.autocomplete_query_term_param_names.detect do |param_name|
23
+ params.keys.map(&:to_sym).include?(param_name.to_sym)
24
+ end
25
+ else
26
+ :q
27
+ end
28
+ end
29
+
30
+ def query_term
31
+ params[query_param_name]
32
+ end
33
+
34
+ def aa_associations_config
35
+ Rails.application.config.aa_associations
36
+ end
37
+ end
@@ -0,0 +1,77 @@
1
+ module ActiveAdminAssociationsHelper
2
+ def collection_relationship_manager(object, association)
3
+ collection = object.send(association.name).page(1)
4
+ relationship_class = object.class.reflect_on_association(association.name).klass
5
+ columns = association.fields.presence || relationship_class.content_columns
6
+ render :partial => 'admin/shared/collection_table', :locals => {
7
+ :object => object,
8
+ :collection => collection,
9
+ :relationship => association.name,
10
+ :columns => columns,
11
+ :relationship_class => relationship_class
12
+ }
13
+ end
14
+
15
+ def admin_form_for(record)
16
+ active_admin_form_for [:admin, record] do |f|
17
+ f.semantic_errors
18
+ if active_admin_config.form_columns.present?
19
+ f.inputs *active_admin_config.form_columns
20
+ end
21
+ if active_admin_config.active_association_form && active_admin_config.active_association_form.respond_to?(:call)
22
+ active_admin_config.active_association_form.call(f)
23
+ end
24
+ f.buttons
25
+ end
26
+ end
27
+
28
+ def edit_url_for(record)
29
+ send("edit_admin_#{record.class.model_name.singular}_path", record)
30
+ end
31
+
32
+ def display_method_name_for(record)
33
+ Formtastic::FormBuilder.collection_label_methods.find { |m| record.respond_to?(m) }
34
+ end
35
+
36
+ def display_name_for(record)
37
+ record.send(display_method_name_for(record))
38
+ end
39
+
40
+ def resource_administrated?(model_class)
41
+ ActiveAdmin.resources.include?(model_class)
42
+ end
43
+
44
+ def relate_to_url(object)
45
+ send("relate_admin_#{object.class.model_name.singular}_path", object)
46
+ end
47
+
48
+ def page_entries_info(collection, options = {})
49
+ if options[:entry_name]
50
+ entry_name = options[:entry_name]
51
+ entries_name = options[:entries_name]
52
+ elsif collection.empty?
53
+ entry_name = I18n.translate("active_admin.pagination.entry", :count => 1, :default => 'entry')
54
+ entries_name = I18n.translate("active_admin.pagination.entry", :count => 2, :default => 'entries')
55
+ else
56
+ begin
57
+ entry_name = I18n.translate!("activerecord.models.#{collection.first.class.model_name.i18n_key}", :count => 1)
58
+ entries_name = I18n.translate!("activerecord.models.#{collection.first.class.model_name.i18n_key}", :count => collection.size)
59
+ rescue I18n::MissingTranslationData
60
+ entry_name = collection.first.class.name.underscore.sub('_', ' ')
61
+ end
62
+ end
63
+ entries_name = entry_name.pluralize unless entries_name
64
+
65
+ if collection.num_pages < 2
66
+ case collection.size
67
+ when 0; I18n.t('active_admin.pagination.empty', :model => entries_name)
68
+ when 1; I18n.t('active_admin.pagination.one', :model => entry_name)
69
+ else; I18n.t('active_admin.pagination.one_page', :model => entries_name, :n => collection.total_count)
70
+ end
71
+ else
72
+ offset = collection.current_page * collection.size
73
+ total = collection.total_count
74
+ I18n.t('active_admin.pagination.multiple', :model => entries_name, :from => (offset - collection.size + 1), :to => offset > total ? total : offset, :total => total)
75
+ end
76
+ end
77
+ end