activeadmin 1.4.2 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activeadmin might be problematic. Click here for more details.

Files changed (226) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +306 -144
  3. data/CONTRIBUTING.md +21 -16
  4. data/README.md +44 -11
  5. data/app/assets/javascripts/active_admin/base.es6 +23 -0
  6. data/app/assets/javascripts/active_admin/ext/jquery-ui.es6 +7 -0
  7. data/app/assets/javascripts/active_admin/ext/jquery.es6 +9 -0
  8. data/app/assets/javascripts/active_admin/initializers/datepicker.es6 +16 -0
  9. data/app/assets/javascripts/active_admin/initializers/filters.es6 +45 -0
  10. data/app/assets/javascripts/active_admin/initializers/tabs.es6 +6 -0
  11. data/app/assets/javascripts/active_admin/lib/active_admin.es6 +41 -0
  12. data/app/assets/javascripts/active_admin/lib/batch_actions.es6 +59 -0
  13. data/app/assets/javascripts/active_admin/lib/checkbox-toggler.es6 +49 -0
  14. data/app/assets/javascripts/active_admin/lib/dropdown-menu.es6 +123 -0
  15. data/app/assets/javascripts/active_admin/lib/has_many.es6 +95 -0
  16. data/app/assets/javascripts/active_admin/lib/modal_dialog.es6 +61 -0
  17. data/app/assets/javascripts/active_admin/lib/per_page.es6 +47 -0
  18. data/app/assets/javascripts/active_admin/lib/table-checkbox-toggler.es6 +36 -0
  19. data/app/assets/stylesheets/active_admin/_forms.scss +2 -14
  20. data/app/assets/stylesheets/active_admin/components/_status_tags.scss +0 -5
  21. data/app/assets/stylesheets/active_admin/components/_tabs.scss +1 -1
  22. data/app/assets/stylesheets/active_admin/mixins/_gradients.scss +1 -1
  23. data/app/views/active_admin/devise/confirmations/new.html.erb +1 -1
  24. data/app/views/active_admin/devise/passwords/edit.html.erb +1 -1
  25. data/app/views/active_admin/devise/passwords/new.html.erb +1 -1
  26. data/app/views/active_admin/devise/registrations/new.html.erb +1 -2
  27. data/app/views/active_admin/devise/shared/_error_messages.html.erb +15 -0
  28. data/app/views/active_admin/devise/unlocks/new.html.erb +1 -1
  29. data/app/views/kaminari/active_admin_countless/_first_page.html.erb +11 -0
  30. data/app/views/kaminari/active_admin_countless/_gap.html.erb +8 -0
  31. data/app/views/kaminari/active_admin_countless/_next_page.html.erb +11 -0
  32. data/app/views/kaminari/active_admin_countless/_page.html.erb +12 -0
  33. data/app/views/kaminari/active_admin_countless/_paginator.html.erb +24 -0
  34. data/app/views/kaminari/active_admin_countless/_prev_page.html.erb +11 -0
  35. data/app/views/layouts/active_admin_logged_out.html.erb +1 -1
  36. data/config/locales/ar.yml +3 -2
  37. data/config/locales/bg.yml +1 -1
  38. data/config/locales/bs.yml +1 -0
  39. data/config/locales/ca.yml +1 -1
  40. data/config/locales/cs.yml +1 -0
  41. data/config/locales/da.yml +1 -0
  42. data/config/locales/de-CH.yml +1 -0
  43. data/config/locales/de.yml +1 -0
  44. data/config/locales/el.yml +1 -0
  45. data/config/locales/en-CA.yml +1 -0
  46. data/config/locales/en-GB.yml +1 -0
  47. data/config/locales/en.yml +1 -0
  48. data/config/locales/eo.yml +1 -0
  49. data/config/locales/es-MX.yml +1 -0
  50. data/config/locales/es.yml +1 -0
  51. data/config/locales/fa.yml +1 -0
  52. data/config/locales/fi.yml +1 -0
  53. data/config/locales/fr.yml +2 -1
  54. data/config/locales/he.yml +1 -1
  55. data/config/locales/hr.yml +1 -0
  56. data/config/locales/hu.yml +5 -0
  57. data/config/locales/id.yml +1 -0
  58. data/config/locales/it.yml +1 -0
  59. data/config/locales/ja.yml +1 -0
  60. data/config/locales/ko.yml +1 -0
  61. data/config/locales/lt.yml +3 -2
  62. data/config/locales/lv.yml +1 -0
  63. data/config/locales/mk.yml +134 -0
  64. data/config/locales/nb.yml +1 -0
  65. data/config/locales/nl.yml +1 -0
  66. data/config/locales/pl.yml +1 -0
  67. data/config/locales/pt-BR.yml +1 -0
  68. data/config/locales/pt-PT.yml +1 -0
  69. data/config/locales/ro.yml +1 -0
  70. data/config/locales/ru.yml +1 -0
  71. data/config/locales/sk.yml +1 -0
  72. data/config/locales/sv-SE.yml +1 -0
  73. data/config/locales/tr.yml +1 -0
  74. data/config/locales/uk.yml +3 -0
  75. data/config/locales/vi.yml +1 -0
  76. data/config/locales/zh-CN.yml +1 -0
  77. data/config/locales/zh-TW.yml +1 -0
  78. data/docs/0-installation.md +2 -2
  79. data/docs/12-arbre-components.md +13 -0
  80. data/docs/13-authorization-adapter.md +6 -6
  81. data/docs/2-resource-customization.md +1 -1
  82. data/docs/3-index-pages/index-as-table.md +7 -0
  83. data/docs/CNAME +1 -1
  84. data/docs/Gemfile +0 -1
  85. data/docs/Gemfile.lock +3 -4
  86. data/docs/_config.yml +2 -0
  87. data/docs/_includes/top-menu.html +2 -2
  88. data/docs/index.html +109 -8
  89. data/docs/stylesheets/main.css +29 -0
  90. data/lib/active_admin.rb +10 -4
  91. data/lib/active_admin/application.rb +11 -18
  92. data/lib/active_admin/application_settings.rb +3 -0
  93. data/lib/active_admin/asset_registration.rb +0 -8
  94. data/lib/active_admin/base_controller.rb +6 -6
  95. data/lib/active_admin/base_controller/authorization.rb +3 -4
  96. data/lib/active_admin/batch_actions/controller.rb +2 -2
  97. data/lib/active_admin/batch_actions/resource_extension.rb +9 -5
  98. data/lib/active_admin/callbacks.rb +1 -1
  99. data/lib/active_admin/controller_action.rb +2 -1
  100. data/lib/active_admin/csv_builder.rb +4 -3
  101. data/lib/active_admin/dependency.rb +3 -75
  102. data/lib/active_admin/dsl.rb +1 -8
  103. data/lib/active_admin/error.rb +4 -2
  104. data/lib/active_admin/filters/active_filter.rb +5 -4
  105. data/lib/active_admin/filters/active_sidebar.rb +5 -1
  106. data/lib/active_admin/filters/forms.rb +2 -2
  107. data/lib/active_admin/filters/formtastic_addons.rb +1 -1
  108. data/lib/active_admin/filters/resource_extension.rb +3 -3
  109. data/lib/active_admin/form_builder.rb +3 -3
  110. data/lib/active_admin/generators/boilerplate.rb +12 -4
  111. data/lib/active_admin/helpers/scope_chain.rb +1 -0
  112. data/lib/active_admin/inputs/datepicker_input.rb +1 -1
  113. data/lib/active_admin/inputs/filters/base/search_method_select.rb +2 -2
  114. data/lib/active_admin/menu_item.rb +1 -1
  115. data/lib/active_admin/namespace.rb +2 -2
  116. data/lib/active_admin/namespace_settings.rb +7 -4
  117. data/lib/active_admin/orm/active_record/comments.rb +4 -4
  118. data/lib/active_admin/orm/active_record/comments/comment.rb +2 -2
  119. data/lib/active_admin/orm/active_record/comments/views/active_admin_comments.rb +10 -5
  120. data/lib/active_admin/page_dsl.rb +1 -1
  121. data/lib/active_admin/page_presenter.rb +2 -1
  122. data/lib/active_admin/pundit_adapter.rb +18 -5
  123. data/lib/active_admin/resource.rb +17 -3
  124. data/lib/active_admin/resource/action_items.rb +1 -1
  125. data/lib/active_admin/resource/attributes.rb +7 -4
  126. data/lib/active_admin/resource/belongs_to.rb +6 -1
  127. data/lib/active_admin/resource/menu.rb +3 -3
  128. data/lib/active_admin/resource/model.rb +15 -0
  129. data/lib/active_admin/resource/naming.rb +3 -3
  130. data/lib/active_admin/resource/routes.rb +20 -7
  131. data/lib/active_admin/resource/scopes.rb +3 -3
  132. data/lib/active_admin/resource/sidebars.rb +1 -1
  133. data/lib/active_admin/resource_collection.rb +2 -2
  134. data/lib/active_admin/resource_controller.rb +2 -0
  135. data/lib/active_admin/resource_controller/action_builder.rb +10 -0
  136. data/lib/active_admin/resource_controller/polymorphic_routes.rb +36 -0
  137. data/lib/active_admin/resource_controller/resource_class_methods.rb +2 -0
  138. data/lib/active_admin/resource_controller/scoping.rb +1 -1
  139. data/lib/active_admin/resource_dsl.rb +6 -4
  140. data/lib/active_admin/router.rb +3 -2
  141. data/lib/active_admin/scope.rb +11 -7
  142. data/lib/active_admin/settings_node.rb +1 -1
  143. data/lib/active_admin/sidebar_section.rb +3 -1
  144. data/lib/active_admin/version.rb +1 -1
  145. data/lib/active_admin/view_helpers.rb +1 -1
  146. data/lib/active_admin/view_helpers/breadcrumb_helper.rb +2 -2
  147. data/lib/active_admin/view_helpers/display_helper.rb +13 -4
  148. data/lib/active_admin/view_helpers/download_format_links_helper.rb +1 -0
  149. data/lib/active_admin/view_helpers/method_or_proc_helper.rb +3 -0
  150. data/lib/active_admin/views.rb +1 -1
  151. data/lib/active_admin/views/components/active_admin_form.rb +7 -1
  152. data/lib/active_admin/views/components/attributes_table.rb +3 -3
  153. data/lib/active_admin/views/components/paginated_collection.rb +2 -2
  154. data/lib/active_admin/views/components/sidebar_section.rb +0 -3
  155. data/lib/active_admin/views/components/status_tag.rb +6 -19
  156. data/lib/active_admin/views/components/table_for.rb +2 -2
  157. data/lib/active_admin/views/components/tabs.rb +11 -2
  158. data/lib/active_admin/views/footer.rb +1 -1
  159. data/lib/active_admin/views/index_as_table.rb +12 -4
  160. data/lib/active_admin/views/pages/base.rb +3 -0
  161. data/lib/generators/active_admin/assets/assets_generator.rb +2 -2
  162. data/lib/generators/active_admin/assets/templates/active_admin.js +1 -0
  163. data/lib/generators/active_admin/install/install_generator.rb +6 -2
  164. data/lib/generators/active_admin/install/templates/active_admin.rb.erb +24 -2
  165. data/lib/generators/active_admin/install/templates/dashboard.rb +2 -3
  166. data/lib/generators/active_admin/install/templates/migrations/create_active_admin_comments.rb.erb +1 -15
  167. data/lib/generators/active_admin/page/page_generator.rb +1 -1
  168. data/lib/generators/active_admin/resource/resource_generator.rb +1 -1
  169. data/lib/generators/active_admin/resource/templates/admin.rb.erb +40 -37
  170. data/lib/ransack_ext.rb +3 -3
  171. data/vendor/assets/javascripts/jquery-ui/form-reset-mixin.js +80 -0
  172. data/vendor/assets/javascripts/jquery-ui/form.js +22 -0
  173. data/vendor/assets/javascripts/jquery-ui/labels.js +65 -0
  174. data/vendor/assets/javascripts/jquery-ui/widgets/checkboxradio.js +274 -283
  175. metadata +113 -100
  176. data/.circleci/config.yml +0 -467
  177. data/.github/ISSUE_TEMPLATE.md +0 -20
  178. data/.gitignore +0 -46
  179. data/.mdlrc +0 -1
  180. data/.rspec +0 -1
  181. data/.rspec_parallel +0 -2
  182. data/.rubocop.yml +0 -94
  183. data/.simplecov +0 -11
  184. data/.yardopts +0 -7
  185. data/Gemfile +0 -10
  186. data/Gemfile.common +0 -53
  187. data/Gemfile.lock +0 -431
  188. data/Rakefile +0 -23
  189. data/activeadmin.gemspec +0 -32
  190. data/app/assets/javascripts/active_admin/base.js.coffee +0 -13
  191. data/app/assets/javascripts/active_admin/ext/jquery-ui.js.coffee +0 -6
  192. data/app/assets/javascripts/active_admin/ext/jquery.js.coffee +0 -7
  193. data/app/assets/javascripts/active_admin/initializers/batch_actions.js.coffee +0 -11
  194. data/app/assets/javascripts/active_admin/initializers/datepicker.js.coffee +0 -14
  195. data/app/assets/javascripts/active_admin/initializers/filters.js.coffee +0 -26
  196. data/app/assets/javascripts/active_admin/initializers/tabs.js.coffee +0 -7
  197. data/app/assets/javascripts/active_admin/lib/batch_actions.js.coffee +0 -42
  198. data/app/assets/javascripts/active_admin/lib/checkbox-toggler.js.coffee +0 -46
  199. data/app/assets/javascripts/active_admin/lib/dropdown-menu.js.coffee +0 -104
  200. data/app/assets/javascripts/active_admin/lib/flash.js.coffee +0 -19
  201. data/app/assets/javascripts/active_admin/lib/has_many.js.coffee +0 -79
  202. data/app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee +0 -45
  203. data/app/assets/javascripts/active_admin/lib/per_page.js.coffee +0 -46
  204. data/app/assets/javascripts/active_admin/lib/table-checkbox-toggler.js.coffee +0 -22
  205. data/bin/install_chromedriver.sh +0 -17
  206. data/codecov.yml +0 -25
  207. data/config/i18n-tasks.yml +0 -26
  208. data/config/mdl_style.rb +0 -11
  209. data/cucumber.yml +0 -7
  210. data/gemfiles/rails_42.gemfile +0 -10
  211. data/gemfiles/rails_42.gemfile.lock +0 -410
  212. data/gemfiles/rails_50.gemfile +0 -10
  213. data/gemfiles/rails_50.gemfile.lock +0 -424
  214. data/gemfiles/rails_51.gemfile +0 -10
  215. data/gemfiles/rails_51.gemfile.lock +0 -423
  216. data/lib/active_admin/event.rb +0 -24
  217. data/lib/active_admin/helpers/output_safety_helper.rb +0 -35
  218. data/lib/active_admin/reloader.rb +0 -25
  219. data/lib/bug_report_templates/active_admin_master.rb +0 -111
  220. data/lib/generators/active_admin/assets/templates/active_admin.js.coffee +0 -1
  221. data/tasks/application_generator.rb +0 -48
  222. data/tasks/docs.rake +0 -64
  223. data/tasks/gemfiles.rake +0 -8
  224. data/tasks/lint.rake +0 -110
  225. data/tasks/local.rake +0 -27
  226. data/tasks/test.rake +0 -43
