activeadmin 2.6.1 → 2.13.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 +291 -9
- data/CONTRIBUTING.md +9 -25
- data/README.md +4 -4
- data/app/assets/javascripts/active_admin/base.js +27 -22
- 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 +37 -3
- data/app/assets/stylesheets/active_admin/_normalize.scss +25 -123
- data/app/assets/stylesheets/active_admin/{print.scss → _print.scss} +0 -0
- 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/mixins/_variables.scss +12 -0
- 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/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/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/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/es-MX.yml +2 -1
- data/config/locales/es.yml +2 -2
- data/config/locales/it.yml +18 -0
- data/config/locales/ja.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 +5 -5
- data/docs/0-installation.md +27 -3
- data/docs/11-decorators.md +16 -5
- data/docs/2-resource-customization.md +10 -1
- data/docs/5-forms.md +9 -3
- data/docs/6-show-pages.md +12 -0
- data/docs/8-custom-actions.md +1 -1
- data/docs/Gemfile +3 -2
- data/docs/Gemfile.lock +138 -103
- data/docs/_includes/top-menu.html +1 -1
- data/docs/documentation.md +1 -1
- data/docs/index.html +6 -6
- data/lib/active_admin/abstract_view_factory.rb +1 -0
- data/lib/active_admin/application.rb +19 -19
- 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 +6 -19
- 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 +6 -6
- 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 +2 -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 +2 -1
- 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 +1 -0
- 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 +15 -14
- data/lib/active_admin/namespace_settings.rb +9 -5
- data/lib/active_admin/order_clause.rb +2 -1
- 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 +59 -15
- 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 +3 -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 +1 -0
- data/lib/active_admin/resource/naming.rb +5 -4
- 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 +6 -7
- 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 +20 -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 +7 -28
- 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 +9 -7
- data/lib/active_admin/resource_controller.rb +13 -11
- 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 +19 -18
- 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 +18 -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 +17 -16
- data/lib/active_admin/views/pages/base.rb +14 -9
- data/lib/active_admin/views/pages/form.rb +1 -0
- data/lib/active_admin/views/pages/index.rb +15 -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 +61 -61
- 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 +9 -2
- 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/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 +32 -53
@@ -1,18 +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
|
15
|
-
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"
|
16
17
|
|
17
18
|
module ActiveAdmin
|
18
19
|
|
@@ -27,7 +28,7 @@ module ActiveAdmin
|
|
27
28
|
class Resource
|
28
29
|
|
29
30
|
# Event dispatched when a new resource is registered
|
30
|
-
RegisterEvent =
|
31
|
+
RegisterEvent = "active_admin.resource.register".freeze
|
31
32
|
|
32
33
|
# The namespace this config belongs to
|
33
34
|
attr_reader :namespace
|
@@ -44,7 +45,7 @@ module ActiveAdmin
|
|
44
45
|
# The default sort order to use in the controller
|
45
46
|
attr_writer :sort_order
|
46
47
|
def sort_order
|
47
|
-
@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"
|
48
49
|
end
|
49
50
|
|
50
51
|
# Set the configuration for the CSV
|
@@ -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,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
64
|
:total_count, :total_pages, :offset, :to_key, :group_values,
|
71
|
-
:except, :find_each, :ransack
|
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
|
@@ -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,11 +1,13 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
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"
|
9
11
|
|
10
12
|
module ActiveAdmin
|
11
13
|
# All Resources Controller inherits from this controller.
|
@@ -24,13 +26,13 @@ module ActiveAdmin
|
|
24
26
|
include Streaming
|
25
27
|
include Sidebars
|
26
28
|
include ViewHelpers::DownloadFormatLinksHelper
|
27
|
-
extend
|
29
|
+
extend ResourceClassMethods
|
28
30
|
|
29
31
|
def self.active_admin_config=(config)
|
30
32
|
if @active_admin_config = config
|
31
33
|
defaults resource_class: config.resource_class,
|
32
|
-
route_prefix:
|
33
|
-
instance_name:
|
34
|
+
route_prefix: config.route_prefix,
|
35
|
+
instance_name: config.resource_name.singular
|
34
36
|
end
|
35
37
|
end
|
36
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
|
@@ -1,16 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module ActiveAdmin
|
2
3
|
module ViewHelpers
|
3
4
|
module DisplayHelper
|
4
5
|
|
5
6
|
DISPLAY_NAME_FALLBACK = -> {
|
6
|
-
name = ""
|
7
7
|
klass = self.class
|
8
|
-
name
|
9
|
-
|
8
|
+
name = if klass.respond_to?(:model_name)
|
9
|
+
if klass.respond_to?(:primary_key)
|
10
|
+
"#{klass.model_name.human} ##{send(klass.primary_key)}"
|
11
|
+
else
|
12
|
+
klass.model_name.human
|
13
|
+
end
|
14
|
+
elsif klass.respond_to?(:primary_key)
|
15
|
+
" ##{send(klass.primary_key)}"
|
16
|
+
end
|
10
17
|
name.present? ? name : to_s
|
11
18
|
}
|
19
|
+
|
12
20
|
def DISPLAY_NAME_FALLBACK.inspect
|
13
|
-
|
21
|
+
"DISPLAY_NAME_FALLBACK"
|
14
22
|
end
|
15
23
|
|
16
24
|
# Attempts to call any known display name methods on the resource.
|
@@ -26,7 +34,7 @@ module ActiveAdmin
|
|
26
34
|
@@display_name_methods_cache ||= {}
|
27
35
|
@@display_name_methods_cache[resource.class] ||= begin
|
28
36
|
methods = active_admin_application.display_name_methods - association_methods_for(resource)
|
29
|
-
method
|
37
|
+
method = methods.detect { |method| resource.respond_to? method }
|
30
38
|
|
31
39
|
if method != :to_s || resource.method(method).source_location
|
32
40
|
method
|
@@ -74,7 +82,7 @@ module ActiveAdmin
|
|
74
82
|
format_collection(object)
|
75
83
|
else
|
76
84
|
if defined?(::ActiveRecord) && object.is_a?(ActiveRecord::Base) ||
|
77
|
-
defined?(::Mongoid)
|
85
|
+
defined?(::Mongoid) && object.class.include?(Mongoid::Document)
|
78
86
|
auto_link object
|
79
87
|
elsif defined?(::ActiveRecord) && object.is_a?(ActiveRecord::Relation)
|
80
88
|
format_collection(object)
|
@@ -85,7 +93,7 @@ module ActiveAdmin
|
|
85
93
|
end
|
86
94
|
|
87
95
|
def format_collection(collection)
|
88
|
-
safe_join(collection.map { |item| pretty_format(item) },
|
96
|
+
safe_join(collection.map { |item| pretty_format(item) }, ", ")
|
89
97
|
end
|
90
98
|
|
91
99
|
def boolean_attr?(resource, attr, value)
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module ActiveAdmin
|
2
3
|
module ViewHelpers
|
3
4
|
module DownloadFormatLinksHelper
|
@@ -18,7 +19,7 @@ module ActiveAdmin
|
|
18
19
|
def build_download_format_links(formats = self.class.formats)
|
19
20
|
params = request.query_parameters.except :format, :commit
|
20
21
|
div class: "download_links" do
|
21
|
-
span I18n.t(
|
22
|
+
span I18n.t("active_admin.download")
|
22
23
|
formats.each do |format|
|
23
24
|
a format.upcase, href: url_for(params: params, format: format)
|
24
25
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module ActiveAdmin
|
2
3
|
module ViewHelpers
|
3
4
|
module FormHelper
|
@@ -15,7 +16,7 @@ module ActiveAdmin
|
|
15
16
|
#
|
16
17
|
def fields_for_params(params, options = {})
|
17
18
|
namespace = options[:namespace]
|
18
|
-
except
|
19
|
+
except = Array.wrap(options[:except]).map &:to_s
|
19
20
|
|
20
21
|
params.flat_map do |k, v|
|
21
22
|
next if namespace.nil? && %w(controller action commit utf8).include?(k.to_s)
|
@@ -37,7 +38,7 @@ module ActiveAdmin
|
|
37
38
|
{ "#{k}[]" => v }
|
38
39
|
end
|
39
40
|
when nil
|
40
|
-
{ k =>
|
41
|
+
{ k => "" }
|
41
42
|
when TrueClass, FalseClass
|
42
43
|
{ k => v }
|
43
44
|
else
|