activeadmin 2.9.0 → 2.14.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +230 -1
- data/CONTRIBUTING.md +4 -5
- data/README.md +2 -2
- data/app/assets/javascripts/active_admin/base.js +13 -9
- data/app/assets/stylesheets/active_admin/_base.scss +53 -37
- data/app/assets/stylesheets/active_admin/_forms.scss +1 -11
- data/app/assets/stylesheets/active_admin/_normalize.scss +25 -123
- data/app/assets/stylesheets/active_admin/components/_date_picker.scss +1 -2
- data/app/assets/stylesheets/active_admin/components/_dropdown_menu.scss +0 -1
- data/app/assets/stylesheets/active_admin/mixins/_variables.scss +9 -0
- data/app/assets/stylesheets/active_admin/structure/_footer.scss +6 -1
- data/app/assets/stylesheets/active_admin/structure/_title_bar.scss +0 -1
- data/app/javascript/active_admin/initializers/has-many.js +4 -1
- data/app/views/active_admin/devise/shared/_links.erb +1 -1
- data/app/views/active_admin/page/index.html.arb +1 -0
- data/app/views/active_admin/resource/edit.html.arb +1 -0
- data/app/views/active_admin/resource/index.html.arb +1 -0
- data/app/views/active_admin/resource/new.html.arb +1 -0
- data/app/views/active_admin/resource/show.html.arb +1 -0
- data/app/views/layouts/active_admin.html.arb +1 -0
- data/app/views/layouts/active_admin_logged_out.html.erb +5 -4
- data/config/locales/fr.yml +3 -3
- data/config/locales/ko.yml +1 -1
- data/config/locales/nl.yml +1 -1
- data/config/locales/ro.yml +3 -2
- data/config/locales/vi.yml +34 -7
- data/config/locales/zh-CN.yml +36 -17
- data/lib/active_admin/abstract_view_factory.rb +1 -0
- data/lib/active_admin/application.rb +10 -10
- data/lib/active_admin/application_settings.rb +1 -0
- data/lib/active_admin/asset_registration.rb +4 -3
- data/lib/active_admin/authorization_adapter.rb +3 -0
- data/lib/active_admin/base_controller/authorization.rb +4 -3
- data/lib/active_admin/base_controller/menu.rb +1 -0
- data/lib/active_admin/base_controller.rb +2 -1
- data/lib/active_admin/batch_actions/controller.rb +1 -0
- data/lib/active_admin/batch_actions/resource_extension.rb +1 -0
- data/lib/active_admin/batch_actions/views/batch_action_form.rb +1 -0
- data/lib/active_admin/batch_actions/views/batch_action_selector.rb +1 -0
- data/lib/active_admin/batch_actions/views/selection_cells.rb +1 -0
- data/lib/active_admin/batch_actions.rb +1 -0
- data/lib/active_admin/callbacks.rb +1 -0
- data/lib/active_admin/cancan_adapter.rb +1 -0
- data/lib/active_admin/collection_decorator.rb +1 -0
- data/lib/active_admin/component.rb +1 -0
- data/lib/active_admin/controller_action.rb +1 -0
- data/lib/active_admin/csv_builder.rb +5 -18
- data/lib/active_admin/dependency.rb +1 -4
- data/lib/active_admin/deprecation.rb +1 -0
- data/lib/active_admin/devise.rb +11 -0
- data/lib/active_admin/dsl.rb +1 -0
- data/lib/active_admin/dynamic_setting.rb +1 -0
- data/lib/active_admin/dynamic_settings_node.rb +1 -0
- data/lib/active_admin/engine.rb +4 -2
- data/lib/active_admin/error.rb +1 -0
- data/lib/active_admin/filters/active.rb +1 -0
- data/lib/active_admin/filters/active_filter.rb +1 -0
- data/lib/active_admin/filters/active_sidebar.rb +2 -28
- data/lib/active_admin/filters/dsl.rb +1 -0
- data/lib/active_admin/filters/forms.rb +1 -0
- data/lib/active_admin/filters/formtastic_addons.rb +1 -0
- data/lib/active_admin/filters/resource_extension.rb +5 -4
- data/lib/active_admin/filters.rb +1 -0
- data/lib/active_admin/form_builder.rb +1 -0
- data/lib/active_admin/generators/boilerplate.rb +1 -0
- data/lib/active_admin/helpers/collection.rb +2 -0
- data/lib/active_admin/helpers/i18n.rb +1 -0
- data/lib/active_admin/helpers/optional_display.rb +1 -0
- data/lib/active_admin/helpers/routes/url_helpers.rb +1 -0
- data/lib/active_admin/helpers/scope_chain.rb +1 -0
- data/lib/active_admin/inputs/datepicker_input.rb +1 -0
- data/lib/active_admin/inputs/filters/base/search_method_select.rb +1 -0
- data/lib/active_admin/inputs/filters/base.rb +1 -0
- data/lib/active_admin/inputs/filters/boolean_input.rb +1 -0
- data/lib/active_admin/inputs/filters/check_boxes_input.rb +1 -0
- data/lib/active_admin/inputs/filters/date_picker_input.rb +1 -0
- data/lib/active_admin/inputs/filters/date_range_input.rb +1 -0
- data/lib/active_admin/inputs/filters/numeric_input.rb +1 -0
- data/lib/active_admin/inputs/filters/select_input.rb +1 -0
- data/lib/active_admin/inputs/filters/string_input.rb +1 -0
- data/lib/active_admin/inputs/filters/text_input.rb +1 -0
- data/lib/active_admin/inputs.rb +1 -0
- data/lib/active_admin/localizers/resource_localizer.rb +1 -0
- data/lib/active_admin/localizers.rb +1 -0
- data/lib/active_admin/menu.rb +1 -0
- data/lib/active_admin/menu_collection.rb +1 -0
- data/lib/active_admin/menu_item.rb +1 -0
- data/lib/active_admin/namespace.rb +3 -2
- data/lib/active_admin/namespace_settings.rb +1 -0
- data/lib/active_admin/order_clause.rb +1 -0
- data/lib/active_admin/orm/active_record/comments/comment.rb +1 -0
- data/lib/active_admin/orm/active_record/comments/namespace_helper.rb +1 -0
- data/lib/active_admin/orm/active_record/comments/resource_helper.rb +1 -0
- data/lib/active_admin/orm/active_record/comments/show_page_helper.rb +1 -0
- data/lib/active_admin/orm/active_record/comments/views/active_admin_comments.rb +2 -1
- data/lib/active_admin/orm/active_record/comments/views.rb +1 -0
- data/lib/active_admin/orm/active_record/comments.rb +9 -8
- data/lib/active_admin/orm/active_record.rb +1 -0
- data/lib/active_admin/orm/mongoid.rb +1 -0
- data/lib/active_admin/page.rb +1 -0
- data/lib/active_admin/page_controller.rb +1 -0
- data/lib/active_admin/page_dsl.rb +1 -0
- data/lib/active_admin/page_presenter.rb +1 -0
- data/lib/active_admin/pundit_adapter.rb +55 -13
- data/lib/active_admin/resource/action_items.rb +3 -2
- data/lib/active_admin/resource/attributes.rb +1 -0
- data/lib/active_admin/resource/belongs_to.rb +1 -0
- data/lib/active_admin/resource/controllers.rb +1 -0
- data/lib/active_admin/resource/includes.rb +1 -0
- data/lib/active_admin/resource/menu.rb +1 -0
- data/lib/active_admin/resource/model.rb +1 -0
- data/lib/active_admin/resource/naming.rb +1 -0
- data/lib/active_admin/resource/ordering.rb +1 -0
- data/lib/active_admin/resource/page_presenters.rb +1 -0
- data/lib/active_admin/resource/pagination.rb +1 -0
- data/lib/active_admin/resource/routes.rb +1 -0
- data/lib/active_admin/resource/scope_to.rb +1 -0
- data/lib/active_admin/resource/scopes.rb +1 -0
- data/lib/active_admin/resource/sidebars.rb +1 -0
- data/lib/active_admin/resource.rb +3 -2
- data/lib/active_admin/resource_collection.rb +1 -0
- data/lib/active_admin/resource_controller/action_builder.rb +1 -0
- data/lib/active_admin/resource_controller/data_access.rb +30 -4
- data/lib/active_admin/resource_controller/decorators.rb +1 -0
- data/lib/active_admin/resource_controller/polymorphic_routes.rb +1 -0
- data/lib/active_admin/resource_controller/resource_class_methods.rb +1 -0
- data/lib/active_admin/resource_controller/scoping.rb +1 -0
- data/lib/active_admin/resource_controller/sidebars.rb +1 -0
- data/lib/active_admin/resource_controller/streaming.rb +3 -2
- data/lib/active_admin/resource_controller.rb +1 -0
- data/lib/active_admin/resource_dsl.rb +7 -21
- data/lib/active_admin/router.rb +1 -0
- data/lib/active_admin/scope.rb +1 -0
- data/lib/active_admin/settings_node.rb +1 -0
- data/lib/active_admin/sidebar_section.rb +1 -0
- data/lib/active_admin/version.rb +2 -1
- data/lib/active_admin/view_factory.rb +1 -0
- data/lib/active_admin/view_helpers/active_admin_application_helper.rb +1 -0
- data/lib/active_admin/view_helpers/auto_link_helper.rb +2 -1
- data/lib/active_admin/view_helpers/breadcrumb_helper.rb +1 -0
- data/lib/active_admin/view_helpers/display_helper.rb +11 -3
- data/lib/active_admin/view_helpers/download_format_links_helper.rb +1 -0
- data/lib/active_admin/view_helpers/fields_for.rb +1 -0
- data/lib/active_admin/view_helpers/flash_helper.rb +1 -0
- data/lib/active_admin/view_helpers/form_helper.rb +1 -0
- data/lib/active_admin/view_helpers/method_or_proc_helper.rb +1 -0
- data/lib/active_admin/view_helpers/scope_name_helper.rb +1 -0
- data/lib/active_admin/view_helpers/sidebar_helper.rb +1 -0
- data/lib/active_admin/view_helpers/title_helper.rb +1 -0
- data/lib/active_admin/view_helpers/view_factory_helper.rb +1 -0
- data/lib/active_admin/view_helpers.rb +1 -0
- data/lib/active_admin/views/action_items.rb +1 -0
- data/lib/active_admin/views/components/active_admin_form.rb +2 -1
- data/lib/active_admin/views/components/active_filters_sidebar_content.rb +59 -0
- data/lib/active_admin/views/components/attributes_table.rb +1 -0
- data/lib/active_admin/views/components/blank_slate.rb +1 -0
- data/lib/active_admin/views/components/columns.rb +1 -0
- data/lib/active_admin/views/components/dropdown_menu.rb +3 -5
- data/lib/active_admin/views/components/index_list.rb +1 -0
- data/lib/active_admin/views/components/menu.rb +1 -0
- data/lib/active_admin/views/components/menu_item.rb +1 -0
- data/lib/active_admin/views/components/paginated_collection.rb +1 -0
- data/lib/active_admin/views/components/panel.rb +1 -0
- data/lib/active_admin/views/components/scopes.rb +1 -0
- data/lib/active_admin/views/components/sidebar.rb +1 -0
- data/lib/active_admin/views/components/sidebar_section.rb +1 -0
- data/lib/active_admin/views/components/site_title.rb +1 -0
- data/lib/active_admin/views/components/status_tag.rb +1 -0
- data/lib/active_admin/views/components/table_for.rb +1 -0
- data/lib/active_admin/views/components/tabs.rb +1 -0
- data/lib/active_admin/views/components/unsupported_browser.rb +1 -0
- data/lib/active_admin/views/footer.rb +1 -0
- data/lib/active_admin/views/header.rb +1 -0
- data/lib/active_admin/views/index_as_block.rb +1 -0
- data/lib/active_admin/views/index_as_blog.rb +1 -0
- data/lib/active_admin/views/index_as_grid.rb +1 -0
- data/lib/active_admin/views/index_as_table.rb +2 -1
- data/lib/active_admin/views/pages/base.rb +8 -4
- data/lib/active_admin/views/pages/form.rb +1 -0
- data/lib/active_admin/views/pages/index.rb +2 -1
- data/lib/active_admin/views/pages/layout.rb +1 -0
- data/lib/active_admin/views/pages/page.rb +1 -0
- data/lib/active_admin/views/pages/show.rb +1 -0
- data/lib/active_admin/views/tabbed_navigation.rb +1 -0
- data/lib/active_admin/views/title_bar.rb +1 -0
- data/lib/active_admin/views.rb +1 -0
- data/lib/active_admin.rb +2 -1
- data/lib/activeadmin.rb +1 -0
- data/lib/generators/active_admin/assets/assets_generator.rb +1 -0
- data/lib/generators/active_admin/devise/devise_generator.rb +1 -0
- data/lib/generators/active_admin/install/install_generator.rb +1 -0
- data/lib/generators/active_admin/install/templates/active_admin.rb.erb +17 -0
- data/lib/generators/active_admin/install/templates/dashboard.rb +1 -0
- data/lib/generators/active_admin/page/page_generator.rb +1 -0
- data/lib/generators/active_admin/page/templates/page.rb +1 -0
- data/lib/generators/active_admin/resource/resource_generator.rb +1 -0
- data/lib/generators/active_admin/webpacker/webpacker_generator.rb +1 -0
- data/lib/ransack_ext.rb +1 -0
- metadata +21 -59
- data/docs/.gitignore +0 -1
- data/docs/0-installation.md +0 -142
- data/docs/1-general-configuration.md +0 -224
- data/docs/10-custom-pages.md +0 -150
- data/docs/11-decorators.md +0 -70
- data/docs/12-arbre-components.md +0 -214
- data/docs/13-authorization-adapter.md +0 -285
- data/docs/14-gotchas.md +0 -138
- data/docs/2-resource-customization.md +0 -475
- data/docs/3-index-pages/custom-index.md +0 -35
- data/docs/3-index-pages/index-as-block.md +0 -19
- data/docs/3-index-pages/index-as-blog.md +0 -69
- data/docs/3-index-pages/index-as-grid.md +0 -27
- data/docs/3-index-pages/index-as-table.md +0 -234
- data/docs/3-index-pages.md +0 -328
- data/docs/4-csv-format.md +0 -74
- data/docs/5-forms.md +0 -237
- data/docs/6-show-pages.md +0 -93
- data/docs/7-sidebars.md +0 -75
- data/docs/8-custom-actions.md +0 -177
- data/docs/9-batch-actions.md +0 -237
- data/docs/CNAME +0 -1
- data/docs/Gemfile +0 -3
- data/docs/Gemfile.lock +0 -259
- data/docs/README.md +0 -24
- data/docs/_config.yml +0 -4
- data/docs/_includes/footer.html +0 -8
- data/docs/_includes/google-analytics.html +0 -16
- data/docs/_includes/head.html +0 -7
- data/docs/_includes/toc.html +0 -98
- data/docs/_includes/top-menu.html +0 -17
- data/docs/_layouts/default.html +0 -21
- data/docs/documentation.md +0 -60
- data/docs/images/activeadmin.png +0 -0
- data/docs/images/code-header.png +0 -0
- data/docs/images/divider.png +0 -0
- data/docs/images/features.png +0 -0
- data/docs/images/tidelift.svg +0 -14
- data/docs/index.html +0 -226
- data/docs/stylesheets/main.css +0 -1205
- /data/app/assets/stylesheets/active_admin/{print.scss → _print.scss} +0 -0
data/lib/active_admin/inputs.rb
CHANGED
data/lib/active_admin/menu.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "active_admin/resource_collection"
|
2
3
|
|
3
4
|
module ActiveAdmin
|
@@ -59,7 +60,7 @@ module ActiveAdmin
|
|
59
60
|
settings.respond_to?(method) ? settings.send(method, *args) : super
|
60
61
|
end
|
61
62
|
|
62
|
-
# Register a resource into this namespace. The
|
63
|
+
# Register a resource into this namespace. The preferred method to access this is to
|
63
64
|
# use the global registration ActiveAdmin.register which delegates to the proper
|
64
65
|
# namespace instance.
|
65
66
|
def register(resource_class, options = {}, &block)
|
@@ -71,7 +72,7 @@ module ActiveAdmin
|
|
71
72
|
reset_menu!
|
72
73
|
|
73
74
|
# Dispatch a registration event
|
74
|
-
ActiveSupport::Notifications.
|
75
|
+
ActiveSupport::Notifications.instrument ActiveAdmin::Resource::RegisterEvent, { active_admin_resource: config }
|
75
76
|
|
76
77
|
# Return the config
|
77
78
|
config
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "active_admin/views"
|
2
3
|
require "active_admin/views/components/panel"
|
3
4
|
|
@@ -35,7 +36,7 @@ module ActiveAdmin
|
|
35
36
|
|
36
37
|
text_node paginate @comments
|
37
38
|
|
38
|
-
if authorized?(ActiveAdmin::Auth::
|
39
|
+
if authorized?(ActiveAdmin::Auth::NEW, ActiveAdmin::Comment)
|
39
40
|
build_comment_form
|
40
41
|
end
|
41
42
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "active_admin/orm/active_record/comments/views"
|
2
3
|
require "active_admin/orm/active_record/comments/show_page_helper"
|
3
4
|
require "active_admin/orm/active_record/comments/namespace_helper"
|
@@ -71,15 +72,15 @@ ActiveAdmin.after_load do |app|
|
|
71
72
|
redirect_back fallback_location: active_admin_root
|
72
73
|
end
|
73
74
|
end
|
75
|
+
end
|
74
76
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
end
|
77
|
+
def destroy
|
78
|
+
destroy! do |success, failure|
|
79
|
+
success.html do
|
80
|
+
redirect_back fallback_location: active_admin_root
|
81
|
+
end
|
82
|
+
failure.html do
|
83
|
+
redirect_back fallback_location: active_admin_root
|
83
84
|
end
|
84
85
|
end
|
85
86
|
end
|
data/lib/active_admin/page.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
ActiveAdmin::Dependency.pundit!
|
2
3
|
|
3
4
|
require "pundit"
|
@@ -30,24 +31,19 @@ module ActiveAdmin
|
|
30
31
|
end
|
31
32
|
|
32
33
|
def retrieve_policy(subject)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
rescue Pundit::NotDefinedError => e
|
39
|
-
if default_policy_class
|
40
|
-
default_policy(user, subject)
|
34
|
+
target = policy_target(subject)
|
35
|
+
if (policy = policy(namespace(target)) || compat_policy(subject))
|
36
|
+
policy
|
37
|
+
elsif default_policy_class
|
38
|
+
default_policy(subject)
|
41
39
|
else
|
42
|
-
raise
|
40
|
+
raise Pundit::NotDefinedError, "unable to find a compatible policy for `#{target}`"
|
43
41
|
end
|
44
42
|
end
|
45
43
|
|
46
44
|
def format_action(action, subject)
|
47
45
|
# https://github.com/varvet/pundit/blob/master/lib/generators/pundit/install/templates/application_policy.rb
|
48
46
|
case action
|
49
|
-
when Auth::CREATE then :create?
|
50
|
-
when Auth::UPDATE then :update?
|
51
47
|
when Auth::READ then subject.is_a?(Class) ? :index? : :show?
|
52
48
|
when Auth::DESTROY then subject.is_a?(Class) ? :destroy_all? : :destroy?
|
53
49
|
else "#{action}?"
|
@@ -56,8 +52,42 @@ module ActiveAdmin
|
|
56
52
|
|
57
53
|
private
|
58
54
|
|
55
|
+
def policy_target(subject)
|
56
|
+
case subject
|
57
|
+
when nil then resource
|
58
|
+
when Class then subject.new
|
59
|
+
else subject
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# This method is needed to fallback to our previous policy searching logic.
|
64
|
+
# I.e.: when class name contains `default_policy_namespace` (eg: ShopAdmin)
|
65
|
+
# we should try to search it without namespace. This is because that's
|
66
|
+
# the only thing that worked in this case before we fixed our buggy namespace
|
67
|
+
# detection, so people are probably relying on it.
|
68
|
+
# This fallback might be removed in future versions of ActiveAdmin, so
|
69
|
+
# pundit_adapter search will work consistently with provided namespaces
|
70
|
+
def compat_policy(subject)
|
71
|
+
return unless default_policy_namespace
|
72
|
+
|
73
|
+
target = policy_target(subject)
|
74
|
+
|
75
|
+
return unless target.class.to_s.include?(default_policy_module) &&
|
76
|
+
(policy = policy(target))
|
77
|
+
|
78
|
+
policy_name = policy.class.to_s
|
79
|
+
|
80
|
+
Deprecation.warn "You have `pundit_policy_namespace` configured as `#{default_policy_namespace}`, " \
|
81
|
+
"but ActiveAdmin was unable to find policy #{default_policy_module}::#{policy_name}. " \
|
82
|
+
"#{policy_name} will be used instead. " \
|
83
|
+
"This behavior will be removed in future versions of ActiveAdmin. " \
|
84
|
+
"To fix this warning, move your #{policy_name} policy to the #{default_policy_module} namespace"
|
85
|
+
|
86
|
+
policy
|
87
|
+
end
|
88
|
+
|
59
89
|
def namespace(object)
|
60
|
-
if default_policy_namespace && !object.class.to_s.
|
90
|
+
if default_policy_namespace && !object.class.to_s.start_with?("#{default_policy_module}::")
|
61
91
|
[default_policy_namespace.to_sym, object]
|
62
92
|
else
|
63
93
|
object
|
@@ -68,7 +98,7 @@ module ActiveAdmin
|
|
68
98
|
ActiveAdmin.application.pundit_default_policy && ActiveAdmin.application.pundit_default_policy.constantize
|
69
99
|
end
|
70
100
|
|
71
|
-
def default_policy(
|
101
|
+
def default_policy(subject)
|
72
102
|
default_policy_class.new(user, subject)
|
73
103
|
end
|
74
104
|
|
@@ -76,6 +106,18 @@ module ActiveAdmin
|
|
76
106
|
ActiveAdmin.application.pundit_policy_namespace
|
77
107
|
end
|
78
108
|
|
109
|
+
def default_policy_module
|
110
|
+
default_policy_namespace.to_s.camelize
|
111
|
+
end
|
112
|
+
|
113
|
+
def policy(target)
|
114
|
+
policies[target] ||= Pundit.policy(user, target)
|
115
|
+
end
|
116
|
+
|
117
|
+
def policies
|
118
|
+
@policies ||= {}
|
119
|
+
end
|
120
|
+
|
79
121
|
end
|
80
122
|
|
81
123
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "active_admin/helpers/optional_display"
|
2
3
|
|
3
4
|
module ActiveAdmin
|
@@ -64,7 +65,7 @@ module ActiveAdmin
|
|
64
65
|
# Adds the default New link on index
|
65
66
|
def add_default_new_action_item
|
66
67
|
add_action_item :new, only: :index do
|
67
|
-
if controller.action_methods.include?("new") && authorized?(ActiveAdmin::Auth::
|
68
|
+
if controller.action_methods.include?("new") && authorized?(ActiveAdmin::Auth::NEW, active_admin_config.resource_class)
|
68
69
|
localizer = ActiveAdmin::Localizers.resource(active_admin_config)
|
69
70
|
link_to localizer.t(:new_model), new_resource_path
|
70
71
|
end
|
@@ -74,7 +75,7 @@ module ActiveAdmin
|
|
74
75
|
# Adds the default Edit link on show
|
75
76
|
def add_default_edit_action_item
|
76
77
|
add_action_item :edit, only: :show do
|
77
|
-
if controller.action_methods.include?("edit") && authorized?(ActiveAdmin::Auth::
|
78
|
+
if controller.action_methods.include?("edit") && authorized?(ActiveAdmin::Auth::EDIT, resource)
|
78
79
|
localizer = ActiveAdmin::Localizers.resource(active_admin_config)
|
79
80
|
link_to localizer.t(:edit_model), edit_resource_path(resource)
|
80
81
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "active_admin/resource/action_items"
|
2
3
|
require "active_admin/resource/attributes"
|
3
4
|
require "active_admin/resource/controllers"
|
@@ -98,11 +99,11 @@ module ActiveAdmin
|
|
98
99
|
# The class this resource wraps. If you register the Post model, Resource#resource_class
|
99
100
|
# will point to the Post class
|
100
101
|
def resource_class
|
101
|
-
|
102
|
+
resource_class_name.constantize
|
102
103
|
end
|
103
104
|
|
104
105
|
def decorator_class
|
105
|
-
|
106
|
+
decorator_class_name&.constantize
|
106
107
|
end
|
107
108
|
|
108
109
|
def resource_name_extension
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module ActiveAdmin
|
2
3
|
class ResourceController < BaseController
|
3
4
|
|
@@ -23,9 +24,9 @@ module ActiveAdmin
|
|
23
24
|
|
24
25
|
COLLECTION_APPLIES = [
|
25
26
|
:authorization_scope,
|
26
|
-
:sorting,
|
27
27
|
:filtering,
|
28
28
|
:scoping,
|
29
|
+
:sorting,
|
29
30
|
:includes,
|
30
31
|
:pagination,
|
31
32
|
:collection_decorator
|
@@ -128,7 +129,7 @@ module ActiveAdmin
|
|
128
129
|
#
|
129
130
|
# @return [ActiveRecord::Base] An un-saved active record base object
|
130
131
|
def build_new_resource
|
131
|
-
scoped_collection.send(
|
132
|
+
apply_authorization_scope(scoped_collection).send(
|
132
133
|
method_for_build,
|
133
134
|
*resource_params.map { |params| params.slice(active_admin_config.resource_class.inheritance_column) }
|
134
135
|
)
|
@@ -249,12 +250,13 @@ module ActiveAdmin
|
|
249
250
|
end
|
250
251
|
|
251
252
|
def apply_pagination(chain)
|
253
|
+
# skip pagination if CSV format was requested
|
254
|
+
return chain if params["format"] == "csv"
|
252
255
|
# skip pagination if already was paginated by scope
|
253
256
|
return chain if chain.respond_to?(:total_pages)
|
254
|
-
page_method_name = Kaminari.config.page_method_name
|
255
257
|
page = params[Kaminari.config.param_name]
|
256
258
|
|
257
|
-
chain
|
259
|
+
paginate(chain, page, per_page)
|
258
260
|
end
|
259
261
|
|
260
262
|
def collection_applies(options = {})
|
@@ -264,6 +266,16 @@ module ActiveAdmin
|
|
264
266
|
COLLECTION_APPLIES & only - except
|
265
267
|
end
|
266
268
|
|
269
|
+
def in_paginated_batches(&block)
|
270
|
+
ActiveRecord::Base.uncached do
|
271
|
+
(1..paginated_collection.total_pages).each do |page|
|
272
|
+
paginated_collection(page).each do |resource|
|
273
|
+
yield apply_decorator(resource)
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
267
279
|
def per_page
|
268
280
|
if active_admin_config.paginate
|
269
281
|
dynamic_per_page || configured_per_page
|
@@ -317,6 +329,20 @@ module ActiveAdmin
|
|
317
329
|
def create_another?
|
318
330
|
params[:create_another].present?
|
319
331
|
end
|
332
|
+
|
333
|
+
def paginated_collection(page_no = 1)
|
334
|
+
paginate(collection, page_no, batch_size)
|
335
|
+
end
|
336
|
+
|
337
|
+
def paginate(chain, page, per_page)
|
338
|
+
page_method_name = Kaminari.config.page_method_name
|
339
|
+
|
340
|
+
chain.public_send(page_method_name, page).per(per_page)
|
341
|
+
end
|
342
|
+
|
343
|
+
def batch_size
|
344
|
+
1000
|
345
|
+
end
|
320
346
|
end
|
321
347
|
end
|
322
348
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "csv"
|
2
3
|
|
3
4
|
module ActiveAdmin
|
@@ -23,14 +24,14 @@ module ActiveAdmin
|
|
23
24
|
headers["Last-Modified"] = Time.current.httpdate
|
24
25
|
|
25
26
|
if ActiveAdmin.application.disable_streaming_in.include? Rails.env
|
26
|
-
self.response_body = block[
|
27
|
+
self.response_body = block[String.new]
|
27
28
|
else
|
28
29
|
self.response_body = Enumerator.new &block
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
33
|
def csv_filename
|
33
|
-
"#{resource_collection_name.to_s.gsub('_', '-')}-#{Time.zone.now.to_date.
|
34
|
+
"#{resource_collection_name.to_s.gsub('_', '-')}-#{Time.zone.now.to_date.to_formatted_s(:default)}.csv"
|
34
35
|
end
|
35
36
|
|
36
37
|
def stream_csv
|