@@ -87,7 +87,7 @@ module ActiveAdmin
87
87
  if controller.action_methods.include?('destroy') && authorized?(ActiveAdmin::Auth::DESTROY, resource)
88
88
  localizer = ActiveAdmin::Localizers.resource(active_admin_config)
89
89
  link_to localizer.t(:delete_model), resource_path(resource), method: :delete,
90
- data: {confirm: localizer.t(:delete_confirmation)}
90
+ data: { confirm: localizer.t(:delete_confirmation) }
91
91
  end
92
92
  end
93
93
  end
@@ -18,13 +18,13 @@ module ActiveAdmin
18
18
 
19
19
  def foreign_methods
20
20
  @foreign_methods ||= resource_class.reflect_on_all_associations.
21
- select{ |r| r.macro == :belongs_to }.
22
- reject{ |r| r.chain.length > 2 && !r.options[:polymorphic] }.
23
- index_by{ |r| r.foreign_key.to_sym }
21
+ select { |r| r.macro == :belongs_to }.
22
+ reject { |r| r.chain.length > 2 && !r.options[:polymorphic] }.
23
+ index_by { |r| r.foreign_key.to_sym }
24
24
  end
25
25
 
26
26
  def reject_col?(c)
27
- primary_col?(c) || sti_col?(c) || counter_cache_col?(c)
27
+ primary_col?(c) || sti_col?(c) || counter_cache_col?(c) || filtered_col?(c)
28
28
  end
