activeadmin 2.6.0 → 2.8.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.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +90 -7
  3. data/CONTRIBUTING.md +5 -33
  4. data/README.md +1 -1
  5. data/app/assets/javascripts/active_admin/base.js +13 -15
  6. data/app/assets/stylesheets/active_admin/_header.scss +37 -3
  7. data/app/assets/stylesheets/active_admin/components/_comments.scss +2 -2
  8. data/app/assets/stylesheets/active_admin/mixins/_variables.scss +3 -0
  9. data/app/javascript/active_admin/initializers/per-page.js +1 -1
  10. data/app/javascript/active_admin/lib/checkbox-toggler.js +3 -3
  11. data/app/javascript/active_admin/lib/dropdown-menu.js +1 -1
  12. data/app/javascript/active_admin/lib/modal-dialog.js +7 -7
  13. data/app/javascript/active_admin/lib/per-page.js +1 -1
  14. data/app/javascript/active_admin/lib/table-checkbox-toggler.js +1 -1
  15. data/app/views/layouts/active_admin_logged_out.html.erb +15 -5
  16. data/config/locales/ar.yml +6 -6
  17. data/config/locales/en-CA.yml +3 -3
  18. data/config/locales/en-GB.yml +3 -3
  19. data/config/locales/en.yml +3 -3
  20. data/config/locales/es-MX.yml +2 -1
  21. data/config/locales/es.yml +2 -2
  22. data/config/locales/it.yml +18 -0
  23. data/config/locales/ja.yml +3 -3
  24. data/config/locales/lv.yml +2 -2
  25. data/config/locales/vi.yml +6 -5
  26. data/docs/0-installation.md +26 -2
  27. data/docs/11-decorators.md +16 -5
  28. data/docs/2-resource-customization.md +10 -1
  29. data/docs/Gemfile.lock +42 -31
  30. data/docs/_includes/top-menu.html +1 -1
  31. data/docs/documentation.md +1 -1
  32. data/docs/index.html +6 -6
  33. data/lib/active_admin/application.rb +6 -6
  34. data/lib/active_admin/authorization_adapter.rb +3 -3
  35. data/lib/active_admin/base_controller/authorization.rb +9 -9
  36. data/lib/active_admin/batch_actions/controller.rb +3 -3
  37. data/lib/active_admin/batch_actions/views/batch_action_form.rb +1 -1
  38. data/lib/active_admin/batch_actions/views/batch_action_selector.rb +5 -5
  39. data/lib/active_admin/collection_decorator.rb +31 -0
  40. data/lib/active_admin/csv_builder.rb +11 -7
  41. data/lib/active_admin/dependency.rb +7 -7
  42. data/lib/active_admin/filters/forms.rb +3 -3
  43. data/lib/active_admin/filters/resource_extension.rb +1 -1
  44. data/lib/active_admin/filters.rb +1 -1
  45. data/lib/active_admin/form_builder.rb +5 -5
  46. data/lib/active_admin/helpers/optional_display.rb +2 -2
  47. data/lib/active_admin/inputs/filters/base/search_method_select.rb +2 -2
  48. data/lib/active_admin/localizers/resource_localizer.rb +1 -1
  49. data/lib/active_admin/menu.rb +5 -2
  50. data/lib/active_admin/menu_item.rb +7 -7
  51. data/lib/active_admin/namespace.rb +7 -7
  52. data/lib/active_admin/namespace_settings.rb +3 -0
  53. data/lib/active_admin/orm/active_record/comments/comment.rb +3 -3
  54. data/lib/active_admin/orm/active_record/comments/views/active_admin_comments.rb +3 -3
  55. data/lib/active_admin/orm/active_record/comments.rb +11 -11
  56. data/lib/active_admin/pundit_adapter.rb +4 -4
  57. data/lib/active_admin/resource/action_items.rb +1 -1
  58. data/lib/active_admin/resource/menu.rb +4 -4
  59. data/lib/active_admin/resource/naming.rb +4 -4
  60. data/lib/active_admin/resource/routes.rb +5 -5
  61. data/lib/active_admin/resource/scope_to.rb +7 -7
  62. data/lib/active_admin/resource_controller/data_access.rb +1 -1
  63. data/lib/active_admin/resource_controller/decorators.rb +5 -25
  64. data/lib/active_admin/resource_controller.rb +4 -3
  65. data/lib/active_admin/resource_dsl.rb +5 -5
  66. data/lib/active_admin/scope.rb +5 -5
  67. data/lib/active_admin/version.rb +1 -1
  68. data/lib/active_admin/view_factory.rb +16 -16
  69. data/lib/active_admin/view_helpers/breadcrumb_helper.rb +1 -1
  70. data/lib/active_admin/view_helpers/display_helper.rb +3 -3
  71. data/lib/active_admin/view_helpers/fields_for.rb +1 -1
  72. data/lib/active_admin/views/components/attributes_table.rb +2 -2
  73. data/lib/active_admin/views/components/dropdown_menu.rb +2 -2
  74. data/lib/active_admin/views/components/index_list.rb +1 -1
  75. data/lib/active_admin/views/components/menu_item.rb +1 -1
  76. data/lib/active_admin/views/components/paginated_collection.rb +14 -14
  77. data/lib/active_admin/views/components/scopes.rb +2 -0
  78. data/lib/active_admin/views/components/table_for.rb +11 -11
  79. data/lib/active_admin/views/components/tabs.rb +1 -1
  80. data/lib/active_admin/views/index_as_table.rb +6 -6
  81. data/lib/active_admin/views/pages/base.rb +4 -2
  82. data/lib/active_admin/views/pages/index.rb +8 -8
  83. data/lib/active_admin.rb +43 -43
  84. data/lib/generators/active_admin/assets/templates/active_admin.scss +2 -2
  85. data/lib/generators/active_admin/devise/devise_generator.rb +4 -4
  86. data/lib/generators/active_admin/install/install_generator.rb +7 -1
  87. data/lib/generators/active_admin/install/templates/active_admin.rb.erb +9 -2
  88. data/lib/generators/active_admin/resource/resource_generator.rb +1 -1
  89. data/lib/generators/active_admin/webpacker/plugins/jquery.js +7 -0
  90. data/lib/generators/active_admin/webpacker/templates/active_admin.js +5 -0
  91. data/lib/generators/active_admin/webpacker/templates/active_admin.scss +17 -0
  92. data/lib/generators/active_admin/webpacker/templates/print.scss +2 -0
  93. data/lib/generators/active_admin/webpacker/webpacker_generator.rb +26 -0
  94. metadata +20 -8
