activeadmin 2.5.0 → 2.8.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +120 -6
- data/CONTRIBUTING.md +11 -57
- data/README.md +2 -2
- data/app/assets/javascripts/active_admin/base.js +26 -18
- data/app/assets/stylesheets/active_admin/_header.scss +37 -3
- data/app/assets/stylesheets/active_admin/components/_comments.scss +2 -2
- data/app/assets/stylesheets/active_admin/mixins/_variables.scss +3 -0
- data/app/javascript/active_admin/base.js +9 -0
- data/app/javascript/active_admin/initializers/per-page.js +1 -1
- data/app/javascript/active_admin/lib/checkbox-toggler.js +3 -3
- data/app/javascript/active_admin/lib/dropdown-menu.js +1 -1
- data/app/javascript/active_admin/lib/modal-dialog.js +7 -7
- data/app/javascript/active_admin/lib/per-page.js +1 -1
- data/app/javascript/active_admin/lib/table-checkbox-toggler.js +1 -1
- data/app/views/layouts/active_admin_logged_out.html.erb +15 -5
- data/config/locales/ar.yml +6 -6
- data/config/locales/en-CA.yml +3 -3
- data/config/locales/en-GB.yml +3 -3
- data/config/locales/en.yml +3 -3
- data/config/locales/es-MX.yml +2 -1
- data/config/locales/es.yml +5 -5
- data/config/locales/fr.yml +4 -4
- data/config/locales/it.yml +18 -0
- data/config/locales/ja.yml +3 -3
- data/config/locales/lv.yml +2 -2
- data/config/locales/vi.yml +6 -5
- data/docs/0-installation.md +26 -2
- data/docs/11-decorators.md +16 -5
- data/docs/2-resource-customization.md +10 -1
- data/docs/3-index-pages.md +1 -1
- data/docs/9-batch-actions.md +2 -2
- data/docs/Gemfile +2 -2
- data/docs/Gemfile.lock +93 -84
- data/docs/_includes/top-menu.html +1 -1
- data/docs/documentation.md +1 -1
- data/docs/index.html +6 -6
- data/lib/active_admin.rb +60 -60
- data/lib/active_admin/application.rb +13 -13
- data/lib/active_admin/application_settings.rb +3 -3
- data/lib/active_admin/authorization_adapter.rb +3 -3
- data/lib/active_admin/base_controller.rb +4 -4
- data/lib/active_admin/base_controller/authorization.rb +13 -12
- data/lib/active_admin/batch_actions/controller.rb +3 -3
- data/lib/active_admin/batch_actions/resource_extension.rb +9 -8
- data/lib/active_admin/batch_actions/views/batch_action_form.rb +3 -3
- data/lib/active_admin/batch_actions/views/batch_action_selector.rb +6 -6
- data/lib/active_admin/batch_actions/views/selection_cells.rb +3 -3
- data/lib/active_admin/cancan_adapter.rb +1 -1
- data/lib/active_admin/collection_decorator.rb +31 -0
- data/lib/active_admin/csv_builder.rb +11 -7
- data/lib/active_admin/dependency.rb +11 -11
- data/lib/active_admin/devise.rb +5 -5
- data/lib/active_admin/dsl.rb +1 -1
- data/lib/active_admin/dynamic_settings_node.rb +2 -2
- data/lib/active_admin/engine.rb +3 -3
- data/lib/active_admin/filters.rb +7 -7
- data/lib/active_admin/filters/active.rb +1 -1
- data/lib/active_admin/filters/active_filter.rb +5 -4
- data/lib/active_admin/filters/active_sidebar.rb +5 -5
- data/lib/active_admin/filters/forms.rb +6 -6
- data/lib/active_admin/filters/formtastic_addons.rb +1 -6
- data/lib/active_admin/filters/resource_extension.rb +1 -1
- data/lib/active_admin/form_builder.rb +21 -19
- data/lib/active_admin/generators/boilerplate.rb +1 -1
- data/lib/active_admin/helpers/optional_display.rb +2 -2
- data/lib/active_admin/inputs/datepicker_input.rb +1 -1
- data/lib/active_admin/inputs/filters/base.rb +1 -1
- data/lib/active_admin/inputs/filters/base/search_method_select.rb +4 -4
- data/lib/active_admin/inputs/filters/boolean_input.rb +1 -1
- data/lib/active_admin/inputs/filters/check_boxes_input.rb +1 -1
- data/lib/active_admin/inputs/filters/date_range_input.rb +12 -9
- data/lib/active_admin/inputs/filters/select_input.rb +2 -2
- data/lib/active_admin/localizers.rb +1 -1
- data/lib/active_admin/localizers/resource_localizer.rb +3 -3
- data/lib/active_admin/menu.rb +6 -3
- data/lib/active_admin/menu_item.rb +7 -7
- data/lib/active_admin/namespace.rb +12 -12
- data/lib/active_admin/namespace_settings.rb +8 -5
- data/lib/active_admin/order_clause.rb +1 -1
- data/lib/active_admin/orm/active_record.rb +1 -1
- data/lib/active_admin/orm/active_record/comments.rb +19 -19
- data/lib/active_admin/orm/active_record/comments/comment.rb +3 -3
- data/lib/active_admin/orm/active_record/comments/views.rb +2 -2
- data/lib/active_admin/orm/active_record/comments/views/active_admin_comments.rb +19 -19
- data/lib/active_admin/page.rb +1 -1
- data/lib/active_admin/pundit_adapter.rb +5 -5
- data/lib/active_admin/resource.rb +17 -17
- data/lib/active_admin/resource/action_items.rb +5 -5
- data/lib/active_admin/resource/attributes.rb +1 -1
- data/lib/active_admin/resource/belongs_to.rb +2 -2
- data/lib/active_admin/resource/controllers.rb +1 -1
- data/lib/active_admin/resource/menu.rb +4 -4
- data/lib/active_admin/resource/naming.rb +5 -5
- data/lib/active_admin/resource/routes.rb +5 -5
- data/lib/active_admin/resource/scope_to.rb +7 -7
- data/lib/active_admin/resource/sidebars.rb +1 -1
- data/lib/active_admin/resource_controller.rb +12 -11
- data/lib/active_admin/resource_controller/data_access.rb +1 -1
- data/lib/active_admin/resource_controller/decorators.rb +6 -26
- data/lib/active_admin/resource_controller/streaming.rb +7 -6
- data/lib/active_admin/resource_dsl.rb +5 -5
- data/lib/active_admin/scope.rb +6 -6
- data/lib/active_admin/version.rb +1 -1
- data/lib/active_admin/view_factory.rb +17 -17
- data/lib/active_admin/view_helpers.rb +1 -1
- data/lib/active_admin/view_helpers/breadcrumb_helper.rb +3 -3
- data/lib/active_admin/view_helpers/display_helper.rb +5 -5
- data/lib/active_admin/view_helpers/download_format_links_helper.rb +1 -1
- data/lib/active_admin/view_helpers/fields_for.rb +2 -2
- data/lib/active_admin/views.rb +1 -1
- data/lib/active_admin/views/components/active_admin_form.rb +5 -5
- data/lib/active_admin/views/components/attributes_table.rb +5 -5
- data/lib/active_admin/views/components/blank_slate.rb +1 -1
- data/lib/active_admin/views/components/dropdown_menu.rb +8 -8
- data/lib/active_admin/views/components/index_list.rb +3 -3
- data/lib/active_admin/views/components/menu.rb +1 -1
- data/lib/active_admin/views/components/menu_item.rb +4 -4
- data/lib/active_admin/views/components/paginated_collection.rb +18 -18
- data/lib/active_admin/views/components/panel.rb +1 -1
- data/lib/active_admin/views/components/scopes.rb +7 -5
- data/lib/active_admin/views/components/site_title.rb +1 -1
- data/lib/active_admin/views/components/status_tag.rb +11 -11
- data/lib/active_admin/views/components/table_for.rb +17 -17
- data/lib/active_admin/views/components/tabs.rb +3 -3
- data/lib/active_admin/views/footer.rb +2 -1
- data/lib/active_admin/views/header.rb +2 -2
- data/lib/active_admin/views/index_as_blog.rb +1 -1
- data/lib/active_admin/views/index_as_grid.rb +1 -1
- data/lib/active_admin/views/index_as_table.rb +16 -16
- data/lib/active_admin/views/pages/base.rb +14 -10
- data/lib/active_admin/views/pages/index.rb +14 -13
- data/lib/active_admin/views/tabbed_navigation.rb +2 -2
- data/lib/active_admin/views/title_bar.rb +1 -1
- data/lib/activeadmin.rb +1 -1
- data/lib/generators/active_admin/assets/assets_generator.rb +2 -2
- data/lib/generators/active_admin/assets/templates/active_admin.scss +2 -2
- data/lib/generators/active_admin/devise/devise_generator.rb +5 -5
- data/lib/generators/active_admin/install/install_generator.rb +14 -8
- data/lib/generators/active_admin/install/templates/active_admin.rb.erb +9 -2
- data/lib/generators/active_admin/page/page_generator.rb +1 -1
- data/lib/generators/active_admin/resource/resource_generator.rb +3 -3
- data/lib/generators/active_admin/webpacker/plugins/jquery.js +7 -0
- data/lib/generators/active_admin/webpacker/templates/active_admin.js +5 -0
- data/lib/generators/active_admin/webpacker/templates/active_admin.scss +17 -0
- data/lib/generators/active_admin/webpacker/templates/print.scss +2 -0
- data/lib/generators/active_admin/webpacker/webpacker_generator.rb +26 -0
- data/lib/ransack_ext.rb +8 -8
- metadata +20 -8
data/lib/active_admin/page.rb
CHANGED
@@ -65,7 +65,7 @@ module ActiveAdmin
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def controller_name
|
68
|
-
[namespace.module_name, camelized_resource_name + "Controller"].compact.join(
|
68
|
+
[namespace.module_name, camelized_resource_name + "Controller"].compact.join("::")
|
69
69
|
end
|
70
70
|
|
71
71
|
# Override from `ActiveAdmin::Resource::Controllers`
|
@@ -1,6 +1,6 @@
|
|
1
1
|
ActiveAdmin::Dependency.pundit!
|
2
2
|
|
3
|
-
require
|
3
|
+
require "pundit"
|
4
4
|
|
5
5
|
# Add a setting to the application to configure the pundit default policy
|
6
6
|
ActiveAdmin::Application.inheritable_setting :pundit_default_policy, nil
|
@@ -31,7 +31,7 @@ module ActiveAdmin
|
|
31
31
|
|
32
32
|
def retrieve_policy(subject)
|
33
33
|
case subject
|
34
|
-
when nil
|
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
|
50
|
-
when Auth::UPDATE
|
51
|
-
when Auth::READ
|
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
|
@@ -1,18 +1,18 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
1
|
+
require "active_admin/resource/action_items"
|
2
|
+
require "active_admin/resource/attributes"
|
3
|
+
require "active_admin/resource/controllers"
|
4
|
+
require "active_admin/resource/menu"
|
5
|
+
require "active_admin/resource/page_presenters"
|
6
|
+
require "active_admin/resource/pagination"
|
7
|
+
require "active_admin/resource/routes"
|
8
|
+
require "active_admin/resource/naming"
|
9
|
+
require "active_admin/resource/scopes"
|
10
|
+
require "active_admin/resource/includes"
|
11
|
+
require "active_admin/resource/scope_to"
|
12
|
+
require "active_admin/resource/sidebars"
|
13
|
+
require "active_admin/resource/belongs_to"
|
14
|
+
require "active_admin/resource/ordering"
|
15
|
+
require "active_admin/resource/model"
|
16
16
|
|
17
17
|
module ActiveAdmin
|
18
18
|
|
@@ -27,7 +27,7 @@ module ActiveAdmin
|
|
27
27
|
class Resource
|
28
28
|
|
29
29
|
# Event dispatched when a new resource is registered
|
30
|
-
RegisterEvent =
|
30
|
+
RegisterEvent = "active_admin.resource.register".freeze
|
31
31
|
|
32
32
|
# The namespace this config belongs to
|
33
33
|
attr_reader :namespace
|
@@ -44,7 +44,7 @@ module ActiveAdmin
|
|
44
44
|
# The default sort order to use in the controller
|
45
45
|
attr_writer :sort_order
|
46
46
|
def sort_order
|
47
|
-
@sort_order ||= (resource_class.respond_to?(:primary_key) ? resource_class.primary_key.to_s :
|
47
|
+
@sort_order ||= (resource_class.respond_to?(:primary_key) ? resource_class.primary_key.to_s : "id") + "_desc"
|
48
48
|
end
|
49
49
|
|
50
50
|
# Set the configuration for the CSV
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "active_admin/helpers/optional_display"
|
2
2
|
|
3
3
|
module ActiveAdmin
|
4
4
|
|
@@ -64,7 +64,7 @@ module ActiveAdmin
|
|
64
64
|
# Adds the default New link on index
|
65
65
|
def add_default_new_action_item
|
66
66
|
add_action_item :new, only: :index do
|
67
|
-
if controller.action_methods.include?(
|
67
|
+
if controller.action_methods.include?("new") && authorized?(ActiveAdmin::Auth::CREATE, active_admin_config.resource_class)
|
68
68
|
localizer = ActiveAdmin::Localizers.resource(active_admin_config)
|
69
69
|
link_to localizer.t(:new_model), new_resource_path
|
70
70
|
end
|
@@ -74,7 +74,7 @@ module ActiveAdmin
|
|
74
74
|
# Adds the default Edit link on show
|
75
75
|
def add_default_edit_action_item
|
76
76
|
add_action_item :edit, only: :show do
|
77
|
-
if controller.action_methods.include?(
|
77
|
+
if controller.action_methods.include?("edit") && authorized?(ActiveAdmin::Auth::UPDATE, resource)
|
78
78
|
localizer = ActiveAdmin::Localizers.resource(active_admin_config)
|
79
79
|
link_to localizer.t(:edit_model), edit_resource_path(resource)
|
80
80
|
end
|
@@ -84,10 +84,10 @@ module ActiveAdmin
|
|
84
84
|
# Adds the default Destroy link on show
|
85
85
|
def add_default_show_action_item
|
86
86
|
add_action_item :destroy, only: :show do
|
87
|
-
if controller.action_methods.include?(
|
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
|
-
|
90
|
+
data: { confirm: localizer.t(:delete_confirmation) }
|
91
91
|
end
|
92
92
|
end
|
93
93
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "active_admin/resource"
|
2
2
|
|
3
3
|
module ActiveAdmin
|
4
4
|
class Resource
|
@@ -46,7 +46,7 @@ module ActiveAdmin
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def to_param
|
49
|
-
:"#{@target_name}_id"
|
49
|
+
(@options[:param] || "#{@target_name}_id").to_sym
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -6,7 +6,7 @@ module ActiveAdmin
|
|
6
6
|
# Returns a properly formatted controller name for this
|
7
7
|
# config within its namespace
|
8
8
|
def controller_name
|
9
|
-
[namespace.module_name, resource_name.plural.camelize + "Controller"].compact.join(
|
9
|
+
[namespace.module_name, resource_name.plural.camelize + "Controller"].compact.join("::")
|
10
10
|
end
|
11
11
|
|
12
12
|
# Returns the controller for this config
|
@@ -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
|
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
|
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:
|
31
|
-
if:
|
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
|
|
@@ -4,7 +4,7 @@ module ActiveAdmin
|
|
4
4
|
module Naming
|
5
5
|
def resource_name
|
6
6
|
@resource_name ||= begin
|
7
|
-
as = @options[:as].gsub /\s/,
|
7
|
+
as = @options[:as].gsub /\s/, "" if @options[:as]
|
8
8
|
|
9
9
|
if as || !resource_class.respond_to?(:model_name)
|
10
10
|
Name.new resource_class, as
|
@@ -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
|
-
|
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:
|
26
|
-
|
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]
|
102
|
-
route << resource.route_prefix
|
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
|
105
|
-
route << suffix
|
104
|
+
route << resource_path_name # "posts" or "post"
|
105
|
+
route << suffix # "path" or "index path"
|
106
106
|
|
107
|
-
route.compact.join(
|
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]
|
42
|
-
scope_to_config[:association_method]
|
43
|
-
scope_to_config[:if]
|
44
|
-
scope_to_config[: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:
|
58
|
+
method: nil,
|
59
59
|
association_method: nil,
|
60
|
-
if:
|
61
|
-
unless:
|
60
|
+
if: nil,
|
61
|
+
unless: nil
|
62
62
|
}
|
63
63
|
end
|
64
64
|
|
@@ -1,11 +1,12 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
1
|
+
require "active_admin/collection_decorator"
|
2
|
+
require "active_admin/resource_controller/action_builder"
|
3
|
+
require "active_admin/resource_controller/data_access"
|
4
|
+
require "active_admin/resource_controller/decorators"
|
5
|
+
require "active_admin/resource_controller/polymorphic_routes"
|
6
|
+
require "active_admin/resource_controller/scoping"
|
7
|
+
require "active_admin/resource_controller/streaming"
|
8
|
+
require "active_admin/resource_controller/sidebars"
|
9
|
+
require "active_admin/resource_controller/resource_class_methods"
|
9
10
|
|
10
11
|
module ActiveAdmin
|
11
12
|
# All Resources Controller inherits from this controller.
|
@@ -24,13 +25,13 @@ module ActiveAdmin
|
|
24
25
|
include Streaming
|
25
26
|
include Sidebars
|
26
27
|
include ViewHelpers::DownloadFormatLinksHelper
|
27
|
-
extend
|
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:
|
33
|
-
instance_name:
|
33
|
+
route_prefix: config.route_prefix,
|
34
|
+
instance_name: config.resource_name.singular
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
@@ -258,7 +258,7 @@ module ActiveAdmin
|
|
258
258
|
end
|
259
259
|
|
260
260
|
def collection_applies(options = {})
|
261
|
-
only
|
261
|
+
only = Array(options.fetch(:only, COLLECTION_APPLIES))
|
262
262
|
except = Array(options.fetch(:except, []))
|
263
263
|
|
264
264
|
COLLECTION_APPLIES & only - except
|
@@ -28,7 +28,7 @@ module ActiveAdmin
|
|
28
28
|
|
29
29
|
def decorate?
|
30
30
|
case action_name
|
31
|
-
when
|
31
|
+
when "new", "edit", "create", "update"
|
32
32
|
form = active_admin_config.get_page_presenter :form
|
33
33
|
form && form.options[:decorate] && decorator_class.present?
|
34
34
|
else
|
@@ -53,13 +53,8 @@ module ActiveAdmin
|
|
53
53
|
|
54
54
|
def self.wrap(decorator)
|
55
55
|
collection_decorator = find_collection_decorator(decorator)
|
56
|
-
|
57
|
-
|
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
|
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
|
-
|
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,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "csv"
|
2
2
|
|
3
3
|
module ActiveAdmin
|
4
4
|
class ResourceController < BaseController
|
@@ -18,11 +18,12 @@ module ActiveAdmin
|
|
18
18
|
protected
|
19
19
|
|
20
20
|
def stream_resource(&block)
|
21
|
-
headers[
|
22
|
-
headers[
|
21
|
+
headers["X-Accel-Buffering"] = "no"
|
22
|
+
headers["Cache-Control"] = "no-cache"
|
23
|
+
headers["Last-Modified"] = Time.current.httpdate
|
23
24
|
|
24
25
|
if ActiveAdmin.application.disable_streaming_in.include? Rails.env
|
25
|
-
self.response_body = block[
|
26
|
+
self.response_body = block[""]
|
26
27
|
else
|
27
28
|
self.response_body = Enumerator.new &block
|
28
29
|
end
|
@@ -33,8 +34,8 @@ module ActiveAdmin
|
|
33
34
|
end
|
34
35
|
|
35
36
|
def stream_csv
|
36
|
-
headers[
|
37
|
-
headers[
|
37
|
+
headers["Content-Type"] = "text/csv; charset=utf-8" # In Rails 5 it's set to HTML??
|
38
|
+
headers["Content-Disposition"] = %{attachment; filename="#{csv_filename}"}
|
38
39
|
stream_resource &active_admin_config.csv_builder.method(:build).to_proc.curry[self]
|
39
40
|
end
|
40
41
|
|
@@ -183,16 +183,16 @@ module ActiveAdmin
|
|
183
183
|
# == Before / After Destroy
|
184
184
|
# Called before and after the object is destroyed from the database.
|
185
185
|
#
|
186
|
-
delegate :before_build,
|
187
|
-
delegate :before_create,
|
188
|
-
delegate :before_update,
|
189
|
-
delegate :before_save,
|
186
|
+
delegate :before_build, :after_build, to: :controller
|
187
|
+
delegate :before_create, :after_create, to: :controller
|
188
|
+
delegate :before_update, :after_update, to: :controller
|
189
|
+
delegate :before_save, :after_save, to: :controller
|
190
190
|
delegate :before_destroy, :after_destroy, to: :controller
|
191
191
|
|
192
192
|
# This code defines both *_filter and *_action for Rails 5.0 and *_action for Rails >= 5.1
|
193
193
|
phases = [
|
194
194
|
:before, :skip_before,
|
195
|
-
:after,
|
195
|
+
:after, :skip_after,
|
196
196
|
:around, :skip
|
197
197
|
]
|
198
198
|
keywords = if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR >= 1
|
data/lib/active_admin/scope.rb
CHANGED
@@ -45,17 +45,17 @@ module ActiveAdmin
|
|
45
45
|
@scope_block = block
|
46
46
|
end
|
47
47
|
|
48
|
-
@localizer
|
49
|
-
@show_count
|
50
|
-
@display_if_block = options[:if]
|
51
|
-
@default_block
|
52
|
-
@group
|
48
|
+
@localizer = options[:localizer]
|
49
|
+
@show_count = options.fetch(:show_count, true)
|
50
|
+
@display_if_block = options[:if] || proc { true }
|
51
|
+
@default_block = options[:default] || proc { false }
|
52
|
+
@group = options[:group].try(:to_sym)
|
53
53
|
end
|
54
54
|
|
55
55
|
def name
|
56
56
|
case @name
|
57
57
|
when String then @name
|
58
|
-
when Symbol then @localizer ? @localizer.t(@name, scope:
|
58
|
+
when Symbol then @localizer ? @localizer.t(@name, scope: "scopes") : @name.to_s.titleize
|
59
59
|
else @name
|
60
60
|
end
|
61
61
|
end
|