activeadmin 2.2.0 → 2.12.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 +382 -32
- data/CONTRIBUTING.md +45 -67
- data/README.md +11 -4
- data/app/assets/javascripts/active_admin/base.js +524 -0
- data/app/assets/stylesheets/active_admin/_base.scss +53 -37
- data/app/assets/stylesheets/active_admin/_forms.scss +0 -10
- data/app/assets/stylesheets/active_admin/_header.scss +40 -8
- data/app/assets/stylesheets/active_admin/_mixins.scss +1 -1
- data/{vendor → app}/assets/stylesheets/active_admin/_normalize.scss +25 -123
- data/app/assets/stylesheets/active_admin/{print.scss → _print.scss} +2 -2
- data/app/assets/stylesheets/active_admin/components/_comments.scss +2 -2
- 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/components/_tables.scss +1 -2
- data/app/assets/stylesheets/active_admin/mixins/_all.scss +8 -8
- data/app/assets/stylesheets/active_admin/mixins/_variables.scss +17 -0
- data/app/assets/stylesheets/active_admin/structure/_main_structure.scss +1 -1
- data/app/assets/stylesheets/active_admin/structure/_title_bar.scss +0 -1
- data/app/javascript/active_admin/base.js +28 -0
- data/app/{assets/javascripts/active_admin/lib/batch_actions.es6 → javascript/active_admin/initializers/batch-actions.js} +9 -3
- data/app/javascript/active_admin/initializers/checkbox-toggler.js +3 -0
- data/app/javascript/active_admin/initializers/dropdown-menu.js +9 -0
- data/app/javascript/active_admin/initializers/filters.js +10 -0
- data/app/{assets/javascripts/active_admin/lib/has_many.es6 → javascript/active_admin/initializers/has-many.js} +4 -1
- data/app/javascript/active_admin/initializers/per-page.js +13 -0
- data/app/javascript/active_admin/initializers/table-checkbox-toggler.js +3 -0
- data/app/{assets/javascripts/active_admin/lib/checkbox-toggler.es6 → javascript/active_admin/lib/checkbox-toggler.js} +5 -5
- data/app/{assets/javascripts/active_admin/lib/dropdown-menu.es6 → javascript/active_admin/lib/dropdown-menu.js} +3 -10
- data/app/javascript/active_admin/lib/filters.js +39 -0
- data/app/{assets/javascripts/active_admin/lib/modal_dialog.es6 → javascript/active_admin/lib/modal-dialog.js} +10 -8
- data/app/javascript/active_admin/lib/per-page.js +38 -0
- data/app/{assets/javascripts/active_admin/lib/table-checkbox-toggler.es6 → javascript/active_admin/lib/table-checkbox-toggler.js} +5 -3
- data/app/javascript/active_admin/lib/utils.js +40 -0
- data/app/views/active_admin/devise/mailer/reset_password_instructions.html.erb +1 -1
- data/app/views/active_admin/devise/mailer/unlock_instructions.html.erb +2 -2
- 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/kaminari/active_admin_countless/_first_page.html.erb +11 -0
- data/app/views/kaminari/active_admin_countless/_gap.html.erb +8 -0
- data/app/views/kaminari/active_admin_countless/_next_page.html.erb +11 -0
- data/app/views/kaminari/active_admin_countless/_page.html.erb +12 -0
- data/app/views/kaminari/active_admin_countless/_paginator.html.erb +24 -0
- data/app/views/kaminari/active_admin_countless/_prev_page.html.erb +11 -0
- data/app/views/layouts/active_admin.html.arb +1 -0
- data/app/views/layouts/active_admin_logged_out.html.erb +15 -5
- data/config/locales/ar.yml +6 -6
- data/config/locales/az.yml +138 -0
- data/config/locales/ca.yml +0 -1
- data/config/locales/de.yml +18 -0
- 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/ko.yml +1 -1
- data/config/locales/lv.yml +2 -2
- data/config/locales/nl.yml +1 -1
- data/config/locales/ro.yml +3 -2
- data/config/locales/sk.yml +59 -0
- data/config/locales/vi.yml +6 -5
- data/docs/0-installation.md +27 -3
- data/docs/1-general-configuration.md +20 -0
- data/docs/11-decorators.md +16 -5
- data/docs/2-resource-customization.md +11 -2
- data/docs/3-index-pages/index-as-table.md +7 -0
- data/docs/3-index-pages.md +1 -1
- data/docs/5-forms.md +7 -2
- data/docs/6-show-pages.md +12 -0
- data/docs/8-custom-actions.md +1 -1
- data/docs/9-batch-actions.md +2 -2
- data/docs/Gemfile +3 -3
- data/docs/Gemfile.lock +192 -158
- data/docs/_config.yml +2 -0
- data/docs/_includes/top-menu.html +2 -2
- data/docs/documentation.md +1 -1
- data/docs/index.html +109 -8
- data/docs/stylesheets/main.css +29 -0
- data/lib/active_admin/abstract_view_factory.rb +1 -0
- data/lib/active_admin/application.rb +20 -20
- data/lib/active_admin/application_settings.rb +4 -3
- data/lib/active_admin/asset_registration.rb +1 -0
- data/lib/active_admin/authorization_adapter.rb +4 -3
- data/lib/active_admin/base_controller/authorization.rb +15 -13
- data/lib/active_admin/base_controller/menu.rb +1 -0
- data/lib/active_admin/base_controller.rb +6 -5
- data/lib/active_admin/batch_actions/controller.rb +4 -3
- data/lib/active_admin/batch_actions/resource_extension.rb +10 -8
- data/lib/active_admin/batch_actions/views/batch_action_form.rb +4 -3
- data/lib/active_admin/batch_actions/views/batch_action_selector.rb +7 -6
- data/lib/active_admin/batch_actions/views/selection_cells.rb +4 -3
- data/lib/active_admin/batch_actions.rb +1 -0
- data/lib/active_admin/callbacks.rb +1 -0
- data/lib/active_admin/cancan_adapter.rb +2 -1
- data/lib/active_admin/collection_decorator.rb +32 -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 +13 -23
- data/lib/active_admin/dependency.rb +13 -12
- data/lib/active_admin/deprecation.rb +1 -0
- data/lib/active_admin/devise.rb +16 -5
- data/lib/active_admin/dsl.rb +2 -1
- data/lib/active_admin/dynamic_setting.rb +1 -0
- data/lib/active_admin/dynamic_settings_node.rb +3 -2
- data/lib/active_admin/engine.rb +13 -9
- data/lib/active_admin/error.rb +1 -2
- data/lib/active_admin/filters/active.rb +2 -1
- data/lib/active_admin/filters/active_filter.rb +7 -7
- data/lib/active_admin/filters/active_sidebar.rb +4 -30
- data/lib/active_admin/filters/dsl.rb +1 -0
- data/lib/active_admin/filters/forms.rb +7 -6
- data/lib/active_admin/filters/formtastic_addons.rb +2 -6
- data/lib/active_admin/filters/resource_extension.rb +26 -1
- data/lib/active_admin/filters.rb +8 -7
- data/lib/active_admin/form_builder.rb +25 -20
- data/lib/active_admin/generators/boilerplate.rb +13 -4
- 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 +3 -2
- 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 +2 -1
- data/lib/active_admin/inputs/filters/base/search_method_select.rb +5 -4
- data/lib/active_admin/inputs/filters/base.rb +2 -1
- data/lib/active_admin/inputs/filters/boolean_input.rb +2 -1
- data/lib/active_admin/inputs/filters/check_boxes_input.rb +2 -1
- data/lib/active_admin/inputs/filters/date_picker_input.rb +1 -0
- data/lib/active_admin/inputs/filters/date_range_input.rb +16 -12
- data/lib/active_admin/inputs/filters/numeric_input.rb +1 -0
- data/lib/active_admin/inputs/filters/select_input.rb +3 -2
- 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 +4 -3
- data/lib/active_admin/localizers.rb +2 -1
- data/lib/active_admin/menu.rb +7 -3
- data/lib/active_admin/menu_collection.rb +1 -0
- data/lib/active_admin/menu_item.rb +8 -7
- data/lib/active_admin/namespace.rb +14 -13
- data/lib/active_admin/namespace_settings.rb +21 -4
- data/lib/active_admin/order_clause.rb +3 -2
- data/lib/active_admin/orm/active_record/comments/comment.rb +4 -3
- 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 +20 -19
- data/lib/active_admin/orm/active_record/comments/views.rb +3 -2
- data/lib/active_admin/orm/active_record/comments.rb +20 -19
- data/lib/active_admin/orm/active_record.rb +2 -1
- data/lib/active_admin/orm/mongoid.rb +1 -0
- data/lib/active_admin/page.rb +2 -1
- 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 +47 -11
- data/lib/active_admin/resource/action_items.rb +6 -5
- data/lib/active_admin/resource/attributes.rb +2 -1
- data/lib/active_admin/resource/belongs_to.rb +6 -2
- data/lib/active_admin/resource/controllers.rb +2 -1
- data/lib/active_admin/resource/includes.rb +1 -0
- data/lib/active_admin/resource/menu.rb +5 -4
- data/lib/active_admin/resource/model.rb +16 -0
- data/lib/active_admin/resource/naming.rb +6 -5
- 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 +17 -10
- data/lib/active_admin/resource/scope_to.rb +8 -7
- data/lib/active_admin/resource/scopes.rb +1 -0
- data/lib/active_admin/resource/sidebars.rb +2 -1
- data/lib/active_admin/resource.rb +33 -19
- 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 +31 -5
- data/lib/active_admin/resource_controller/decorators.rb +8 -29
- data/lib/active_admin/resource_controller/polymorphic_routes.rb +38 -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 +9 -7
- data/lib/active_admin/resource_controller.rb +14 -10
- data/lib/active_admin/resource_dsl.rb +11 -25
- data/lib/active_admin/router.rb +1 -0
- data/lib/active_admin/scope.rb +7 -6
- 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 +18 -17
- data/lib/active_admin/view_helpers/active_admin_application_helper.rb +1 -0
- data/lib/active_admin/view_helpers/auto_link_helper.rb +1 -0
- data/lib/active_admin/view_helpers/breadcrumb_helper.rb +4 -3
- data/lib/active_admin/view_helpers/display_helper.rb +15 -7
- data/lib/active_admin/view_helpers/download_format_links_helper.rb +2 -1
- data/lib/active_admin/view_helpers/fields_for.rb +3 -2
- 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 +2 -1
- data/lib/active_admin/views/action_items.rb +1 -0
- data/lib/active_admin/views/components/active_admin_form.rb +7 -6
- data/lib/active_admin/views/components/active_filters_sidebar_content.rb +59 -0
- data/lib/active_admin/views/components/attributes_table.rb +6 -5
- data/lib/active_admin/views/components/blank_slate.rb +2 -1
- data/lib/active_admin/views/components/columns.rb +1 -0
- data/lib/active_admin/views/components/dropdown_menu.rb +7 -9
- data/lib/active_admin/views/components/index_list.rb +4 -3
- data/lib/active_admin/views/components/menu.rb +2 -1
- data/lib/active_admin/views/components/menu_item.rb +5 -4
- data/lib/active_admin/views/components/paginated_collection.rb +21 -19
- data/lib/active_admin/views/components/panel.rb +2 -1
- data/lib/active_admin/views/components/scopes.rb +8 -5
- 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 +2 -1
- data/lib/active_admin/views/components/status_tag.rb +12 -11
- data/lib/active_admin/views/components/table_for.rb +19 -17
- data/lib/active_admin/views/components/tabs.rb +4 -3
- data/lib/active_admin/views/components/unsupported_browser.rb +1 -0
- data/lib/active_admin/views/footer.rb +3 -1
- data/lib/active_admin/views/header.rb +3 -2
- data/lib/active_admin/views/index_as_block.rb +1 -0
- data/lib/active_admin/views/index_as_blog.rb +2 -1
- data/lib/active_admin/views/index_as_grid.rb +2 -1
- data/lib/active_admin/views/index_as_table.rb +24 -16
- data/lib/active_admin/views/pages/base.rb +19 -12
- data/lib/active_admin/views/pages/form.rb +1 -0
- data/lib/active_admin/views/pages/index.rb +16 -13
- 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 +3 -2
- data/lib/active_admin/views/title_bar.rb +2 -1
- data/lib/active_admin/views.rb +2 -1
- data/lib/active_admin.rb +63 -64
- data/lib/activeadmin.rb +2 -1
- data/lib/generators/active_admin/assets/assets_generator.rb +3 -2
- data/lib/generators/active_admin/assets/templates/active_admin.scss +2 -2
- data/lib/generators/active_admin/devise/devise_generator.rb +6 -5
- data/lib/generators/active_admin/install/install_generator.rb +15 -8
- data/lib/generators/active_admin/install/templates/active_admin.rb.erb +21 -1
- data/lib/generators/active_admin/install/templates/dashboard.rb +1 -0
- data/lib/generators/active_admin/page/page_generator.rb +2 -1
- data/lib/generators/active_admin/page/templates/page.rb +1 -0
- data/lib/generators/active_admin/resource/resource_generator.rb +4 -3
- data/lib/generators/active_admin/resource/templates/admin.rb.erb +4 -2
- 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 +27 -0
- data/lib/ransack_ext.rb +9 -8
- metadata +62 -91
- data/app/assets/images/active_admin/nested_menu_arrow.gif +0 -0
- data/app/assets/images/active_admin/nested_menu_arrow_dark.gif +0 -0
- data/app/assets/images/active_admin/orderable.png +0 -0
- data/app/assets/javascripts/active_admin/base.es6 +0 -23
- data/app/assets/javascripts/active_admin/initializers/filters.es6 +0 -45
- data/app/assets/javascripts/active_admin/lib/active_admin.es6 +0 -41
- data/app/assets/javascripts/active_admin/lib/per_page.es6 +0 -47
- /data/app/{assets/javascripts/active_admin/ext/jquery-ui.es6 → javascript/active_admin/ext/jquery-ui.js} +0 -0
- /data/app/{assets/javascripts/active_admin/ext/jquery.es6 → javascript/active_admin/ext/jquery.js} +0 -0
- /data/app/{assets/javascripts/active_admin/initializers/datepicker.es6 → javascript/active_admin/initializers/datepicker.js} +0 -0
- /data/app/{assets/javascripts/active_admin/initializers/tabs.es6 → javascript/active_admin/initializers/tabs.js} +0 -0
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module ActiveAdmin
|
2
3
|
class Resource
|
3
4
|
module ScopeTo
|
@@ -38,10 +39,10 @@ module ActiveAdmin
|
|
38
39
|
options = args.extract_options!
|
39
40
|
method = args.first
|
40
41
|
|
41
|
-
scope_to_config[:method]
|
42
|
-
scope_to_config[:association_method]
|
43
|
-
scope_to_config[:if]
|
44
|
-
scope_to_config[:unless]
|
42
|
+
scope_to_config[:method] = block || method
|
43
|
+
scope_to_config[:association_method] = options[:association_method]
|
44
|
+
scope_to_config[:if] = options[:if]
|
45
|
+
scope_to_config[:unless] = options[:unless]
|
45
46
|
|
46
47
|
end
|
47
48
|
|
@@ -55,10 +56,10 @@ module ActiveAdmin
|
|
55
56
|
|
56
57
|
def scope_to_config
|
57
58
|
@scope_to_config ||= {
|
58
|
-
method:
|
59
|
+
method: nil,
|
59
60
|
association_method: nil,
|
60
|
-
if:
|
61
|
-
unless:
|
61
|
+
if: nil,
|
62
|
+
unless: nil
|
62
63
|
}
|
63
64
|
end
|
64
65
|
|
@@ -1,17 +1,19 @@
|
|
1
|
-
|
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
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "active_admin/resource/action_items"
|
3
|
+
require "active_admin/resource/attributes"
|
4
|
+
require "active_admin/resource/controllers"
|
5
|
+
require "active_admin/resource/menu"
|
6
|
+
require "active_admin/resource/page_presenters"
|
7
|
+
require "active_admin/resource/pagination"
|
8
|
+
require "active_admin/resource/routes"
|
9
|
+
require "active_admin/resource/naming"
|
10
|
+
require "active_admin/resource/scopes"
|
11
|
+
require "active_admin/resource/includes"
|
12
|
+
require "active_admin/resource/scope_to"
|
13
|
+
require "active_admin/resource/sidebars"
|
14
|
+
require "active_admin/resource/belongs_to"
|
15
|
+
require "active_admin/resource/ordering"
|
16
|
+
require "active_admin/resource/model"
|
15
17
|
|
16
18
|
module ActiveAdmin
|
17
19
|
|
@@ -26,7 +28,7 @@ module ActiveAdmin
|
|
26
28
|
class Resource
|
27
29
|
|
28
30
|
# Event dispatched when a new resource is registered
|
29
|
-
RegisterEvent =
|
31
|
+
RegisterEvent = "active_admin.resource.register".freeze
|
30
32
|
|
31
33
|
# The namespace this config belongs to
|
32
34
|
attr_reader :namespace
|
@@ -43,7 +45,7 @@ module ActiveAdmin
|
|
43
45
|
# The default sort order to use in the controller
|
44
46
|
attr_writer :sort_order
|
45
47
|
def sort_order
|
46
|
-
@sort_order ||= (resource_class.respond_to?(:primary_key) ? resource_class.primary_key.to_s :
|
48
|
+
@sort_order ||= (resource_class.respond_to?(:primary_key) ? resource_class.primary_key.to_s : "id") + "_desc"
|
47
49
|
end
|
48
50
|
|
49
51
|
# Set the configuration for the CSV
|
@@ -69,7 +71,7 @@ module ActiveAdmin
|
|
69
71
|
def initialize(namespace, resource_class, options = {})
|
70
72
|
@namespace = namespace
|
71
73
|
@resource_class_name = "::#{resource_class.name}"
|
72
|
-
@options
|
74
|
+
@options = options
|
73
75
|
@sort_order = options[:sort_order]
|
74
76
|
@member_actions = []
|
75
77
|
@collection_actions = []
|
@@ -97,11 +99,15 @@ module ActiveAdmin
|
|
97
99
|
# The class this resource wraps. If you register the Post model, Resource#resource_class
|
98
100
|
# will point to the Post class
|
99
101
|
def resource_class
|
100
|
-
|
102
|
+
resource_class_name.constantize
|
101
103
|
end
|
102
104
|
|
103
105
|
def decorator_class
|
104
|
-
|
106
|
+
decorator_class_name&.constantize
|
107
|
+
end
|
108
|
+
|
109
|
+
def resource_name_extension
|
110
|
+
@resource_name_extension ||= define_resource_name_extension(self)
|
105
111
|
end
|
106
112
|
|
107
113
|
def resource_table_name
|
@@ -133,6 +139,7 @@ module ActiveAdmin
|
|
133
139
|
def belongs_to(target, options = {})
|
134
140
|
@belongs_to = Resource::BelongsTo.new(self, target, options)
|
135
141
|
self.menu_item_options = false if @belongs_to.required?
|
142
|
+
options[:class_name] ||= @belongs_to.resource.resource_class_name if @belongs_to.resource
|
136
143
|
controller.send :belongs_to, target, options.dup
|
137
144
|
end
|
138
145
|
|
@@ -203,5 +210,12 @@ module ActiveAdmin
|
|
203
210
|
@default_csv_builder ||= CSVBuilder.default_for_resource(self)
|
204
211
|
end
|
205
212
|
|
213
|
+
def define_resource_name_extension(resource)
|
214
|
+
Module.new do
|
215
|
+
define_method :model_name do
|
216
|
+
resource.resource_name
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
206
220
|
end # class Resource
|
207
221
|
end # module ActiveAdmin
|
@@ -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,21 +250,32 @@ 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 = {})
|
261
|
-
only
|
263
|
+
only = Array(options.fetch(:only, COLLECTION_APPLIES))
|
262
264
|
except = Array(options.fetch(:except, []))
|
263
265
|
|
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
|
module ActiveAdmin
|
2
3
|
class ResourceController < BaseController
|
3
4
|
module Decorators
|
@@ -28,7 +29,7 @@ module ActiveAdmin
|
|
28
29
|
|
29
30
|
def decorate?
|
30
31
|
case action_name
|
31
|
-
when
|
32
|
+
when "new", "edit", "create", "update"
|
32
33
|
form = active_admin_config.get_page_presenter :form
|
33
34
|
form && form.options[:decorate] && decorator_class.present?
|
34
35
|
else
|
@@ -53,49 +54,27 @@ module ActiveAdmin
|
|
53
54
|
|
54
55
|
def self.wrap(decorator)
|
55
56
|
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
|
57
|
+
name = "#{collection_decorator.name} of #{decorator} + ActiveAdmin"
|
58
|
+
@cache[name] ||= wrap! collection_decorator, name
|
63
59
|
end
|
64
60
|
|
65
|
-
private
|
66
|
-
|
67
61
|
def self.wrap!(parent, name)
|
68
62
|
::Class.new parent do
|
69
63
|
delegate :reorder, :page, :current_page, :total_pages, :limit_value,
|
70
|
-
:total_count, :total_pages, :
|
71
|
-
:find_each, :ransack
|
64
|
+
:total_count, :total_pages, :offset, :to_key, :group_values,
|
65
|
+
:except, :find_each, :ransack, to: :object
|
72
66
|
|
73
67
|
define_singleton_method(:name) { name }
|
74
68
|
end
|
75
69
|
end
|
76
70
|
|
77
|
-
# Draper::CollectionDecorator was introduced in 1.0.0
|
78
|
-
# Draper::Decorator#collection_decorator_class was introduced in 1.3.0
|
79
71
|
def self.find_collection_decorator(decorator)
|
80
|
-
if
|
72
|
+
if decorator.respond_to?(:collection_decorator_class)
|
81
73
|
decorator.collection_decorator_class
|
82
|
-
elsif Dependency.draper? '>= 1.0.0'
|
83
|
-
draper_collection_decorator
|
84
74
|
else
|
85
|
-
|
75
|
+
CollectionDecorator
|
86
76
|
end
|
87
77
|
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
78
|
end
|
100
79
|
end
|
101
80
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "active_admin/resource"
|
3
|
+
require "active_admin/resource/model"
|
4
|
+
|
5
|
+
module ActiveAdmin
|
6
|
+
class ResourceController < BaseController
|
7
|
+
module PolymorphicRoutes
|
8
|
+
def polymorphic_url(record_or_hash_or_array, options = {})
|
9
|
+
super(map_named_resources_for(record_or_hash_or_array), options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def polymorphic_path(record_or_hash_or_array, options = {})
|
13
|
+
super(map_named_resources_for(record_or_hash_or_array), options)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def map_named_resources_for(record_or_hash_or_array)
|
19
|
+
return record_or_hash_or_array unless record_or_hash_or_array.is_a?(Array)
|
20
|
+
|
21
|
+
record_or_hash_or_array.map { |record| to_named_resource(record) }
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_named_resource(record)
|
25
|
+
if record.is_a?(resource_class)
|
26
|
+
return ActiveAdmin::Model.new(active_admin_config, record)
|
27
|
+
end
|
28
|
+
|
29
|
+
belongs_to_resource = active_admin_config.belongs_to_config.try(:resource)
|
30
|
+
if belongs_to_resource && record.is_a?(belongs_to_resource.resource_class)
|
31
|
+
return ActiveAdmin::Model.new(belongs_to_resource, record)
|
32
|
+
end
|
33
|
+
|
34
|
+
record
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "csv"
|
2
3
|
|
3
4
|
module ActiveAdmin
|
4
5
|
class ResourceController < BaseController
|
@@ -18,23 +19,24 @@ module ActiveAdmin
|
|
18
19
|
protected
|
19
20
|
|
20
21
|
def stream_resource(&block)
|
21
|
-
headers[
|
22
|
-
headers[
|
22
|
+
headers["X-Accel-Buffering"] = "no"
|
23
|
+
headers["Cache-Control"] = "no-cache"
|
24
|
+
headers["Last-Modified"] = Time.current.httpdate
|
23
25
|
|
24
26
|
if ActiveAdmin.application.disable_streaming_in.include? Rails.env
|
25
|
-
self.response_body = block[
|
27
|
+
self.response_body = block[String.new]
|
26
28
|
else
|
27
29
|
self.response_body = Enumerator.new &block
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
31
33
|
def csv_filename
|
32
|
-
"#{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"
|
33
35
|
end
|
34
36
|
|
35
37
|
def stream_csv
|
36
|
-
headers[
|
37
|
-
headers[
|
38
|
+
headers["Content-Type"] = "text/csv; charset=utf-8" # In Rails 5 it's set to HTML??
|
39
|
+
headers["Content-Disposition"] = %{attachment; filename="#{csv_filename}"}
|
38
40
|
stream_resource &active_admin_config.csv_builder.method(:build).to_proc.curry[self]
|
39
41
|
end
|
40
42
|
|
@@ -1,10 +1,13 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "active_admin/collection_decorator"
|
3
|
+
require "active_admin/resource_controller/action_builder"
|
4
|
+
require "active_admin/resource_controller/data_access"
|
5
|
+
require "active_admin/resource_controller/decorators"
|
6
|
+
require "active_admin/resource_controller/polymorphic_routes"
|
7
|
+
require "active_admin/resource_controller/scoping"
|
8
|
+
require "active_admin/resource_controller/streaming"
|
9
|
+
require "active_admin/resource_controller/sidebars"
|
10
|
+
require "active_admin/resource_controller/resource_class_methods"
|
8
11
|
|
9
12
|
module ActiveAdmin
|
10
13
|
# All Resources Controller inherits from this controller.
|
@@ -18,17 +21,18 @@ module ActiveAdmin
|
|
18
21
|
include ActionBuilder
|
19
22
|
include Decorators
|
20
23
|
include DataAccess
|
24
|
+
include PolymorphicRoutes
|
21
25
|
include Scoping
|
22
26
|
include Streaming
|
23
27
|
include Sidebars
|
24
28
|
include ViewHelpers::DownloadFormatLinksHelper
|
25
|
-
extend
|
29
|
+
extend ResourceClassMethods
|
26
30
|
|
27
31
|
def self.active_admin_config=(config)
|
28
32
|
if @active_admin_config = config
|
29
33
|
defaults resource_class: config.resource_class,
|
30
|
-
route_prefix:
|
31
|
-
instance_name:
|
34
|
+
route_prefix: config.route_prefix,
|
35
|
+
instance_name: config.resource_name.singular
|
32
36
|
end
|
33
37
|
end
|
34
38
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module ActiveAdmin
|
2
3
|
# This is the class where all the register blocks are evaluated.
|
3
4
|
class ResourceDSL < DSL
|
@@ -62,11 +63,12 @@ module ActiveAdmin
|
|
62
63
|
#
|
63
64
|
def permit_params(*args, &block)
|
64
65
|
param_key = config.param_key.to_sym
|
65
|
-
belongs_to_param = config.belongs_to_param
|
66
|
-
create_another_param = :create_another if config.create_another
|
67
66
|
|
68
67
|
controller do
|
69
68
|
define_method :permitted_params do
|
69
|
+
belongs_to_param = active_admin_config.belongs_to_param
|
70
|
+
create_another_param = :create_another if active_admin_config.create_another
|
71
|
+
|
70
72
|
permitted_params =
|
71
73
|
active_admin_namespace.permitted_params +
|
72
74
|
Array.wrap(belongs_to_param) +
|
@@ -183,31 +185,15 @@ module ActiveAdmin
|
|
183
185
|
# == Before / After Destroy
|
184
186
|
# Called before and after the object is destroyed from the database.
|
185
187
|
#
|
186
|
-
delegate :before_build,
|
187
|
-
delegate :before_create,
|
188
|
-
delegate :before_update,
|
189
|
-
delegate :before_save,
|
188
|
+
delegate :before_build, :after_build, to: :controller
|
189
|
+
delegate :before_create, :after_create, to: :controller
|
190
|
+
delegate :before_update, :after_update, to: :controller
|
191
|
+
delegate :before_save, :after_save, to: :controller
|
190
192
|
delegate :before_destroy, :after_destroy, to: :controller
|
191
193
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
:after, :skip_after,
|
196
|
-
:around, :skip
|
197
|
-
]
|
198
|
-
keywords = if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR >= 1
|
199
|
-
[:action]
|
200
|
-
else
|
201
|
-
[:action, :filter]
|
202
|
-
end
|
203
|
-
|
204
|
-
keywords.each do |name|
|
205
|
-
phases.each do |action|
|
206
|
-
define_method "#{action}_#{name}" do |*args, &block|
|
207
|
-
controller.public_send "#{action}_action", *args, &block
|
208
|
-
end
|
209
|
-
end
|
210
|
-
end
|
194
|
+
standard_rails_filters =
|
195
|
+
AbstractController::Callbacks::ClassMethods.public_instance_methods.select { |m| m.match(/_action\z/) }
|
196
|
+
delegate *standard_rails_filters, to: :controller
|
211
197
|
|
212
198
|
# Specify which actions to create in the controller
|
213
199
|
#
|
data/lib/active_admin/router.rb
CHANGED
data/lib/active_admin/scope.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module ActiveAdmin
|
2
3
|
class Scope
|
3
4
|
|
@@ -45,17 +46,17 @@ module ActiveAdmin
|
|
45
46
|
@scope_block = block
|
46
47
|
end
|
47
48
|
|
48
|
-
@localizer
|
49
|
-
@show_count
|
50
|
-
@display_if_block = options[:if]
|
51
|
-
@default_block
|
52
|
-
@group
|
49
|
+
@localizer = options[:localizer]
|
50
|
+
@show_count = options.fetch(:show_count, true)
|
51
|
+
@display_if_block = options[:if] || proc { true }
|
52
|
+
@default_block = options[:default] || proc { false }
|
53
|
+
@group = options[:group].try(:to_sym)
|
53
54
|
end
|
54
55
|
|
55
56
|
def name
|
56
57
|
case @name
|
57
58
|
when String then @name
|
58
|
-
when Symbol then @localizer ? @localizer.t(@name, scope:
|
59
|
+
when Symbol then @localizer ? @localizer.t(@name, scope: "scopes") : @name.to_s.titleize
|
59
60
|
else @name
|
60
61
|
end
|
61
62
|
end
|
data/lib/active_admin/version.rb
CHANGED
@@ -1,27 +1,28 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "active_admin/abstract_view_factory"
|
2
3
|
|
3
4
|
module ActiveAdmin
|
4
5
|
class ViewFactory < AbstractViewFactory
|
5
6
|
|
6
7
|
# Register Helper Renderers
|
7
|
-
register
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
8
|
+
register global_navigation: ActiveAdmin::Views::TabbedNavigation,
|
9
|
+
utility_navigation: ActiveAdmin::Views::TabbedNavigation,
|
10
|
+
site_title: ActiveAdmin::Views::SiteTitle,
|
11
|
+
unsupported_browser: ActiveAdmin::Views::UnsupportedBrowser,
|
12
|
+
action_items: ActiveAdmin::Views::ActionItems,
|
13
|
+
title_bar: ActiveAdmin::Views::TitleBar,
|
14
|
+
header: ActiveAdmin::Views::Header,
|
15
|
+
footer: ActiveAdmin::Views::Footer,
|
16
|
+
index_scopes: ActiveAdmin::Views::Scopes,
|
17
|
+
blank_slate: ActiveAdmin::Views::BlankSlate
|
17
18
|
|
18
19
|
# Register All The Pages
|
19
|
-
register
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
register index_page: ActiveAdmin::Views::Pages::Index,
|
21
|
+
show_page: ActiveAdmin::Views::Pages::Show,
|
22
|
+
new_page: ActiveAdmin::Views::Pages::Form,
|
23
|
+
edit_page: ActiveAdmin::Views::Pages::Form,
|
24
|
+
layout: ActiveAdmin::Views::Pages::Layout,
|
25
|
+
page: ActiveAdmin::Views::Pages::Page
|
25
26
|
|
26
27
|
end
|
27
28
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module ActiveAdmin
|
2
3
|
module ViewHelpers
|
3
4
|
module BreadcrumbHelper
|
@@ -6,7 +7,7 @@ module ActiveAdmin
|
|
6
7
|
def breadcrumb_links(path = request.path)
|
7
8
|
# remove leading "/" and split up the URL
|
8
9
|
# and remove last since it's used as the page title
|
9
|
-
parts = path.split(
|
10
|
+
parts = path.split("/").select(&:present?)[0..-2]
|
10
11
|
|
11
12
|
parts.each_with_index.map do |part, index|
|
12
13
|
# 1. try using `display_name` if we can locate a DB object
|
@@ -15,13 +16,13 @@ module ActiveAdmin
|
|
15
16
|
if part =~ /\A(\d+|[a-f0-9]{24}|(?:[a-f0-9]{8}-(?:[a-f0-9]{4}-){3}[a-f0-9]{12}))\z/ && parts[index - 1]
|
16
17
|
parent = active_admin_config.belongs_to_config.try :target
|
17
18
|
config = parent && parent.resource_name.route_key == parts[index - 1] ? parent : active_admin_config
|
18
|
-
name
|
19
|
+
name = display_name config.find_resource part
|
19
20
|
end
|
20
21
|
name ||= I18n.t "activerecord.models.#{part.singularize}", count: ::ActiveAdmin::Helpers::I18n::PLURAL_MANY_COUNT, default: part.titlecase
|
21
22
|
|
22
23
|
# Don't create a link if the resource's show action is disabled
|
23
24
|
if !config || config.defined_actions.include?(:show)
|
24
|
-
link_to name,
|
25
|
+
link_to name, "/" + parts[0..index].join("/")
|
25
26
|
else
|
26
27
|
name
|
27
28
|
end
|