29
29
 
30
30
  def primary_col?(c)
@@ -39,6 +39,9 @@ module ActiveAdmin
39
39
  c.name.end_with?('_count')
40
40
  end
41
41
 
42
+ def filtered_col?(c)
43
+ ActiveAdmin.application.filter_attributes.include?(c.name.to_sym)
44
+ end
42
45
  end
43
46
  end
44
47
  end
@@ -14,8 +14,13 @@ module ActiveAdmin
14
14
  # The resource which initiated this relationship
15
15
  attr_reader :owner
16
16
 
17
+ # The name of the relation
18
+ attr_reader :target_name
19
+
17
20
  def initialize(owner, target_name, options = {})
18
- @owner, @target_name, @options = owner, target_name, options
21
+ @owner = owner
22
+ @target_name = target_name
23
+ @options = options
19
24
  end
20
25
 
21
26
  # Returns the target resource class or raises an exception if it doesn't exist
@@ -26,9 +26,9 @@ module ActiveAdmin
26
26
  resource = self
27
27
  {
28
28
  id: resource_name.plural,
29
- label: proc{ resource.plural_resource_label },
30
- url: proc{ resource.route_collection_path(params, url_options) },
31
- if: proc{ authorized?(Auth::READ, menu_resource_class) }
29
+ label: proc { resource.plural_resource_label },
30
+ url: proc { resource.route_collection_path(params, url_options) },
31
+ if: proc { authorized?(Auth::READ, menu_resource_class) }
32
32
  }