@@ -31,17 +31,17 @@ module ActiveAdmin
31
31
  confirmation_text = render_or_call_method_or_proc_on(self, batch_action.confirm)
32
32
 
33
33
  options = {
34
- :class => "batch_action",
35
- "data-action" => batch_action.sym,
36
- "data-confirm" => confirmation_text,
37
- "data-inputs" => render_in_context(self, batch_action.inputs).to_json
34
+ class: "batch_action",
35
+ "data-action": batch_action.sym,
36
+ "data-confirm": confirmation_text,
37
+ "data-inputs": render_in_context(self, batch_action.inputs).to_json
38
38
  }
39
39
 
40
40
  default_title = render_or_call_method_or_proc_on(self, batch_action.title)
41
41
  title = I18n.t("active_admin.batch_actions.labels.#{batch_action.sym}", default: default_title)
42
42
  label = I18n.t("active_admin.batch_actions.action_label", title: title)
43
43
 
44
- item label, "#", options
44
+ item label, "#", **options
45
45
  end
46
46
  end
47
47
  end
@@ -0,0 +1,31 @@
1
+ module ActiveAdmin
2
+ # This class decorates a collection of objects delegating
3
+ # mehods to behave like an Array. It's used to decouple ActiveAdmin
4
+ # from Draper and thus being able to use PORO decorators as well.
5
+ #
6
+ # It's implementation is heavily based on the Draper::CollectionDecorator
7
+ # https://github.com/drapergem/draper/blob/aaa06bd2f1e219838b241a5534e7ca513edd1fe2/lib/draper/collection_decorator.rb
8
+ class CollectionDecorator
9
+ # @return the collection being decorated.
10
+ attr_reader :object
11
+
12
+ # @return [Class] the decorator class used to decorate each item, as set by {#initialize}.
13
+ attr_reader :decorator_class
14
+
15
+ array_methods = Array.instance_methods - Object.instance_methods
16
+ delegate :==, :as_json, *array_methods, to: :decorated_collection
17
+
18
+ def initialize(object, with:)
19
+ @object = object
20
+ @decorator_class = with
21
+ end
22
+
23
+ class << self
24
+ alias_method :decorate, :new
25
+ end
26
+
27
+ def decorated_collection
28
+ @decorated_collection ||= object.map { |item| decorator_class.new(item) }
29
+ end
30
+ end
31
+ end
@@ -42,23 +42,23 @@ module ActiveAdmin
42
42
  end
