activeadmin 1.4.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +92 -11
- data/CONTRIBUTING.md +12 -11
- data/README.md +34 -8
- data/app/assets/javascripts/active_admin/base.es6 +23 -0
- data/app/assets/javascripts/active_admin/ext/jquery-ui.es6 +7 -0
- data/app/assets/javascripts/active_admin/ext/jquery.es6 +9 -0
- data/app/assets/javascripts/active_admin/initializers/datepicker.es6 +16 -0
- data/app/assets/javascripts/active_admin/initializers/filters.es6 +45 -0
- data/app/assets/javascripts/active_admin/initializers/tabs.es6 +6 -0
- data/app/assets/javascripts/active_admin/lib/active_admin.es6 +41 -0
- data/app/assets/javascripts/active_admin/lib/batch_actions.es6 +55 -0
- data/app/assets/javascripts/active_admin/lib/checkbox-toggler.es6 +49 -0
- data/app/assets/javascripts/active_admin/lib/dropdown-menu.es6 +123 -0
- data/app/assets/javascripts/active_admin/lib/has_many.es6 +95 -0
- data/app/assets/javascripts/active_admin/lib/modal_dialog.es6 +61 -0
- data/app/assets/javascripts/active_admin/lib/per_page.es6 +47 -0
- data/app/assets/javascripts/active_admin/lib/table-checkbox-toggler.es6 +36 -0
- data/app/assets/stylesheets/active_admin/_forms.scss +2 -14
- data/app/assets/stylesheets/active_admin/components/_status_tags.scss +0 -5
- data/app/assets/stylesheets/active_admin/components/_tabs.scss +1 -1
- data/app/assets/stylesheets/active_admin/mixins/_gradients.scss +1 -1
- data/app/views/active_admin/devise/confirmations/new.html.erb +1 -1
- data/app/views/active_admin/devise/passwords/edit.html.erb +1 -1
- data/app/views/active_admin/devise/passwords/new.html.erb +1 -1
- data/app/views/active_admin/devise/registrations/new.html.erb +1 -2
- data/app/views/active_admin/devise/shared/_error_messages.html.erb +15 -0
- data/app/views/active_admin/devise/unlocks/new.html.erb +1 -1
- data/app/views/layouts/active_admin_logged_out.html.erb +1 -1
- data/config/locales/bg.yml +0 -1
- data/config/locales/he.yml +0 -1
- data/config/locales/hu.yml +4 -0
- data/config/locales/lt.yml +2 -2
- data/config/locales/uk.yml +2 -0
- data/docs/0-installation.md +2 -2
- data/docs/13-authorization-adapter.md +4 -4
- data/docs/CNAME +1 -1
- data/docs/index.html +2 -2
- data/lib/active_admin/application.rb +8 -14
- data/lib/active_admin/application_settings.rb +3 -0
- data/lib/active_admin/asset_registration.rb +0 -8
- data/lib/active_admin/base_controller/authorization.rb +2 -4
- data/lib/active_admin/base_controller.rb +6 -6
- data/lib/active_admin/batch_actions/controller.rb +1 -1
- data/lib/active_admin/batch_actions/resource_extension.rb +4 -4
- data/lib/active_admin/callbacks.rb +1 -1
- data/lib/active_admin/csv_builder.rb +1 -1
- data/lib/active_admin/dependency.rb +7 -75
- data/lib/active_admin/dsl.rb +1 -8
- data/lib/active_admin/error.rb +1 -1
- data/lib/active_admin/filters/active_filter.rb +3 -1
- data/lib/active_admin/filters/active_sidebar.rb +5 -1
- data/lib/active_admin/filters/forms.rb +2 -2
- data/lib/active_admin/filters/formtastic_addons.rb +1 -1
- data/lib/active_admin/filters/resource_extension.rb +3 -3
- data/lib/active_admin/form_builder.rb +3 -3
- data/lib/active_admin/generators/boilerplate.rb +1 -1
- data/lib/active_admin/helpers/scope_chain.rb +1 -0
- data/lib/active_admin/inputs/datepicker_input.rb +1 -1
- data/lib/active_admin/inputs/filters/base/search_method_select.rb +2 -2
- data/lib/active_admin/menu_item.rb +1 -1
- data/lib/active_admin/namespace.rb +2 -2
- data/lib/active_admin/namespace_settings.rb +7 -4
- data/lib/active_admin/orm/active_record/comments/comment.rb +2 -2
- data/lib/active_admin/orm/active_record/comments/views/active_admin_comments.rb +10 -5
- data/lib/active_admin/orm/active_record/comments.rb +4 -4
- data/lib/active_admin/page_dsl.rb +1 -1
- data/lib/active_admin/pundit_adapter.rb +13 -4
- data/lib/active_admin/resource/action_items.rb +1 -1
- data/lib/active_admin/resource/attributes.rb +7 -4
- data/lib/active_admin/resource/menu.rb +3 -3
- data/lib/active_admin/resource/naming.rb +3 -3
- data/lib/active_admin/resource/routes.rb +9 -4
- data/lib/active_admin/resource/scopes.rb +3 -3
- data/lib/active_admin/resource/sidebars.rb +1 -1
- data/lib/active_admin/resource.rb +2 -2
- data/lib/active_admin/resource_collection.rb +2 -2
- data/lib/active_admin/resource_controller/action_builder.rb +10 -0
- data/lib/active_admin/resource_controller/resource_class_methods.rb +2 -0
- data/lib/active_admin/resource_dsl.rb +5 -3
- data/lib/active_admin/router.rb +1 -1
- data/lib/active_admin/scope.rb +4 -4
- data/lib/active_admin/settings_node.rb +1 -1
- data/lib/active_admin/version.rb +1 -1
- data/lib/active_admin/view_helpers/display_helper.rb +10 -2
- data/lib/active_admin/view_helpers/download_format_links_helper.rb +1 -0
- data/lib/active_admin/view_helpers/method_or_proc_helper.rb +2 -0
- data/lib/active_admin/view_helpers.rb +1 -1
- data/lib/active_admin/views/components/active_admin_form.rb +7 -1
- data/lib/active_admin/views/components/attributes_table.rb +3 -3
- data/lib/active_admin/views/components/paginated_collection.rb +1 -1
- data/lib/active_admin/views/components/sidebar_section.rb +0 -3
- data/lib/active_admin/views/components/status_tag.rb +1 -18
- data/lib/active_admin/views/components/table_for.rb +2 -2
- data/lib/active_admin/views/components/tabs.rb +11 -2
- data/lib/active_admin/views/footer.rb +1 -1
- data/lib/active_admin/views/index_as_table.rb +5 -4
- data/lib/active_admin/views/pages/base.rb +3 -0
- data/lib/active_admin/views.rb +1 -1
- data/lib/active_admin.rb +9 -4
- data/lib/generators/active_admin/assets/assets_generator.rb +2 -2
- data/lib/generators/active_admin/assets/templates/active_admin.js +1 -0
- data/lib/generators/active_admin/install/install_generator.rb +6 -2
- data/lib/generators/active_admin/install/templates/active_admin.rb.erb +20 -1
- data/lib/generators/active_admin/install/templates/dashboard.rb +2 -3
- data/lib/generators/active_admin/install/templates/migrations/create_active_admin_comments.rb.erb +1 -15
- data/lib/generators/active_admin/page/page_generator.rb +1 -1
- data/lib/generators/active_admin/resource/resource_generator.rb +1 -1
- data/lib/ransack_ext.rb +3 -3
- data/vendor/assets/javascripts/jquery-ui/form-reset-mixin.js +80 -0
- data/vendor/assets/javascripts/jquery-ui/form.js +22 -0
- data/vendor/assets/javascripts/jquery-ui/labels.js +65 -0
- data/vendor/assets/javascripts/jquery-ui/widgets/checkboxradio.js +274 -283
- metadata +106 -95
- data/.circleci/config.yml +0 -572
- data/.github/ISSUE_TEMPLATE.md +0 -20
- data/.gitignore +0 -16
- data/.mdlrc +0 -1
- data/.rspec +0 -1
- data/.rspec_parallel +0 -2
- data/.rubocop.yml +0 -99
- data/.simplecov +0 -9
- data/.yardopts +0 -7
- data/Gemfile +0 -30
- data/Gemfile.common +0 -26
- data/Gemfile.lock +0 -433
- data/Rakefile +0 -24
- data/activeadmin.gemspec +0 -32
- data/app/assets/javascripts/active_admin/base.js.coffee +0 -13
- data/app/assets/javascripts/active_admin/ext/jquery-ui.js.coffee +0 -6
- data/app/assets/javascripts/active_admin/ext/jquery.js.coffee +0 -7
- data/app/assets/javascripts/active_admin/initializers/batch_actions.js.coffee +0 -11
- data/app/assets/javascripts/active_admin/initializers/datepicker.js.coffee +0 -14
- data/app/assets/javascripts/active_admin/initializers/filters.js.coffee +0 -26
- data/app/assets/javascripts/active_admin/initializers/tabs.js.coffee +0 -7
- data/app/assets/javascripts/active_admin/lib/batch_actions.js.coffee +0 -42
- data/app/assets/javascripts/active_admin/lib/checkbox-toggler.js.coffee +0 -46
- data/app/assets/javascripts/active_admin/lib/dropdown-menu.js.coffee +0 -104
- data/app/assets/javascripts/active_admin/lib/flash.js.coffee +0 -19
- data/app/assets/javascripts/active_admin/lib/has_many.js.coffee +0 -79
- data/app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee +0 -45
- data/app/assets/javascripts/active_admin/lib/per_page.js.coffee +0 -46
- data/app/assets/javascripts/active_admin/lib/table-checkbox-toggler.js.coffee +0 -22
- data/bin/install_chromedriver.sh +0 -17
- data/config/i18n-tasks.yml +0 -26
- data/config/mdl_style.rb +0 -11
- data/cucumber.yml +0 -7
- data/gemfiles/rails_42.gemfile +0 -10
- data/gemfiles/rails_42.gemfile.lock +0 -339
- data/gemfiles/rails_50.gemfile +0 -10
- data/gemfiles/rails_50.gemfile.lock +0 -353
- data/gemfiles/rails_51.gemfile +0 -10
- data/gemfiles/rails_51.gemfile.lock +0 -353
- data/lib/active_admin/event.rb +0 -24
- data/lib/active_admin/helpers/output_safety_helper.rb +0 -35
- data/lib/bug_report_templates/active_admin_master.rb +0 -111
- data/lib/generators/active_admin/assets/templates/active_admin.js.coffee +0 -1
- data/tasks/application_generator.rb +0 -50
- data/tasks/docs.rake +0 -64
- data/tasks/gemfiles.rake +0 -8
- data/tasks/lint.rake +0 -110
- data/tasks/local.rake +0 -27
- data/tasks/release.rake +0 -6
- data/tasks/test.rake +0 -42
|
@@ -4,6 +4,7 @@ require 'pundit'
|
|
|
4
4
|
|
|
5
5
|
# Add a setting to the application to configure the pundit default policy
|
|
6
6
|
ActiveAdmin::Application.inheritable_setting :pundit_default_policy, nil
|
|
7
|
+
ActiveAdmin::Application.inheritable_setting :pundit_policy_namespace, nil
|
|
7
8
|
|
|
8
9
|
module ActiveAdmin
|
|
9
10
|
|
|
@@ -19,7 +20,7 @@ module ActiveAdmin
|
|
|
19
20
|
def scope_collection(collection, action = Auth::READ)
|
|
20
21
|
# scoping is appliable only to read/index action
|
|
21
22
|
# which means there is no way how to scope other actions
|
|
22
|
-
Pundit.policy_scope!(user, collection)
|
|
23
|
+
Pundit.policy_scope!(user, namespace(collection))
|
|
23
24
|
rescue Pundit::NotDefinedError => e
|
|
24
25
|
if default_policy_class && default_policy_class.const_defined?(:Scope)
|
|
25
26
|
default_policy_class::Scope.new(user, collection).resolve
|
|
@@ -30,9 +31,9 @@ module ActiveAdmin
|
|
|
30
31
|
|
|
31
32
|
def retrieve_policy(subject)
|
|
32
33
|
case subject
|
|
33
|
-
when nil then Pundit.policy!(user, resource)
|
|
34
|
-
when Class then Pundit.policy!(user, subject.new)
|
|
35
|
-
else Pundit.policy!(user, subject)
|
|
34
|
+
when nil then Pundit.policy!(user, namespace(resource))
|
|
35
|
+
when Class then Pundit.policy!(user, namespace(subject.new))
|
|
36
|
+
else Pundit.policy!(user, namespace(subject))
|
|
36
37
|
end
|
|
37
38
|
rescue Pundit::NotDefinedError => e
|
|
38
39
|
if default_policy_class
|
|
@@ -55,6 +56,14 @@ module ActiveAdmin
|
|
|
55
56
|
|
|
56
57
|
private
|
|
57
58
|
|
|
59
|
+
def namespace(object)
|
|
60
|
+
if ActiveAdmin.application.pundit_policy_namespace
|
|
61
|
+
[ActiveAdmin.application.pundit_policy_namespace.to_sym, object]
|
|
62
|
+
else
|
|
63
|
+
object
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
58
67
|
def default_policy_class
|
|
59
68
|
ActiveAdmin.application.pundit_default_policy && ActiveAdmin.application.pundit_default_policy.constantize
|
|
60
69
|
end
|
|
@@ -87,7 +87,7 @@ module ActiveAdmin
|
|
|
87
87
|
if controller.action_methods.include?('destroy') && authorized?(ActiveAdmin::Auth::DESTROY, resource)
|
|
88
88
|
localizer = ActiveAdmin::Localizers.resource(active_admin_config)
|
|
89
89
|
link_to localizer.t(:delete_model), resource_path(resource), method: :delete,
|
|
90
|
-
data: {confirm: localizer.t(:delete_confirmation)}
|
|
90
|
+
data: { confirm: localizer.t(:delete_confirmation) }
|
|
91
91
|
end
|
|
92
92
|
end
|
|
93
93
|
end
|
|
@@ -18,13 +18,13 @@ module ActiveAdmin
|
|
|
18
18
|
|
|
19
19
|
def foreign_methods
|
|
20
20
|
@foreign_methods ||= resource_class.reflect_on_all_associations.
|
|
21
|
-
select{ |r| r.macro == :belongs_to }.
|
|
22
|
-
reject{ |r| r.chain.length > 2 && !r.options[:polymorphic] }.
|
|
23
|
-
index_by{ |r| r.foreign_key.to_sym }
|
|
21
|
+
select { |r| r.macro == :belongs_to }.
|
|
22
|
+
reject { |r| r.chain.length > 2 && !r.options[:polymorphic] }.
|
|
23
|
+
index_by { |r| r.foreign_key.to_sym }
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def reject_col?(c)
|
|
27
|
-
primary_col?(c) || sti_col?(c) || counter_cache_col?(c)
|
|
27
|
+
primary_col?(c) || sti_col?(c) || counter_cache_col?(c) || filtered_col?(c)
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def primary_col?(c)
|
|
@@ -39,6 +39,9 @@ module ActiveAdmin
|
|
|
39
39
|
c.name.end_with?('_count')
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
+
def filtered_col?(c)
|
|
43
|
+
ActiveAdmin.application.filter_attributes.include?(c.name.to_sym)
|
|
44
|
+
end
|
|
42
45
|
end
|
|
43
46
|
end
|
|
44
47
|
end
|
|
@@ -26,9 +26,9 @@ module ActiveAdmin
|
|
|
26
26
|
resource = self
|
|
27
27
|
{
|
|
28
28
|
id: resource_name.plural,
|
|
29
|
-
label: proc{ resource.plural_resource_label },
|
|
30
|
-
url: proc{ resource.route_collection_path(params, url_options) },
|
|
31
|
-
if: proc{ authorized?(Auth::READ, menu_resource_class) }
|
|
29
|
+
label: proc { resource.plural_resource_label },
|
|
30
|
+
url: proc { resource.route_collection_path(params, url_options) },
|
|
31
|
+
if: proc { authorized?(Auth::READ, menu_resource_class) }
|
|
32
32
|
}
|
|
33
33
|
end
|
|
34
34
|
|
|
@@ -22,8 +22,8 @@ module ActiveAdmin
|
|
|
22
22
|
|
|
23
23
|
# Returns the plural version of this resource such as "Bank Accounts"
|
|
24
24
|
def plural_resource_label(options = {})
|
|
25
|
-
defaults = {count: Helpers::I18n::PLURAL_MANY_COUNT,
|
|
26
|
-
default: resource_label.pluralize.titleize}
|
|
25
|
+
defaults = { count: Helpers::I18n::PLURAL_MANY_COUNT,
|
|
26
|
+
default: resource_label.pluralize.titleize }
|
|
27
27
|
resource_name.translate defaults.merge options
|
|
28
28
|
end
|
|
29
29
|
|
|
@@ -46,7 +46,7 @@ module ActiveAdmin
|
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
def translate(options = {})
|
|
49
|
-
I18n.t i18n_key, {scope: [:activerecord, :models]}.merge(options)
|
|
49
|
+
I18n.t i18n_key, { scope: [:activerecord, :models] }.merge(options)
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
def route_key
|
|
@@ -20,7 +20,11 @@ module ActiveAdmin
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def route_edit_instance_path(resource, additional_params = {})
|
|
23
|
-
route_builder.
|
|
23
|
+
route_builder.member_action_path(:edit, resource, additional_params)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def route_member_action_path(action, resource, additional_params = {})
|
|
27
|
+
route_builder.member_action_path(action, resource, additional_params)
|
|
24
28
|
end
|
|
25
29
|
|
|
26
30
|
# Returns the routes prefix for this config
|
|
@@ -75,12 +79,13 @@ module ActiveAdmin
|
|
|
75
79
|
routes.public_send route_name, *route_instance_params(instance), additional_params
|
|
76
80
|
end
|
|
77
81
|
|
|
78
|
-
# @return [String] the path to the
|
|
82
|
+
# @return [String] the path to the member action of this resource
|
|
83
|
+
# @param action [Symbol]
|
|
79
84
|
# @param instance [ActiveRecord::Base] the instance we want the path of
|
|
80
85
|
# @example "/admin/posts/1/edit"
|
|
81
|
-
def
|
|
86
|
+
def member_action_path(action, instance, additional_params = {})
|
|
82
87
|
path = resource.resources_configuration[:self][:route_instance_name]
|
|
83
|
-
route_name = route_name(path, action:
|
|
88
|
+
route_name = route_name(path, action: action)
|
|
84
89
|
|
|
85
90
|
routes.public_send route_name, *route_instance_params(instance), additional_params
|
|
86
91
|
end
|
|
@@ -10,7 +10,7 @@ module ActiveAdmin
|
|
|
10
10
|
# Returns a scope for this object by its identifier
|
|
11
11
|
def get_scope_by_id(id)
|
|
12
12
|
id = id.to_s
|
|
13
|
-
scopes.find{|s| s.id == id }
|
|
13
|
+
scopes.find { |s| s.id == id }
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def default_scope(context = nil)
|
|
@@ -27,7 +27,7 @@ module ActiveAdmin
|
|
|
27
27
|
# If you want to internationalize the scope name, you can add
|
|
28
28
|
# to your i18n files a key like "active_admin.scopes.scope_method".
|
|
29
29
|
def scope(*args, &block)
|
|
30
|
-
default_options = {show_count: namespace.scopes_show_count}
|
|
30
|
+
default_options = { show_count: namespace.scopes_show_count }
|
|
31
31
|
options = default_options.merge(args.extract_options!)
|
|
32
32
|
title = args[0] rescue nil
|
|
33
33
|
method = args[1] rescue nil
|
|
@@ -36,7 +36,7 @@ module ActiveAdmin
|
|
|
36
36
|
scope = ActiveAdmin::Scope.new(title, method, options, &block)
|
|
37
37
|
|
|
38
38
|
# Finds and replaces a scope by the same name if it already exists
|
|
39
|
-
existing_scope_index = scopes.index{|existing_scope| existing_scope.id == scope.id }
|
|
39
|
+
existing_scope_index = scopes.index { |existing_scope| existing_scope.id == scope.id }
|
|
40
40
|
if existing_scope_index
|
|
41
41
|
scopes.delete_at(existing_scope_index)
|
|
42
42
|
scopes.insert(existing_scope_index, scope)
|
|
@@ -14,7 +14,7 @@ module ActiveAdmin
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def sidebar_sections_for(action, render_context = nil)
|
|
17
|
-
sidebar_sections.select{|section| section.display_on?(action, render_context) }
|
|
17
|
+
sidebar_sections.select { |section| section.display_on?(action, render_context) }
|
|
18
18
|
.sort_by(&:priority)
|
|
19
19
|
end
|
|
20
20
|
|
|
@@ -181,11 +181,11 @@ module ActiveAdmin
|
|
|
181
181
|
end
|
|
182
182
|
|
|
183
183
|
def association_columns
|
|
184
|
-
@association_columns ||= resource_attributes.select{ |key, value| key != value }.values
|
|
184
|
+
@association_columns ||= resource_attributes.select { |key, value| key != value }.values
|
|
185
185
|
end
|
|
186
186
|
|
|
187
187
|
def content_columns
|
|
188
|
-
@content_columns ||= resource_attributes.select{ |key, value| key == value }.values
|
|
188
|
+
@content_columns ||= resource_attributes.select { |key, value| key == value }.values
|
|
189
189
|
end
|
|
190
190
|
|
|
191
191
|
private
|
|
@@ -38,12 +38,12 @@ module ActiveAdmin
|
|
|
38
38
|
r.resource_class.to_s == obj.to_s
|
|
39
39
|
end ||
|
|
40
40
|
if obj.respond_to? :base_class
|
|
41
|
-
resources.detect{ |r| r.resource_class.to_s == obj.base_class.to_s }
|
|
41
|
+
resources.detect { |r| r.resource_class.to_s == obj.base_class.to_s }
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
def resources
|
|
46
|
-
select{ |r| r.class <= Resource } # can otherwise be a Page
|
|
46
|
+
select { |r| r.class <= Resource } # can otherwise be a Page
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
def raise_if_mismatched!(existing, given)
|
|
@@ -7,12 +7,22 @@ module ActiveAdmin
|
|
|
7
7
|
module ClassMethods
|
|
8
8
|
|
|
9
9
|
def clear_member_actions!
|
|
10
|
+
remove_action_methods(:member)
|
|
10
11
|
active_admin_config.clear_member_actions!
|
|
11
12
|
end
|
|
12
13
|
|
|
13
14
|
def clear_collection_actions!
|
|
15
|
+
remove_action_methods(:collection)
|
|
14
16
|
active_admin_config.clear_collection_actions!
|
|
15
17
|
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def remove_action_methods(actions_type)
|
|
22
|
+
active_admin_config.public_send("#{actions_type}_actions").each do |action|
|
|
23
|
+
remove_method action.name
|
|
24
|
+
end
|
|
25
|
+
end
|
|
16
26
|
end
|
|
17
27
|
|
|
18
28
|
end
|
|
@@ -74,6 +74,8 @@ module ActiveAdmin
|
|
|
74
74
|
|
|
75
75
|
params.permit(*permitted_params, param_key => block ? instance_exec(&block) : args)
|
|
76
76
|
end
|
|
77
|
+
|
|
78
|
+
private :permitted_params
|
|
77
79
|
end
|
|
78
80
|
end
|
|
79
81
|
|
|
@@ -119,7 +121,7 @@ module ActiveAdmin
|
|
|
119
121
|
#
|
|
120
122
|
# ActiveAdmin.register Post do
|
|
121
123
|
# member_action :comments do
|
|
122
|
-
# @post = Post.find(params[:id]
|
|
124
|
+
# @post = Post.find(params[:id])
|
|
123
125
|
# @comments = @post.comments
|
|
124
126
|
# end
|
|
125
127
|
# end
|
|
@@ -138,7 +140,7 @@ module ActiveAdmin
|
|
|
138
140
|
|
|
139
141
|
controller do
|
|
140
142
|
before_action(only: [name]) { @page_title = title } if title
|
|
141
|
-
define_method(name, &block || Proc.new{})
|
|
143
|
+
define_method(name, &block || Proc.new {})
|
|
142
144
|
end
|
|
143
145
|
end
|
|
144
146
|
|
|
@@ -187,7 +189,7 @@ module ActiveAdmin
|
|
|
187
189
|
delegate :before_save, :after_save, to: :controller
|
|
188
190
|
delegate :before_destroy, :after_destroy, to: :controller
|
|
189
191
|
|
|
190
|
-
# This code defines both *_filter and *_action for Rails
|
|
192
|
+
# This code defines both *_filter and *_action for Rails 5.0 and *_action for Rails >= 5.1
|
|
191
193
|
phases = [
|
|
192
194
|
:before, :skip_before,
|
|
193
195
|
:after, :skip_after,
|
data/lib/active_admin/router.rb
CHANGED
|
@@ -28,7 +28,7 @@ module ActiveAdmin
|
|
|
28
28
|
|
|
29
29
|
# Defines the routes for each resource
|
|
30
30
|
def define_resources_routes
|
|
31
|
-
resources = namespaces.flat_map{ |n| n.resources.values }
|
|
31
|
+
resources = namespaces.flat_map { |n| n.resources.values }
|
|
32
32
|
resources.each do |config|
|
|
33
33
|
define_resource_routes(config)
|
|
34
34
|
end
|
data/lib/active_admin/scope.rb
CHANGED
|
@@ -32,10 +32,10 @@ module ActiveAdmin
|
|
|
32
32
|
|
|
33
33
|
if name.is_a? Proc
|
|
34
34
|
raise "A string/symbol is required as the second argument if your label is a proc." unless method
|
|
35
|
-
@id =
|
|
35
|
+
@id = method.to_s.parameterize(separator: "_")
|
|
36
36
|
else
|
|
37
37
|
@scope_method ||= name.to_sym
|
|
38
|
-
@id =
|
|
38
|
+
@id = name.to_s.parameterize(separator: "_")
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
@scope_method = nil if @scope_method == :all
|
|
@@ -43,8 +43,8 @@ module ActiveAdmin
|
|
|
43
43
|
|
|
44
44
|
@localizer = options[:localizer]
|
|
45
45
|
@show_count = options.fetch(:show_count, true)
|
|
46
|
-
@display_if_block = options[:if] || proc{ true }
|
|
47
|
-
@default_block = options[:default] || proc{ false }
|
|
46
|
+
@display_if_block = options[:if] || proc { true }
|
|
47
|
+
@default_block = options[:default] || proc { false }
|
|
48
48
|
@group = options[:group].try(:to_sym)
|
|
49
49
|
end
|
|
50
50
|
|
|
@@ -5,7 +5,7 @@ module ActiveAdmin
|
|
|
5
5
|
# Never instantiated. Variables are stored in the singleton_class.
|
|
6
6
|
private_class_method :new
|
|
7
7
|
|
|
8
|
-
# @
|
|
8
|
+
# @return anonymous class with same accessors as the superclass.
|
|
9
9
|
def build(superclass = self)
|
|
10
10
|
Class.new(superclass)
|
|
11
11
|
end
|
data/lib/active_admin/version.rb
CHANGED
|
@@ -2,7 +2,7 @@ module ActiveAdmin
|
|
|
2
2
|
module ViewHelpers
|
|
3
3
|
module DisplayHelper
|
|
4
4
|
|
|
5
|
-
DISPLAY_NAME_FALLBACK = ->{
|
|
5
|
+
DISPLAY_NAME_FALLBACK = -> {
|
|
6
6
|
name, klass = "", self.class
|
|
7
7
|
name << klass.model_name.human if klass.respond_to? :model_name
|
|
8
8
|
name << " ##{send(klass.primary_key)}" if klass.respond_to? :primary_key
|
|
@@ -25,7 +25,7 @@ module ActiveAdmin
|
|
|
25
25
|
@@display_name_methods_cache ||= {}
|
|
26
26
|
@@display_name_methods_cache[resource.class] ||= begin
|
|
27
27
|
methods = active_admin_application.display_name_methods - association_methods_for(resource)
|
|
28
|
-
method = methods.detect{ |method| resource.respond_to? method }
|
|
28
|
+
method = methods.detect { |method| resource.respond_to? method }
|
|
29
29
|
|
|
30
30
|
if method != :to_s || resource.method(method).source_location
|
|
31
31
|
method
|
|
@@ -69,16 +69,24 @@ module ActiveAdmin
|
|
|
69
69
|
object.to_s
|
|
70
70
|
when Date, Time
|
|
71
71
|
I18n.localize object, format: active_admin_application.localize_format
|
|
72
|
+
when Array
|
|
73
|
+
format_collection(object)
|
|
72
74
|
else
|
|
73
75
|
if defined?(::ActiveRecord) && object.is_a?(ActiveRecord::Base) ||
|
|
74
76
|
defined?(::Mongoid) && object.class.include?(Mongoid::Document)
|
|
75
77
|
auto_link object
|
|
78
|
+
elsif defined?(::ActiveRecord) && object.is_a?(ActiveRecord::Relation)
|
|
79
|
+
format_collection(object)
|
|
76
80
|
else
|
|
77
81
|
display_name object
|
|
78
82
|
end
|
|
79
83
|
end
|
|
80
84
|
end
|
|
81
85
|
|
|
86
|
+
def format_collection(collection)
|
|
87
|
+
safe_join(collection.map { |item| pretty_format(item) }, ', ')
|
|
88
|
+
end
|
|
89
|
+
|
|
82
90
|
def boolean_attr?(resource, attr, value)
|
|
83
91
|
case value
|
|
84
92
|
when TrueClass, FalseClass
|
|
@@ -2,7 +2,7 @@ module ActiveAdmin
|
|
|
2
2
|
module ViewHelpers
|
|
3
3
|
|
|
4
4
|
# Require all ruby files in the view helpers dir
|
|
5
|
-
Dir[File.expand_path('
|
|
5
|
+
Dir[File.expand_path('view_helpers', __dir__) + "/*.rb"].each { |f| require f }
|
|
6
6
|
|
|
7
7
|
include ActiveAdminApplicationHelper
|
|
8
8
|
include AutoLinkHelper
|
|
@@ -57,6 +57,12 @@ module ActiveAdmin
|
|
|
57
57
|
end
|
|
58
58
|
insert_tag(SemanticInputsProxy, form_builder, *args, &wrapped_block)
|
|
59
59
|
else
|
|
60
|
+
# Set except option to prevent sensitive fields from being shown in forms by default.
|
|
61
|
+
opts = args.extract_options!
|
|
62
|
+
opts[:except] ||= []
|
|
63
|
+
ActiveAdmin.application.filter_attributes.each { |e| opts[:except] << e }
|
|
64
|
+
args << opts
|
|
65
|
+
|
|
60
66
|
proxy_call_to_form(:inputs, *args, &block)
|
|
61
67
|
end
|
|
62
68
|
end
|
|
@@ -125,7 +131,7 @@ module ActiveAdmin
|
|
|
125
131
|
legend = args.shift if args.first.is_a?(::String)
|
|
126
132
|
legend = html_options.delete(:name) if html_options.key?(:name)
|
|
127
133
|
legend_tag = legend ? "<legend><span>#{legend}</span></legend>" : ""
|
|
128
|
-
fieldset_attrs = html_options.map {|k, v| %Q{#{k}="#{v}"} }.join(" ")
|
|
134
|
+
fieldset_attrs = html_options.map { |k, v| %Q{#{k}="#{v}"} }.join(" ")
|
|
129
135
|
@opening_tag = "<fieldset #{fieldset_attrs}>#{legend_tag}<ol>"
|
|
130
136
|
@closing_tag = "</ol></fieldset>"
|
|
131
137
|
super(*(args << html_options), &block)
|
|
@@ -7,7 +7,7 @@ module ActiveAdmin
|
|
|
7
7
|
def build(obj, *attrs)
|
|
8
8
|
@collection = Array.wrap(obj)
|
|
9
9
|
@resource_class = @collection.first.class
|
|
10
|
-
options = {
|
|
10
|
+
options = {}
|
|
11
11
|
options[:for] = @collection.first if single_record?
|
|
12
12
|
super(options)
|
|
13
13
|
@table = table
|
|
@@ -16,7 +16,7 @@ module ActiveAdmin
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def rows(*attrs)
|
|
19
|
-
attrs.each {|attr| row(attr) }
|
|
19
|
+
attrs.each { |attr| row(attr) }
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def row(*args, &block)
|
|
@@ -26,7 +26,7 @@ module ActiveAdmin
|
|
|
26
26
|
if options[:class]
|
|
27
27
|
classes << options[:class]
|
|
28
28
|
elsif title.present?
|
|
29
|
-
classes << "row-#{
|
|
29
|
+
classes << "row-#{title.to_s.parameterize(separator: "_")}"
|
|
30
30
|
end
|
|
31
31
|
options[:class] = classes.join(' ')
|
|
32
32
|
|
|
@@ -102,7 +102,7 @@ module ActiveAdmin
|
|
|
102
102
|
# you pass in the :total_pages option. We issue a query to determine
|
|
103
103
|
# if there is another page or not, but the limit/offset make this
|
|
104
104
|
# query fast.
|
|
105
|
-
offset = collection.offset(collection.current_page *
|
|
105
|
+
offset = collection.offset(collection.current_page * collection.limit_value).limit(1).count
|
|
106
106
|
options[:total_pages] = collection.current_page + offset
|
|
107
107
|
options[:right] = 0
|
|
108
108
|
end
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
require 'active_admin/helpers/output_safety_helper'
|
|
2
|
-
|
|
3
1
|
module ActiveAdmin
|
|
4
2
|
module Views
|
|
5
3
|
|
|
6
4
|
class SidebarSection < Panel
|
|
7
5
|
builder_method :sidebar_section
|
|
8
|
-
include OutputSafetyHelper
|
|
9
6
|
|
|
10
7
|
# Takes a ActiveAdmin::SidebarSection instance
|
|
11
8
|
def build(section)
|
|
@@ -28,11 +28,7 @@ module ActiveAdmin
|
|
|
28
28
|
# status_tag('active', class: 'important', id: 'status_123', label: 'on')
|
|
29
29
|
# # => <span class='status_tag active important' id='status_123'>on</span>
|
|
30
30
|
#
|
|
31
|
-
def build(
|
|
32
|
-
options = args.extract_options!
|
|
33
|
-
status = args[0]
|
|
34
|
-
type = args[1]
|
|
35
|
-
|
|
31
|
+
def build(status, options = {})
|
|
36
32
|
label = options.delete(:label)
|
|
37
33
|
classes = options.delete(:class)
|
|
38
34
|
status = convert_to_boolean_status(status)
|
|
@@ -46,19 +42,6 @@ module ActiveAdmin
|
|
|
46
42
|
super(content, options)
|
|
47
43
|
|
|
48
44
|
add_class(status_to_class(status)) if status
|
|
49
|
-
|
|
50
|
-
if type
|
|
51
|
-
Deprecation.warn <<-MSG.strip_heredoc
|
|
52
|
-
The `type` parameter has been deprecated. Provide the "#{type}" type as
|
|
53
|
-
a class instead. For example, `status_tag(status, :#{type}, class: "abc")`
|
|
54
|
-
would change to `status_tag(status, class: "#{type} abc")`. Also note that
|
|
55
|
-
the "#{type}" CSS rule will be removed too, so you'll have to provide
|
|
56
|
-
the styles yourself. See https://github.com/activeadmin/activeadmin/blob/master/CHANGELOG.md#110-
|
|
57
|
-
for more information.
|
|
58
|
-
MSG
|
|
59
|
-
add_class(type.to_s)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
45
|
add_class(classes) if classes
|
|
63
46
|
end
|
|
64
47
|
|
|
@@ -22,7 +22,7 @@ module ActiveAdmin
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def columns(*attrs)
|
|
25
|
-
attrs.each {|attr| column(attr) }
|
|
25
|
+
attrs.each { |attr| column(attr) }
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def column(*args, &block)
|
|
@@ -147,7 +147,7 @@ module ActiveAdmin
|
|
|
147
147
|
if @options.has_key?(:class)
|
|
148
148
|
html_classes << @options.delete(:class)
|
|
149
149
|
elsif @title.present?
|
|
150
|
-
html_classes << "col-#{
|
|
150
|
+
html_classes << "col-#{@title.to_s.parameterize(separator: "_")}"
|
|
151
151
|
end
|
|
152
152
|
@html_class = html_classes.join(' ')
|
|
153
153
|
@data = args[1] || args[0]
|
|
@@ -15,7 +15,8 @@ module ActiveAdmin
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def build_menu_item(title, options, &block)
|
|
18
|
-
fragment = options.fetch(:id, title
|
|
18
|
+
fragment = options.fetch(:id, fragmentize(title))
|
|
19
|
+
|
|
19
20
|
html_options = options.fetch(:html_options, {})
|
|
20
21
|
li html_options do
|
|
21
22
|
link_to title, "##{fragment}"
|
|
@@ -23,9 +24,17 @@ module ActiveAdmin
|
|
|
23
24
|
end
|
|
24
25
|
|
|
25
26
|
def build_content_item(title, options, &block)
|
|
26
|
-
options = options.reverse_merge(id: title
|
|
27
|
+
options = options.reverse_merge(id: fragmentize(title))
|
|
27
28
|
div(options, &block)
|
|
28
29
|
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def fragmentize(string)
|
|
34
|
+
result = string.parameterize
|
|
35
|
+
result = URI.encode(string) if result.blank?
|
|
36
|
+
result
|
|
37
|
+
end
|
|
29
38
|
end
|
|
30
39
|
end
|
|
31
40
|
end
|
|
@@ -21,7 +21,7 @@ module ActiveAdmin
|
|
|
21
21
|
|
|
22
22
|
def powered_by_message
|
|
23
23
|
I18n.t('active_admin.powered_by',
|
|
24
|
-
active_admin: link_to("Active Admin", "
|
|
24
|
+
active_admin: link_to("Active Admin", "https://activeadmin.info"),
|
|
25
25
|
version: ActiveAdmin::VERSION).html_safe
|
|
26
26
|
end
|
|
27
27
|
|
|
@@ -365,15 +365,16 @@ module ActiveAdmin
|
|
|
365
365
|
private
|
|
366
366
|
|
|
367
367
|
def defaults(resource, options = {})
|
|
368
|
+
localizer = ActiveAdmin::Localizers.resource(active_admin_config)
|
|
368
369
|
if controller.action_methods.include?('show') && authorized?(ActiveAdmin::Auth::READ, resource)
|
|
369
|
-
item
|
|
370
|
+
item localizer.t(:view), resource_path(resource), class: "view_link #{options[:css_class]}", title: localizer.t(:view)
|
|
370
371
|
end
|
|
371
372
|
if controller.action_methods.include?('edit') && authorized?(ActiveAdmin::Auth::UPDATE, resource)
|
|
372
|
-
item
|
|
373
|
+
item localizer.t(:edit), edit_resource_path(resource), class: "edit_link #{options[:css_class]}", title: localizer.t(:edit)
|
|
373
374
|
end
|
|
374
375
|
if controller.action_methods.include?('destroy') && authorized?(ActiveAdmin::Auth::DESTROY, resource)
|
|
375
|
-
item
|
|
376
|
-
method: :delete, data: {confirm:
|
|
376
|
+
item localizer.t(:delete), resource_path(resource), class: "delete_link #{options[:css_class]}", title: localizer.t(:delete),
|
|
377
|
+
method: :delete, data: { confirm: localizer.t(:delete_confirmation) }
|
|
377
378
|
end
|
|
378
379
|
end
|
|
379
380
|
|
|
@@ -4,6 +4,7 @@ module ActiveAdmin
|
|
|
4
4
|
class Base < Arbre::HTML::Document
|
|
5
5
|
|
|
6
6
|
def build(*args)
|
|
7
|
+
set_attribute :lang, I18n.locale
|
|
7
8
|
build_active_admin_head
|
|
8
9
|
build_page
|
|
9
10
|
end
|
|
@@ -25,6 +26,8 @@ module ActiveAdmin
|
|
|
25
26
|
within head do
|
|
26
27
|
html_title [title, helpers.active_admin_namespace.site_title(self)].compact.join(" | ")
|
|
27
28
|
|
|
29
|
+
text_node(active_admin_namespace.head)
|
|
30
|
+
|
|
28
31
|
active_admin_application.stylesheets.each do |style, options|
|
|
29
32
|
text_node stylesheet_link_tag(style, options).html_safe
|
|
30
33
|
end
|
data/lib/active_admin/views.rb
CHANGED