33
33
  end
34
34
 
@@ -0,0 +1,15 @@
1
+ module ActiveAdmin
2
+ class Model
3
+ def initialize(resource, record)
4
+ @record = record
5
+
6
+ if resource
7
+ @record.extend(resource.resource_name_extension)
8
+ end
9
+ end
10
+
11
+ def to_model
12
+ @record
13
+ end
14
+ end
15
+ end
@@ -22,8 +22,8 @@ module ActiveAdmin
22
22
 
23
23
  # Returns the plural version of this resource such as "Bank Accounts"
24
24
  def plural_resource_label(options = {})
25
- defaults = {count: Helpers::I18n::PLURAL_MANY_COUNT,
26
- default: resource_label.pluralize.titleize}
25
+ defaults = { count: Helpers::I18n::PLURAL_MANY_COUNT,
26
+ default: resource_label.pluralize.titleize }
27
27
  resource_name.translate defaults.merge options
28
28
  end
29
29
 
@@ -46,7 +46,7 @@ module ActiveAdmin
46
46
  end
47
47
 
48
48
  def translate(options = {})
49
- I18n.t i18n_key, {scope: [:activerecord, :models]}.merge(options)
49
+ I18n.t i18n_key, { scope: [:activerecord, :models] }.merge(options)
50
50
  end