43
43
 
44
44
  def build(controller, csv)
45
- @collection = controller.send :find_collection, except: :pagination
46
- columns = exec_columns controller.view_context
47
- bom = options.delete :byte_order_mark
45
+ @collection = controller.send :find_collection, except: :pagination
46
+ columns = exec_columns controller.view_context
47
+ bom = options.delete :byte_order_mark
48
48
  column_names = options.delete(:column_names) { true }
49
- csv_options = options.except :encoding_options, :humanize_name
49
+ csv_options = options.except :encoding_options, :humanize_name
50
50
 
51
51
  csv << bom if bom
52
52
 
53
53
  if column_names
54
- csv << CSV.generate_line(columns.map { |c| encode c.name, options }, csv_options)
54
+ csv << CSV.generate_line(columns.map { |c| encode c.name, options }, **csv_options)
55
55
  end
56
56
 
57
57
  ActiveRecord::Base.uncached do
58
58
  (1..paginated_collection.total_pages).each do |page|
59
59
  paginated_collection(page).each do |resource|
60
60
  resource = controller.send :apply_decorator, resource
61
- csv << CSV.generate_line(build_row(resource, columns, options), csv_options)
61
+ csv << CSV.generate_line(build_row(resource, columns, options), **csv_options)
62
62
  end
63
63
  end
64
64
  end
@@ -81,7 +81,11 @@ module ActiveAdmin
81
81
 
82
82
  def encode(content, options)
83
83
  if options[:encoding]
84
- content.to_s.encode options[:encoding], options[:encoding_options]
84
+ if options[:encoding_options]
85
+ content.to_s.encode options[:encoding], **options[:encoding_options]
86
+ else
87
+ content.to_s.encode options[:encoding]
88
+ end
85
89
  else
86
90
  content
87
91
  end
@@ -6,22 +6,22 @@ module ActiveAdmin
6
6
 
7
7
  # Provides a clean interface to check for gem dependencies at runtime.
8
8
  #
9
- # ActiveAdmin::Dependency.draper
10
- # => #<ActiveAdmin::Dependency::Matcher for draper 1.2.1>
9
+ # ActiveAdmin::Dependency.rails
10
+ # => #<ActiveAdmin::Dependency::Matcher for rails 6.0.3.2>
11
11
  #
12
- # ActiveAdmin::Dependency.draper?
12
+ # ActiveAdmin::Dependency.rails?
13
13
  # => true
14
14
  #
15
- # ActiveAdmin::Dependency.draper? '>= 1.5.0'
15
+ # ActiveAdmin::Dependency.rails? '>= 6.1'
16
16
  # => false
17
17
  #
18
- # ActiveAdmin::Dependency.draper? '= 1.2.1'
18
+ # ActiveAdmin::Dependency.rails? '= 6.0.3.2'
19
19
  # => true
20
20
  #
21
- # ActiveAdmin::Dependency.draper? '~> 1.2.0'
21
+ # ActiveAdmin::Dependency.rails? '~> 6.0.3'
22
22
  # => true
23
23
  #
24
- # ActiveAdmin::Dependency.rails? '>= 4.2.7', '<= 5.0.2'
24
+ # ActiveAdmin::Dependency.rails? '>= 6.0.3', '<= 6.1.0'
25
25
  # => true
26
26
  #
27
27
  # ActiveAdmin::Dependency.rails! '5'
@@ -51,12 +51,12 @@ module ActiveAdmin
51
51
  html: { class: 'filter_form' } }
52
52
  required = { html: { method: :get },
53
53
  as: :q }
54
- options = defaults.deep_merge(options).deep_merge(required)
54
+ options = defaults.deep_merge(options).deep_merge(required)
55
55
 
56
56
  form_for search, options do |f|
57
57
  filters.each do |attribute, opts|
58
- next if opts.key?(:if) && !call_method_or_proc_on(self, opts[:if])
59
- next if opts.key?(:unless) && call_method_or_proc_on(self, opts[:unless])
58
+ next if opts.key?(:if) && !call_method_or_proc_on(self, opts[:if])
59
+ next if opts.key?(:unless) && call_method_or_proc_on(self, opts[:unless])
60
60
 
61
61
  filter_opts = opts.except(:if, :unless)
62
62
  filter_opts[:input_html] = instance_exec(&filter_opts[:input_html]) if filter_opts[:input_html].is_a?(Proc)
@@ -165,7 +165,7 @@ module ActiveAdmin
165
165
 
166
166
  def filters_sidebar_section
167
167
  ActiveAdmin::SidebarSection.new :filters, only: :index, if: -> { active_admin_config.filters.any? } do
168
- active_admin_filters_form_for assigns[:search], active_admin_config.filters
168
+ active_admin_filters_form_for assigns[:search], **active_admin_config.filters
169
169
  end
170
170
  end
171
171
 
@@ -7,5 +7,5 @@ require 'active_admin/filters/active_sidebar'
7
7
 
8
8
  # Add our Extensions
9
9
  ActiveAdmin::ResourceDSL.send :include, ActiveAdmin::Filters::DSL
10
- ActiveAdmin::Resource.send :include, ActiveAdmin::Filters::ResourceExtension
10
+ ActiveAdmin::Resource.send :include, ActiveAdmin::Filters::ResourceExtension
11
11
  ActiveAdmin::ViewHelpers.send :include, ActiveAdmin::Filters::ViewHelper
@@ -69,7 +69,7 @@ module ActiveAdmin
69
69
  def extract_custom_settings!(options)
70
70
  @heading = options.key?(:heading) ? options.delete(:heading) : default_heading
71
71
  @sortable_column = options.delete(:sortable)
72
- @sortable_start = options.delete(:sortable_start) || 0
72
+ @sortable_start = options.delete(:sortable_start) || 0
73
73
  @new_record = options.key?(:new_record) ? options.delete(:new_record) : true
74
74
  @destroy_option = options.delete(:allow_destroy)
75
75
  options
@@ -111,8 +111,8 @@ module ActiveAdmin
111
111
  end
112
112
  elsif allow_destroy?(form_builder.object)
113
113
  form_builder.input(:_destroy, as: :boolean,
114
- wrapper_html: { class: 'has_many_delete' },
115
- label: I18n.t('active_admin.has_many_delete'))
114
+ wrapper_html: { class: 'has_many_delete' },
115
+ label: I18n.t('active_admin.has_many_delete'))
116
116
  end
117
117
 
118
118
  if sortable_column
@@ -156,8 +156,8 @@ module ActiveAdmin
156
156
 
157
157
  # Capture the ADD JS
158
158
  def js_for_has_many(class_string, &form_block)