51
51
 
52
52
  def route_key
@@ -20,7 +20,11 @@ module ActiveAdmin
20
20
  end
21
21
 
22
22
  def route_edit_instance_path(resource, additional_params = {})
23
- route_builder.edit_instance_path(resource, additional_params)
23
+ route_builder.member_action_path(:edit, resource, additional_params)
24
+ end
25
+
26
+ def route_member_action_path(action, resource, additional_params = {})
27
+ route_builder.member_action_path(action, resource, additional_params)
24
28
  end
25
29
 
26
30
  # Returns the routes prefix for this config
@@ -75,12 +79,13 @@ module ActiveAdmin
75
79
  routes.public_send route_name, *route_instance_params(instance), additional_params
76
80
  end
77
81
 
78
- # @return [String] the path to the edit page of this resource
82
+ # @return [String] the path to the member action of this resource
83
+ # @param action [Symbol]
79
84
  # @param instance [ActiveRecord::Base] the instance we want the path of
80
85
  # @example "/admin/posts/1/edit"
81
- def edit_instance_path(instance, additional_params = {})
86
+ def member_action_path(action, instance, additional_params = {})
82
87
  path = resource.resources_configuration[:self][:route_instance_name]
83
- route_name = route_name(path, action: :edit)
88
+ route_name = route_name(path, action: action)
84
89
 
85
90
  routes.public_send route_name, *route_instance_params(instance), additional_params
86
91
  end
@@ -105,7 +110,7 @@ module ActiveAdmin
105
110
  # @return params to pass to instance path
106
111
  def route_instance_params(instance)
107
112
  if nested?
108
- [instance.public_send(belongs_to_name).to_param, instance.to_param]
113
+ [instance.public_send(belongs_to_target_name).to_param, instance.to_param]
109
114
  else
110
115
  instance.to_param
111
116
  end
@@ -118,11 +123,19 @@ module ActiveAdmin
118
123
  end
119
124
 
120
125
  def nested?
121
- resource.belongs_to? && resource.belongs_to_config.required?
126
+ resource.belongs_to? && belongs_to_config.required?
127
+ end
128
+
129
+ def belongs_to_target_name
130
+ belongs_to_config.target_name
122
131
  end
123
132
 
124
133
  def belongs_to_name
125
- resource.belongs_to_config.target.resource_name.singular if nested?
134
+ belongs_to_config.target.resource_name.singular
135
+ end
136
+
137
+ def belongs_to_config
138
+ resource.belongs_to_config
126
139
  end
127
140
 
128
141
  def routes
@@ -10,7 +10,7 @@ module ActiveAdmin
10
10
  # Returns a scope for this object by its identifier
11
11
  def get_scope_by_id(id)
12
12
  id = id.to_s
13
- scopes.find{|s| s.id == id }
13
+ scopes.find { |s| s.id == id }
14
14
  end
15
15
 
16
16
  def default_scope(context = nil)
@@ -27,7 +27,7 @@ module ActiveAdmin
27
27
  # If you want to internationalize the scope name, you can add
28
28
  # to your i18n files a key like "active_admin.scopes.scope_method".
29
29
  def scope(*args, &block)
30
- default_options = {show_count: namespace.scopes_show_count}
30
+ default_options = { show_count: namespace.scopes_show_count }
31
31
  options = default_options.merge(args.extract_options!)
32
32
  title = args[0] rescue nil
33
33
  method = args[1] rescue nil
@@ -36,7 +36,7 @@ module ActiveAdmin
36
36
  scope = ActiveAdmin::Scope.new(title, method, options, &block)
37
37
 
38
38
  # Finds and replaces a scope by the same name if it already exists
39
- existing_scope_index = scopes.index{|existing_scope| existing_scope.id == scope.id }
39
+ existing_scope_index = scopes.index { |existing_scope| existing_scope.id == scope.id }
40
40
  if existing_scope_index
41
41
  scopes.delete_at(existing_scope_index)
42
42
  scopes.insert(existing_scope_index, scope)
@@ -14,7 +14,7 @@ module ActiveAdmin
14
14
  end
15
15
 
16
16
  def sidebar_sections_for(action, render_context = nil)
17
- sidebar_sections.select{|section| section.display_on?(action, render_context) }
17
+ sidebar_sections.select { |section| section.display_on?(action, render_context) }
18
18
  .sort_by(&:priority)
19
19
  end
20
20
 
@@ -38,12 +38,12 @@ module ActiveAdmin
38
38
  r.resource_class.to_s == obj.to_s
39
39
  end ||
40
40
  if obj.respond_to? :base_class
41
- resources.detect{ |r| r.resource_class.to_s == obj.base_class.to_s }
41
+ resources.detect { |r| r.resource_class.to_s == obj.base_class.to_s }
42
42
  end
43
43
  end
44
44
 
45
45
  def resources
46
- select{ |r| r.class <= Resource } # can otherwise be a Page
46
+ select { |r| r.class <= Resource } # can otherwise be a Page
47
47
  end
48
48
 
49
49
  def raise_if_mismatched!(existing, given)
@@ -1,6 +1,7 @@
1
1
  require 'active_admin/resource_controller/action_builder'
2
2
  require 'active_admin/resource_controller/data_access'
3
3
  require 'active_admin/resource_controller/decorators'
4
+ require 'active_admin/resource_controller/polymorphic_routes'
4
5
  require 'active_admin/resource_controller/scoping'
5
6
  require 'active_admin/resource_controller/streaming'
6
7
  require 'active_admin/resource_controller/sidebars'
@@ -18,6 +19,7 @@ module ActiveAdmin
18
19
  include ActionBuilder
19
20
  include Decorators
20
21
  include DataAccess