159
- assoc_name = assoc_klass.model_name
160
- placeholder = "NEW_#{assoc_name.to_s.underscore.upcase.gsub(/\//, '_')}_RECORD"
159
+ assoc_name = assoc_klass.model_name
160
+ placeholder = "NEW_#{assoc_name.to_s.underscore.upcase.gsub(/\//, '_')}_RECORD"
161
161
  opts = {
162
162
  for: [assoc, assoc_klass.new],
163
163
  class: class_string,
@@ -15,7 +15,7 @@ module ActiveAdmin
15
15
 
16
16
  module OptionalDisplay
17
17
  def display_on?(action, render_context = self)
18
- return false if @options[:only] && !@options[:only].include?(action.to_sym)
18
+ return false if @options[:only] && !@options[:only].include?(action.to_sym)
19
19
  return false if @options[:except] && @options[:except].include?(action.to_sym)
20
20
 
21
21
  case condition = @options[:if]
@@ -31,7 +31,7 @@ module ActiveAdmin
31
31
  private
32
32
 
33
33
  def normalize_display_options!
34
- @options[:only] = Array(@options[:only]) if @options[:only]
34
+ @options[:only] = Array(@options[:only]) if @options[:only]
35
35
  @options[:except] = Array(@options[:except]) if @options[:except]
36
36
  end
37
37
  end
@@ -37,9 +37,9 @@ module ActiveAdmin
37
37
 
38
38
  def to_html
39
39
  input_wrapping do
40
- label_html << # your label
40
+ label_html << # your label
41
41
  select_html << # the dropdown that holds the available search methods
42
- input_html # your input field
42
+ input_html # your input field
43
43
  end
44
44
  end
45
45
 
@@ -21,7 +21,7 @@ module ActiveAdmin
21
21
  scope = options.delete(:scope)
22
22
  specific_key = array_to_key('resources', @model_name, scope, key)
23
23
  defaults = [array_to_key(scope, key), key.to_s.titleize]
24
- ::I18n.t specific_key, options.reverse_merge(model: @model, default: defaults, scope: 'active_admin')
24
+ ::I18n.t specific_key, **options.reverse_merge(model: @model, default: defaults, scope: 'active_admin')
25
25
  end
26
26
  alias_method :t, :translate
27
27
 
@@ -47,7 +47,10 @@ module ActiveAdmin
47
47
  # menu.add parent: 'Dashboard', label: 'My Child Dashboard'
48
48
  #
49
49
  def add(options)
50
- item = if parent = options.delete(:parent)
50
+ parent_chain = Array.wrap(options.delete(:parent))
51
+
52
+ item = if parent = parent_chain.shift
53
+ options[:parent] = parent_chain if parent_chain.any?
51
54
  (self[parent] || add(label: parent)).add options
52
55
  else
53
56
  _add options.merge parent: self
@@ -60,7 +63,7 @@ module ActiveAdmin
60
63
 
61
64
  # Whether any children match the given item.
62
65
  def include?(item)
63
- @children.values.include? item
66
+ @children.values.include?(item) || @children.values.any? { |child| child.include?(item) }
64
67
  end
65
68
 
66
69
  # Used in the UI to visually distinguish which menu item is selected.
@@ -45,13 +45,13 @@ module ActiveAdmin
45
45
  #
46
46
  def initialize(options = {})
47
47
  super() # MenuNode
48
- @label = options[:label]
49
- @dirty_id = options[:id] || options[:label]
50
- @url = options[:url] || '#'
51
- @priority = options[:priority] || 10
52
- @html_options = options[:html_options] || {}
53
- @should_display = options[:if] || proc { true }
54
- @parent = options[:parent]
48
+ @label = options[:label]
49
+ @dirty_id = options[:id] || options[:label]
50
+ @url = options[:url] || '#'
51
+ @priority = options[:priority] || 10
52
+ @html_options = options[:html_options] || {}
53
+ @should_display = options[:if] || proc { true }
54
+ @parent = options[:parent]
55
55
 
56
56
  yield(self) if block_given? # Builder style syntax
57
57
  end
@@ -150,9 +150,9 @@ module ActiveAdmin
150
150
  if logout_link_path
151
151
  html_options = html_options.reverse_merge(method: logout_link_method || :get)
152
152
  menu.add id: 'logout', priority: priority, html_options: html_options,
153
- label: -> { I18n.t 'active_admin.logout' },
154
- url: -> { render_or_call_method_or_proc_on self, active_admin_namespace.logout_link_path },
155
- if: :current_active_admin_user?
153
+ label: -> { I18n.t 'active_admin.logout' },
154
+ url: -> { render_or_call_method_or_proc_on self, active_admin_namespace.logout_link_path },
155
+ if: :current_active_admin_user?
156
156
  end
157
157
  end
158
158
 
@@ -165,9 +165,9 @@ module ActiveAdmin
165
165
  def add_current_user_to_menu(menu, priority = 10, html_options = {})
166
166
  if current_user_method
167
167
  menu.add id: 'current_user', priority: priority, html_options: html_options,
168
- label: -> { display_name current_active_admin_user },
169
- url: -> { auto_url_for(current_active_admin_user) },
170
- if: :current_active_admin_user?
168
+ label: -> { display_name current_active_admin_user },
169
+ url: -> { auto_url_for(current_active_admin_user) },
170
+ if: :current_active_admin_user?
171
171
  end
172
172
  end
173
173
 
@@ -212,7 +212,7 @@ module ActiveAdmin
212
212
  def unload_resources!
213
213
  resources.each do |resource|
214
214
  parent = (module_name || 'Object').constantize
215
- name = resource.controller_name.split('::').last
215
+ name = resource.controller_name.split('::').last
216
216
  parent.send(:remove_const, name) if parent.const_defined?(name, false)
217
217
 
218
218
  # Remove circular references
@@ -119,5 +119,8 @@ module ActiveAdmin
119
119
  :email,
120
120
  ]