22
+ include PolymorphicRoutes
21
23
  include Scoping
22
24
  include Streaming
23
25
  include Sidebars
@@ -7,12 +7,22 @@ module ActiveAdmin
7
7
  module ClassMethods
8
8
 
9
9
  def clear_member_actions!
10
+ remove_action_methods(:member)
10
11
  active_admin_config.clear_member_actions!
11
12
  end
12
13
 
13
14
  def clear_collection_actions!
15
+ remove_action_methods(:collection)
14
16
  active_admin_config.clear_collection_actions!
15
17
  end
18
+
19
+ private
20
+
21
+ def remove_action_methods(actions_type)
22
+ active_admin_config.public_send("#{actions_type}_actions").each do |action|
23
+ remove_method action.name
24
+ end
25
+ end
16
26
  end
17
27
 
18
28
  end
@@ -0,0 +1,36 @@
1
+ require "active_admin/resource"
2
+ require "active_admin/resource/model"
3
+
4
+ module ActiveAdmin
5
+ class ResourceController < BaseController
6
+ module PolymorphicRoutes
7
+ def polymorphic_url(record_or_hash_or_array, options = {})
8
+ super(map_named_resources_for(record_or_hash_or_array), options)
9
+ end
10
+
11
+ def polymorphic_path(record_or_hash_or_array, options = {})
12
+ super(map_named_resources_for(record_or_hash_or_array), options)
13
+ end
14
+
15
+ private
16
+
17
+ def map_named_resources_for(record_or_hash_or_array)
18
+ return record_or_hash_or_array unless record_or_hash_or_array.is_a?(Array)
19
+
20
+ record_or_hash_or_array.map { |record| to_named_resource(record) }
21
+ end
22
+
23
+ def to_named_resource(record)
24
+ if record.is_a?(resource_class)
25
+ return ActiveAdmin::Model.new(active_admin_config, record)
26
+ end
27
+
28
+ if record.is_a?(parent.class)
29
+ return ActiveAdmin::Model.new(active_admin_config.belongs_to_config.resource, record)
30
+ end
31
+
32
+ record
33
+ end
34
+ end
35
+ end
36
+ end
@@ -13,6 +13,8 @@ module ActiveAdmin
13
13
  @active_admin_config ? @active_admin_config.resource_class : nil
14
14
  end
15
15
 
16
+ private
17
+
16
18
  def resource_class
17
19
  self.class.resource_class
18
20
  end
@@ -15,7 +15,7 @@ module ActiveAdmin
15
15
  # Collection can be scoped conditionally with an :if or :unless proc.
16
16
  def begin_of_association_chain
17
17
  return nil unless active_admin_config.scope_to?(self)
18
- StringSymbolOrProcSetting.new(active_admin_config.scope_to_method).value(self)
18
+ MethodOrProcHelper.render_in_context(self, active_admin_config.scope_to_method)
19
19
  end
20
20
 
21
21
  # Overriding from InheritedResources::BaseHelpers
@@ -74,6 +74,8 @@ module ActiveAdmin
74
74
 
75
75
  params.permit(*permitted_params, param_key => block ? instance_exec(&block) : args)
76
76
  end
77
+
78
+ private :permitted_params
77
79
  end
78
80
  end
79
81
 
@@ -119,7 +121,7 @@ module ActiveAdmin
119
121
  #
120
122
  # ActiveAdmin.register Post do
121
123
  # member_action :comments do
122
- # @post = Post.find(params[:id]
124
+ # @post = Post.find(params[:id])
123
125
  # @comments = @post.comments
124
126
  # end
125
127
  # end
@@ -131,14 +133,14 @@ module ActiveAdmin
131
133
  # action.
132
134
  #
133
135
  def action(set, name, options = {}, &block)
134
- warn "Warning: method `#{name}` already defined" if controller.method_defined?(name)
136
+ warn "Warning: method `#{name}` already defined in #{controller.name}" if controller.method_defined?(name)
135
137
 
136
138
  set << ControllerAction.new(name, options)
137
139
  title = options.delete(:title)
138
140
 
139
141
  controller do
140
142
  before_action(only: [name]) { @page_title = title } if title
141
- define_method(name, &block || Proc.new{})
143
+ define_method(name, &block || Proc.new {})
142
144
  end
143
145
  end
144
146
 