121
121
  register :filter_method_for_large_association, '_starts_with'
122
+
123
+ # Switch between asset pipeline and webpacker assets
124
+ register :use_webpacker, false
122
125
  end
123
126
  end
@@ -4,7 +4,7 @@ module ActiveAdmin
4
4
  self.table_name = "#{table_name_prefix}active_admin_comments#{table_name_suffix}"
5
5
 
6
6
  belongs_to :resource, polymorphic: true, optional: true
7
- belongs_to :author, polymorphic: true
7
+ belongs_to :author, polymorphic: true
8
8
 
9
9
  validates_presence_of :body, :namespace, :resource
10
10
 
@@ -18,8 +18,8 @@ module ActiveAdmin
18
18
  def self.find_for_resource_in_namespace(resource, namespace)
19
19
  where(
20
20
  resource_type: resource_type(resource),
21
- resource_id: resource.id,
22
- namespace: namespace.to_s
21
+ resource_id: resource.id,
22
+ namespace: namespace.to_s
23
23
  ).order(ActiveAdmin.application.namespaces[namespace.to_sym].comments_order)
24
24
  end
25
25
 
@@ -80,9 +80,9 @@ module ActiveAdmin
80
80
  def build_comment_form
81
81
  active_admin_form_for(ActiveAdmin::Comment.new, url: comment_form_url) do |f|
82
82
  f.inputs do
83
- f.input :resource_type, as: :hidden, input_html: { value: ActiveAdmin::Comment.resource_type(parent.resource) }
84
- f.input :resource_id, as: :hidden, input_html: { value: parent.resource.id }
85
- f.input :body, label: false, input_html: { size: '80x8' }
83
+ f.input :resource_type, as: :hidden, input_html: { value: ActiveAdmin::Comment.resource_type(parent.resource) }
84
+ f.input :resource_id, as: :hidden, input_html: { value: parent.resource.id }
85
+ f.input :body, label: false, input_html: { size: '80x8' }
86
86
  end
87
87
  f.actions do
88
88
  f.action :submit, label: I18n.t('active_admin.comments.add')
@@ -4,14 +4,14 @@ require 'active_admin/orm/active_record/comments/namespace_helper'
4
4
  require 'active_admin/orm/active_record/comments/resource_helper'
5
5
 
6
6
  # Add the comments configuration
7
- ActiveAdmin::Application.inheritable_setting :comments, true
7
+ ActiveAdmin::Application.inheritable_setting :comments, true
8
8
  ActiveAdmin::Application.inheritable_setting :comments_registration_name, 'Comment'
9
- ActiveAdmin::Application.inheritable_setting :comments_order, "created_at ASC"
10
- ActiveAdmin::Application.inheritable_setting :comments_menu, {}
9
+ ActiveAdmin::Application.inheritable_setting :comments_order, "created_at ASC"
10
+ ActiveAdmin::Application.inheritable_setting :comments_menu, {}
11
11
 
12
12
  # Insert helper modules
13
13
  ActiveAdmin::Namespace.send :include, ActiveAdmin::Comments::NamespaceHelper
14
- ActiveAdmin::Resource.send :include, ActiveAdmin::Comments::ResourceHelper
14
+ ActiveAdmin::Resource.send :include, ActiveAdmin::Comments::ResourceHelper
15
15
  ActiveAdmin.application.view_factory.show_page.send :include, ActiveAdmin::Comments::ShowPageHelper
16
16
 
17
17
  # Load the model as soon as it's referenced. By that point, Rails & Kaminari will be ready
@@ -36,7 +36,7 @@ ActiveAdmin.after_load do |app|
36
36
 
37
37
  menu namespace.comments ? namespace.comments_menu : false
38
38
 
39
- config.comments = false # Don't allow comments on comments
39
+ config.comments = false # Don't allow comments on comments
40
40
  config.batch_actions = false # The default destroy batch action isn't showing up anyway...
41
41
 
42
42
  scope :all, show_count: false
@@ -51,7 +51,7 @@ ActiveAdmin.after_load do |app|
51
51
  # Store the author and namespace
52
52
  before_save do |comment|
53
53
  comment.namespace = active_admin_config.namespace.name