@@ -187,7 +189,7 @@ module ActiveAdmin
187
189
  delegate :before_save, :after_save, to: :controller
188
190
  delegate :before_destroy, :after_destroy, to: :controller
189
191
 
190
- # This code defines both *_filter and *_action for Rails 4.0 to Rails 5 and *_action for Rails >= 5.1
192
+ # This code defines both *_filter and *_action for Rails 5.0 and *_action for Rails >= 5.1
191
193
  phases = [
192
194
  :before, :skip_before,
193
195
  :after, :skip_after,
@@ -4,7 +4,8 @@ module ActiveAdmin
4
4
  attr_reader :namespaces, :router
5
5
 
6
6
  def initialize(router:, namespaces:)
7
- @router, @namespaces = router, namespaces
7
+ @router = router
8
+ @namespaces = namespaces
8
9
  end
9
10
 
10
11
  def apply
@@ -28,7 +29,7 @@ module ActiveAdmin
28
29
 
29
30
  # Defines the routes for each resource
30
31
  def define_resources_routes
31
- resources = namespaces.flat_map{ |n| n.resources.values }
32
+ resources = namespaces.flat_map { |n| n.resources.values }
32
33
  resources.each do |config|
33
34
  define_resource_routes(config)
34
35
  end
@@ -28,23 +28,27 @@ module ActiveAdmin
28
28
  # # => Scope with the group :status
29
29
  #
30
30
  def initialize(name, method = nil, options = {}, &block)
31
- @name, @scope_method = name, method.try(:to_sym)
31
+ @name = name
32
+ @scope_method = method.try(:to_sym)
32
33
 
33
34
  if name.is_a? Proc
34
35
  raise "A string/symbol is required as the second argument if your label is a proc." unless method
35
- @id = ActiveAdmin::Dependency.rails.parameterize method.to_s
36
+ @id = method.to_s.parameterize(separator: "_")
36
37
  else
37
38
  @scope_method ||= name.to_sym
38
- @id = ActiveAdmin::Dependency.rails.parameterize name.to_s
39
+ @id = name.to_s.parameterize(separator: "_")
39
40
  end
40
41
 
41
- @scope_method = nil if @scope_method == :all
42
- @scope_method, @scope_block = nil, block if block_given?
42
+ @scope_method = nil if @scope_method == :all
43
+ if block_given?
44
+ @scope_method = nil
45
+ @scope_block = block
46
+ end
43
47
 
44
48
  @localizer = options[:localizer]
45
49
  @show_count = options.fetch(:show_count, true)
46
- @display_if_block = options[:if] || proc{ true }
47
- @default_block = options[:default] || proc{ false }
50
+ @display_if_block = options[:if] || proc { true }
51
+ @default_block = options[:default] || proc { false }
48
52
  @group = options[:group].try(:to_sym)
49
53
  end
50
54
 
@@ -5,7 +5,7 @@ module ActiveAdmin
5
5
  # Never instantiated. Variables are stored in the singleton_class.
6
6
  private_class_method :new
7
7
 
8
- # @returns anonymous class with same accessors as the superclass.
8
+ # @return anonymous class with same accessors as the superclass.
9
9
  def build(superclass = self)
10
10
  Class.new(superclass)
11
11
  end
@@ -6,7 +6,9 @@ module ActiveAdmin
6
6
  attr_accessor :name, :options, :block
7
7
 
8
8
  def initialize(name, options = {}, &block)
9
- @name, @options, @block = name.to_s, options, block
9
+ @name = name.to_s
10
+ @options = options
11
+ @block = block
10
12
  normalize_display_options!
11
13
  end
12
14
 
@@ -1,3 +1,3 @@
1
1
  module ActiveAdmin
2
- VERSION = '1.4.2'
2
+ VERSION = '2.3.0'
3
3
  end
@@ -2,7 +2,7 @@ module ActiveAdmin
2
2
  module ViewHelpers
3
3
 
4
4
  # Require all ruby files in the view helpers dir
5
- Dir[File.expand_path('../view_helpers', __FILE__) + "/*.rb"].each{|f| require f }
5
+ Dir[File.expand_path('view_helpers', __dir__) + "/*.rb"].each { |f| require f }
6
6
 
7
7
  include ActiveAdminApplicationHelper
8
8
  include AutoLinkHelper