54
- comment.author = current_active_admin_user
54
+ comment.author = current_active_admin_user
55
55
  end
56
56
 
57
57
  controller do
@@ -89,11 +89,11 @@ ActiveAdmin.after_load do |app|
89
89
 
90
90
  index do
91
91
  column I18n.t('active_admin.comments.resource_type'), :resource_type
92
- column I18n.t('active_admin.comments.author_type'), :author_type
93
- column I18n.t('active_admin.comments.resource'), :resource
94
- column I18n.t('active_admin.comments.author'), :author
95
- column I18n.t('active_admin.comments.body'), :body
96
- column I18n.t('active_admin.comments.created_at'), :created_at
92
+ column I18n.t('active_admin.comments.author_type'), :author_type
93
+ column I18n.t('active_admin.comments.resource'), :resource
94
+ column I18n.t('active_admin.comments.author'), :author
95
+ column I18n.t('active_admin.comments.body'), :body
96
+ column I18n.t('active_admin.comments.created_at'), :created_at
97
97
  actions
98
98
  end
99
99
  end
@@ -31,7 +31,7 @@ module ActiveAdmin
31
31
 
32
32
  def retrieve_policy(subject)
33
33
  case subject
34
- when nil then Pundit.policy!(user, namespace(resource))
34
+ when nil then Pundit.policy!(user, namespace(resource))
35
35
  when Class then Pundit.policy!(user, namespace(subject.new))
36
36
  else Pundit.policy!(user, namespace(subject))
37
37
  end
@@ -46,9 +46,9 @@ module ActiveAdmin
46
46
  def format_action(action, subject)
47
47
  # https://github.com/varvet/pundit/blob/master/lib/generators/pundit/install/templates/application_policy.rb
48
48
  case action
49
- when Auth::CREATE then :create?
50
- when Auth::UPDATE then :update?
51
- when Auth::READ then subject.is_a?(Class) ? :index? : :show?
49
+ when Auth::CREATE then :create?
50
+ when Auth::UPDATE then :update?
51
+ when Auth::READ then subject.is_a?(Class) ? :index? : :show?
52
52
  when Auth::DESTROY then subject.is_a?(Class) ? :destroy_all? : :destroy?
53
53
  else "#{action}?"
54
54
  end
@@ -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
@@ -7,12 +7,12 @@ module ActiveAdmin
7
7
  # To disable this menu item, call `menu(false)` from the DSL
8
8
  def menu_item_options=(options)
9
9
  if options == false
10
- @include_in_menu = false
10
+ @include_in_menu = false
11
11
  @menu_item_options = {}
12
12
  else
13
13
  @include_in_menu = true
14
14
  @navigation_menu_name = options[:menu_name]
15
- @menu_item_options = default_menu_options.merge options
15
+ @menu_item_options = default_menu_options.merge options
16
16
  end
17
17
  end
18
18
 
@@ -27,8 +27,8 @@ module ActiveAdmin
27
27
  {
28
28
  id: resource_name.plural,
29
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) }
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
 
@@ -17,13 +17,13 @@ module ActiveAdmin
17
17
  # Returns the name to call this resource such as "Bank Account"
18
18
  def resource_label
19
19
  resource_name.translate count: 1,
20
- default: resource_name.to_s.gsub('::', ' ').titleize
20
+ default: resource_name.to_s.gsub('::', ' ').titleize
21
21
  end
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
@@ -98,13 +98,13 @@ module ActiveAdmin
98
98
  suffix = options[:suffix] || "path"
99
99
  route = []
100
100
 
101
- route << options[:action] # "batch_action", "edit" or "new"
102
- route << resource.route_prefix # "admin"
101
+ route << options[:action] # "batch_action", "edit" or "new"
102
+ route << resource.route_prefix # "admin"
103
103
  route << belongs_to_name if nested? # "category"
104
- route << resource_path_name # "posts" or "post"
105
- route << suffix # "path" or "index path"
104
+ route << resource_path_name # "posts" or "post"
105
+ route << suffix # "path" or "index path"
106
106
 
107
- route.compact.join('_').to_sym # :admin_category_posts_path
107
+ route.compact.join('_').to_sym # :admin_category_posts_path
108
108
  end
109
109
 
110
110
  # @return params to pass to instance path
@@ -38,10 +38,10 @@ module ActiveAdmin
38
38
  options = args.extract_options!
39
39
  method = args.first
40
40
 
41
- scope_to_config[:method] = block || method
42
- scope_to_config[:association_method] = options[:association_method]
43
- scope_to_config[:if] = options[:if]
44
- scope_to_config[:unless] = options[:unless]
41
+ scope_to_config[:method] = block || method
42
+ scope_to_config[:association_method] = options[:association_method]
43
+ scope_to_config[:if] = options[:if]
44
+ scope_to_config[:unless] = options[:unless]
45
45
 
46
46
  end
47
47
 
@@ -55,10 +55,10 @@ module ActiveAdmin
55
55
 
56
56
  def scope_to_config
57
57
  @scope_to_config ||= {
58
- method: nil,
58
+ method: nil,
59
59
  association_method: nil,
60
- if: nil,
61
- unless: nil
60
+ if: nil,
61
+ unless: nil
62
62
  }
63
63
  end
64
64
 
@@ -258,7 +258,7 @@ module ActiveAdmin
258
258
  end
259
259
 
260
260
  def collection_applies(options = {})
261
- only = Array(options.fetch(:only, COLLECTION_APPLIES))
261
+ only = Array(options.fetch(:only, COLLECTION_APPLIES))
262
262
  except = Array(options.fetch(:except, []))
263
263
 
264
264
  COLLECTION_APPLIES & only - except
@@ -53,13 +53,8 @@ module ActiveAdmin
53
53
 
54
54
  def self.wrap(decorator)
55
55
  collection_decorator = find_collection_decorator(decorator)
56
-
57
- if draper_collection_decorator? collection_decorator
58
- name = "#{collection_decorator.name} of #{decorator} + ActiveAdmin"
59
- @cache[name] ||= wrap! collection_decorator, name
60
- else
61
- collection_decorator
62
- end
56
+ name = "#{collection_decorator.name} of #{decorator} + ActiveAdmin"
57
+ @cache[name] ||= wrap! collection_decorator, name
63
58
  end
64
59
 
65
60
  private
@@ -68,34 +63,19 @@ module ActiveAdmin
68
63
  ::Class.new parent do
69
64
  delegate :reorder, :page, :current_page, :total_pages, :limit_value,
70
65
  :total_count, :total_pages, :offset, :to_key, :group_values,
71
- :except, :find_each, :ransack
66
+ :except, :find_each, :ransack, to: :object
72
67
 
73
68
  define_singleton_method(:name) { name }
74
69
  end
75
70
  end
76
71
 
77
- # Draper::CollectionDecorator was introduced in 1.0.0
78
- # Draper::Decorator#collection_decorator_class was introduced in 1.3.0
79
72
  def self.find_collection_decorator(decorator)
80
- if Dependency.draper? '>= 1.3.0'
73
+ if decorator.respond_to?(:collection_decorator_class)
81
74
  decorator.collection_decorator_class
82
- elsif Dependency.draper? '>= 1.0.0'
83
- draper_collection_decorator
84
75
  else
85
- decorator
76
+ CollectionDecorator
86
77
  end
87
78
  end
88
-
89
- def self.draper_collection_decorator?(decorator)
90
- decorator && decorator <= draper_collection_decorator
91
- rescue NameError
92
- false
93
- end
94
-
95
- def self.draper_collection_decorator
96
- ::Draper::CollectionDecorator
97
- end
98
-
99
79
  end
100
80
  end
101
81
  end
@@ -1,3 +1,4 @@
1
+ require 'active_admin/collection_decorator'
1
2
  require 'active_admin/resource_controller/action_builder'
2
3
  require 'active_admin/resource_controller/data_access'
3
4
  require 'active_admin/resource_controller/decorators'
@@ -24,13 +25,13 @@ module ActiveAdmin
24
25
  include Streaming
25
26
  include Sidebars
26
27
  include ViewHelpers::DownloadFormatLinksHelper
27
- extend ResourceClassMethods
28
+ extend ResourceClassMethods
28
29
 
29
30
  def self.active_admin_config=(config)
30
31
  if @active_admin_config = config
31
32
  defaults resource_class: config.resource_class,
32
- route_prefix: config.route_prefix,
33
- instance_name: config.resource_name.singular
33
+ route_prefix: config.route_prefix,
34
+ instance_name: config.resource_name.singular
34
35
  end
35
36
  end
36
37