activeadmin 2.0.0 → 2.4.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 +97 -6
- data/CONTRIBUTING.md +3 -5
- data/README.md +8 -1
- data/app/assets/javascripts/active_admin/lib/batch_actions.es6 +5 -1
- 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/config/locales/ar.yml +3 -2
- data/config/locales/bg.yml +1 -0
- data/config/locales/bs.yml +1 -0
- data/config/locales/ca.yml +1 -1
- data/config/locales/cs.yml +1 -0
- data/config/locales/da.yml +1 -0
- data/config/locales/de-CH.yml +1 -0
- data/config/locales/de.yml +19 -0
- data/config/locales/el.yml +1 -0
- data/config/locales/en-CA.yml +1 -0
- data/config/locales/en-GB.yml +1 -0
- data/config/locales/en.yml +1 -0
- data/config/locales/eo.yml +1 -0
- data/config/locales/es-MX.yml +1 -0
- data/config/locales/es.yml +1 -0
- data/config/locales/fa.yml +1 -0
- data/config/locales/fi.yml +1 -0
- data/config/locales/fr.yml +2 -1
- data/config/locales/he.yml +1 -0
- data/config/locales/hr.yml +1 -0
- data/config/locales/hu.yml +1 -0
- data/config/locales/id.yml +1 -0
- data/config/locales/it.yml +1 -0
- data/config/locales/ja.yml +1 -0
- data/config/locales/ko.yml +1 -0
- data/config/locales/lt.yml +1 -0
- data/config/locales/lv.yml +1 -0
- data/config/locales/mk.yml +134 -0
- data/config/locales/nb.yml +1 -0
- data/config/locales/nl.yml +1 -0
- data/config/locales/pl.yml +1 -0
- data/config/locales/pt-BR.yml +1 -0
- data/config/locales/pt-PT.yml +1 -0
- data/config/locales/ro.yml +1 -0
- data/config/locales/ru.yml +1 -0
- data/config/locales/sk.yml +60 -0
- data/config/locales/sv-SE.yml +1 -0
- data/config/locales/tr.yml +1 -0
- data/config/locales/uk.yml +1 -0
- data/config/locales/vi.yml +1 -0
- data/config/locales/zh-CN.yml +1 -0
- data/config/locales/zh-TW.yml +1 -0
- data/docs/12-arbre-components.md +13 -0
- data/docs/13-authorization-adapter.md +2 -2
- data/docs/2-resource-customization.md +1 -1
- data/docs/3-index-pages/index-as-table.md +7 -0
- data/docs/Gemfile +0 -1
- data/docs/Gemfile.lock +4 -5
- data/docs/_config.yml +2 -0
- data/docs/_includes/top-menu.html +2 -2
- data/docs/index.html +108 -7
- data/docs/stylesheets/main.css +29 -0
- data/lib/active_admin.rb +1 -0
- data/lib/active_admin/application.rb +3 -4
- data/lib/active_admin/base_controller/authorization.rb +1 -0
- data/lib/active_admin/batch_actions/resource_extension.rb +5 -1
- data/lib/active_admin/controller_action.rb +2 -1
- data/lib/active_admin/csv_builder.rb +3 -2
- data/lib/active_admin/dependency.rb +0 -4
- data/lib/active_admin/error.rb +3 -1
- data/lib/active_admin/filters/active_filter.rb +2 -3
- data/lib/active_admin/filters/resource_extension.rb +24 -0
- data/lib/active_admin/generators/boilerplate.rb +12 -4
- data/lib/active_admin/namespace_settings.rb +13 -0
- data/lib/active_admin/order_clause.rb +1 -1
- data/lib/active_admin/page_presenter.rb +2 -1
- data/lib/active_admin/pundit_adapter.rb +7 -3
- data/lib/active_admin/resource.rb +15 -1
- data/lib/active_admin/resource/belongs_to.rb +6 -1
- data/lib/active_admin/resource/model.rb +15 -0
- data/lib/active_admin/resource/routes.rb +11 -3
- data/lib/active_admin/resource_controller.rb +2 -0
- data/lib/active_admin/resource_controller/decorators.rb +2 -2
- data/lib/active_admin/resource_controller/polymorphic_routes.rb +36 -0
- data/lib/active_admin/resource_dsl.rb +1 -1
- data/lib/active_admin/router.rb +2 -1
- data/lib/active_admin/scope.rb +7 -3
- data/lib/active_admin/sidebar_section.rb +3 -1
- data/lib/active_admin/version.rb +1 -1
- data/lib/active_admin/view_helpers/breadcrumb_helper.rb +2 -2
- data/lib/active_admin/view_helpers/display_helper.rb +3 -2
- data/lib/active_admin/views/components/paginated_collection.rb +2 -2
- data/lib/active_admin/views/components/status_tag.rb +5 -1
- data/lib/active_admin/views/index_as_table.rb +7 -0
- data/lib/generators/active_admin/install/templates/active_admin.rb.erb +18 -2
- data/lib/generators/active_admin/resource/templates/admin.rb.erb +40 -37
- data/lib/ransack_ext.rb +2 -2
- metadata +17 -9
- data/lib/active_admin/reloader.rb +0 -25
|
@@ -112,7 +112,11 @@ module ActiveAdmin
|
|
|
112
112
|
# => You can pass a hash of options to `:form` that will be rendered as form input fields for the user to fill out.
|
|
113
113
|
#
|
|
114
114
|
def initialize(sym, title, options = {}, &block)
|
|
115
|
-
@sym
|
|
115
|
+
@sym = sym
|
|
116
|
+
@title = title
|
|
117
|
+
@options = options
|
|
118
|
+
@block = block
|
|
119
|
+
@confirm = options[:confirm]
|
|
116
120
|
@block ||= proc {}
|
|
117
121
|
end
|
|
118
122
|
|
|
@@ -32,7 +32,9 @@ module ActiveAdmin
|
|
|
32
32
|
|
|
33
33
|
def initialize(options = {}, &block)
|
|
34
34
|
@resource = options.delete(:resource)
|
|
35
|
-
@columns
|
|
35
|
+
@columns = []
|
|
36
|
+
@options = ActiveAdmin.application.csv_options.merge options
|
|
37
|
+
@block = block
|
|
36
38
|
end
|
|
37
39
|
|
|
38
40
|
def column(name, options = {}, &block)
|
|
@@ -42,7 +44,6 @@ module ActiveAdmin
|
|
|
42
44
|
def build(controller, csv)
|
|
43
45
|
@collection = controller.send :find_collection, except: :pagination
|
|
44
46
|
columns = exec_columns controller.view_context
|
|
45
|
-
options = ActiveAdmin.application.csv_options.merge self.options
|
|
46
47
|
bom = options.delete :byte_order_mark
|
|
47
48
|
column_names = options.delete(:column_names) { true }
|
|
48
49
|
csv_options = options.except :encoding_options, :humanize_name
|
data/lib/active_admin/error.rb
CHANGED
|
@@ -26,8 +26,7 @@ module ActiveAdmin
|
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def label
|
|
29
|
-
|
|
30
|
-
translated_predicate = predicate_name.mb_chars.downcase.to_s
|
|
29
|
+
translated_predicate = predicate_name.downcase
|
|
31
30
|
if filter_label && filter_label.is_a?(Proc)
|
|
32
31
|
"#{filter_label.call} #{translated_predicate}"
|
|
33
32
|
elsif filter_label
|
|
@@ -67,7 +66,7 @@ module ActiveAdmin
|
|
|
67
66
|
def filter_label
|
|
68
67
|
return unless filter
|
|
69
68
|
|
|
70
|
-
filter[:label]
|
|
69
|
+
filter[:label] || I18n.t(name, scope: ['formtastic', 'labels'], default: nil)
|
|
71
70
|
end
|
|
72
71
|
|
|
73
72
|
#@return Ransack::Nodes::Attribute
|
|
@@ -129,12 +129,36 @@ module ActiveAdmin
|
|
|
129
129
|
not_poly.reject! { |r| r.chain.length > 2 }
|
|
130
130
|
|
|
131
131
|
filters = poly.map(&:foreign_type) + not_poly.map(&:name)
|
|
132
|
+
|
|
133
|
+
# Check high-arity associations for filterable columns
|
|
134
|
+
max = namespace.maximum_association_filter_arity
|
|
135
|
+
if max != :unlimited
|
|
136
|
+
high_arity, low_arity = not_poly.partition do |r|
|
|
137
|
+
r.klass.reorder(nil).limit(max + 1).count > max
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
# Remove high-arity associations with no searchable column
|
|
141
|
+
high_arity = high_arity.select(&method(:searchable_column_for))
|
|
142
|
+
|
|
143
|
+
high_arity = high_arity.map { |r| r.name.to_s + "_" + searchable_column_for(r) + namespace.filter_method_for_large_association }
|
|
144
|
+
|
|
145
|
+
filters = poly.map(&:foreign_type) + low_arity.map(&:name) + high_arity
|
|
146
|
+
end
|
|
147
|
+
|
|
132
148
|
filters.map &:to_sym
|
|
133
149
|
else
|
|
134
150
|
[]
|
|
135
151
|
end
|
|
136
152
|
end
|
|
137
153
|
|
|
154
|
+
def search_columns
|
|
155
|
+
@search_columns ||= namespace.filter_columns_for_large_association.map(&:to_s)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def searchable_column_for(relation)
|
|
159
|
+
relation.klass.column_names.find { |name| search_columns.include?(name) }
|
|
160
|
+
end
|
|
161
|
+
|
|
138
162
|
def add_filters_sidebar_section
|
|
139
163
|
self.sidebar_sections << filters_sidebar_section
|
|
140
164
|
end
|
|
@@ -9,8 +9,16 @@ module ActiveAdmin
|
|
|
9
9
|
@class_name.constantize.new.attributes.keys
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
+
def assignable_attributes
|
|
13
|
+
attributes - %w(id created_at updated_at)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def permit_params
|
|
17
|
+
assignable_attributes.map { |a| a.to_sym.inspect }.join(', ')
|
|
18
|
+
end
|
|
19
|
+
|
|
12
20
|
def rows
|
|
13
|
-
attributes.map { |a| row(a) }.join("\n")
|
|
21
|
+
attributes.map { |a| row(a) }.join("\n ")
|
|
14
22
|
end
|
|
15
23
|
|
|
16
24
|
def row(name)
|
|
@@ -18,7 +26,7 @@ module ActiveAdmin
|
|
|
18
26
|
end
|
|
19
27
|
|
|
20
28
|
def columns
|
|
21
|
-
attributes.map { |a| column(a) }.join("\n")
|
|
29
|
+
attributes.map { |a| column(a) }.join("\n ")
|
|
22
30
|
end
|
|
23
31
|
|
|
24
32
|
def column(name)
|
|
@@ -26,7 +34,7 @@ module ActiveAdmin
|
|
|
26
34
|
end
|
|
27
35
|
|
|
28
36
|
def filters
|
|
29
|
-
attributes.map { |a| filter(a) }.join("\n")
|
|
37
|
+
attributes.map { |a| filter(a) }.join("\n ")
|
|
30
38
|
end
|
|
31
39
|
|
|
32
40
|
def filter(name)
|
|
@@ -34,7 +42,7 @@ module ActiveAdmin
|
|
|
34
42
|
end
|
|
35
43
|
|
|
36
44
|
def form_inputs
|
|
37
|
-
|
|
45
|
+
assignable_attributes.map { |a| form_input(a) }.join("\n ")
|
|
38
46
|
end
|
|
39
47
|
|
|
40
48
|
def form_input(name)
|
|
@@ -106,5 +106,18 @@ module ActiveAdmin
|
|
|
106
106
|
|
|
107
107
|
# Include association filters by default
|
|
108
108
|
register :include_default_association_filters, true
|
|
109
|
+
|
|
110
|
+
register :maximum_association_filter_arity, :unlimited
|
|
111
|
+
|
|
112
|
+
register :filter_columns_for_large_association, [
|
|
113
|
+
:display_name,
|
|
114
|
+
:full_name,
|
|
115
|
+
:name,
|
|
116
|
+
:username,
|
|
117
|
+
:login,
|
|
118
|
+
:title,
|
|
119
|
+
:email,
|
|
120
|
+
]
|
|
121
|
+
register :filter_method_for_large_association, '_starts_with'
|
|
109
122
|
end
|
|
110
123
|
end
|
|
@@ -44,7 +44,7 @@ module ActiveAdmin
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
def format_action(action, subject)
|
|
47
|
-
# https://github.com/
|
|
47
|
+
# https://github.com/varvet/pundit/blob/master/lib/generators/pundit/install/templates/application_policy.rb
|
|
48
48
|
case action
|
|
49
49
|
when Auth::CREATE then :create?
|
|
50
50
|
when Auth::UPDATE then :update?
|
|
@@ -57,8 +57,8 @@ module ActiveAdmin
|
|
|
57
57
|
private
|
|
58
58
|
|
|
59
59
|
def namespace(object)
|
|
60
|
-
if
|
|
61
|
-
[
|
|
60
|
+
if default_policy_namespace && !object.class.to_s.include?(default_policy_namespace.to_s.camelize)
|
|
61
|
+
[default_policy_namespace.to_sym, object]
|
|
62
62
|
else
|
|
63
63
|
object
|
|
64
64
|
end
|
|
@@ -72,6 +72,10 @@ module ActiveAdmin
|
|
|
72
72
|
default_policy_class.new(user, subject)
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
+
def default_policy_namespace
|
|
76
|
+
ActiveAdmin.application.pundit_policy_namespace
|
|
77
|
+
end
|
|
78
|
+
|
|
75
79
|
end
|
|
76
80
|
|
|
77
81
|
end
|
|
@@ -12,6 +12,7 @@ require 'active_admin/resource/scope_to'
|
|
|
12
12
|
require 'active_admin/resource/sidebars'
|
|
13
13
|
require 'active_admin/resource/belongs_to'
|
|
14
14
|
require 'active_admin/resource/ordering'
|
|
15
|
+
require 'active_admin/resource/model'
|
|
15
16
|
|
|
16
17
|
module ActiveAdmin
|
|
17
18
|
|
|
@@ -71,7 +72,8 @@ module ActiveAdmin
|
|
|
71
72
|
@resource_class_name = "::#{resource_class.name}"
|
|
72
73
|
@options = options
|
|
73
74
|
@sort_order = options[:sort_order]
|
|
74
|
-
@member_actions
|
|
75
|
+
@member_actions = []
|
|
76
|
+
@collection_actions = []
|
|
75
77
|
end
|
|
76
78
|
end
|
|
77
79
|
|
|
@@ -103,6 +105,10 @@ module ActiveAdmin
|
|
|
103
105
|
ActiveSupport::Dependencies.constantize(decorator_class_name) if decorator_class_name
|
|
104
106
|
end
|
|
105
107
|
|
|
108
|
+
def resource_name_extension
|
|
109
|
+
@resource_name_extension ||= define_resource_name_extension(self)
|
|
110
|
+
end
|
|
111
|
+
|
|
106
112
|
def resource_table_name
|
|
107
113
|
resource_class.quoted_table_name
|
|
108
114
|
end
|
|
@@ -132,6 +138,7 @@ module ActiveAdmin
|
|
|
132
138
|
def belongs_to(target, options = {})
|
|
133
139
|
@belongs_to = Resource::BelongsTo.new(self, target, options)
|
|
134
140
|
self.menu_item_options = false if @belongs_to.required?
|
|
141
|
+
options[:class_name] ||= @belongs_to.resource.resource_class_name if @belongs_to.resource
|
|
135
142
|
controller.send :belongs_to, target, options.dup
|
|
136
143
|
end
|
|
137
144
|
|
|
@@ -202,5 +209,12 @@ module ActiveAdmin
|
|
|
202
209
|
@default_csv_builder ||= CSVBuilder.default_for_resource(self)
|
|
203
210
|
end
|
|
204
211
|
|
|
212
|
+
def define_resource_name_extension(resource)
|
|
213
|
+
Module.new do
|
|
214
|
+
define_method :model_name do
|
|
215
|
+
resource.resource_name
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
end
|
|
205
219
|
end # class Resource
|
|
206
220
|
end # module ActiveAdmin
|
|
@@ -14,8 +14,13 @@ module ActiveAdmin
|
|
|
14
14
|
# The resource which initiated this relationship
|
|
15
15
|
attr_reader :owner
|
|
16
16
|
|
|
17
|
+
# The name of the relation
|
|
18
|
+
attr_reader :target_name
|
|
19
|
+
|
|
17
20
|
def initialize(owner, target_name, options = {})
|
|
18
|
-
@owner
|
|
21
|
+
@owner = owner
|
|
22
|
+
@target_name = target_name
|
|
23
|
+
@options = options
|
|
19
24
|
end
|
|
20
25
|
|
|
21
26
|
# Returns the target resource class or raises an exception if it doesn't exist
|
|
@@ -110,7 +110,7 @@ module ActiveAdmin
|
|
|
110
110
|
# @return params to pass to instance path
|
|
111
111
|
def route_instance_params(instance)
|
|
112
112
|
if nested?
|
|
113
|
-
[instance.public_send(
|
|
113
|
+
[instance.public_send(belongs_to_target_name).to_param, instance.to_param]
|
|
114
114
|
else
|
|
115
115
|
instance.to_param
|
|
116
116
|
end
|
|
@@ -123,11 +123,19 @@ module ActiveAdmin
|
|
|
123
123
|
end
|
|
124
124
|
|
|
125
125
|
def nested?
|
|
126
|
-
resource.belongs_to? &&
|
|
126
|
+
resource.belongs_to? && belongs_to_config.required?
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def belongs_to_target_name
|
|
130
|
+
belongs_to_config.target_name
|
|
127
131
|
end
|
|
128
132
|
|
|
129
133
|
def belongs_to_name
|
|
130
|
-
|
|
134
|
+
belongs_to_config.target.resource_name.singular
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def belongs_to_config
|
|
138
|
+
resource.belongs_to_config
|
|
131
139
|
end
|
|
132
140
|
|
|
133
141
|
def routes
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require 'active_admin/resource_controller/action_builder'
|
|
2
2
|
require 'active_admin/resource_controller/data_access'
|
|
3
3
|
require 'active_admin/resource_controller/decorators'
|
|
4
|
+
require 'active_admin/resource_controller/polymorphic_routes'
|
|
4
5
|
require 'active_admin/resource_controller/scoping'
|
|
5
6
|
require 'active_admin/resource_controller/streaming'
|
|
6
7
|
require 'active_admin/resource_controller/sidebars'
|
|
@@ -18,6 +19,7 @@ module ActiveAdmin
|
|
|
18
19
|
include ActionBuilder
|
|
19
20
|
include Decorators
|
|
20
21
|
include DataAccess
|
|
22
|
+
include PolymorphicRoutes
|
|
21
23
|
include Scoping
|
|
22
24
|
include Streaming
|
|
23
25
|
include Sidebars
|
|
@@ -67,8 +67,8 @@ module ActiveAdmin
|
|
|
67
67
|
def self.wrap!(parent, name)
|
|
68
68
|
::Class.new parent do
|
|
69
69
|
delegate :reorder, :page, :current_page, :total_pages, :limit_value,
|
|
70
|
-
:total_count, :total_pages, :
|
|
71
|
-
:find_each, :ransack
|
|
70
|
+
:total_count, :total_pages, :offset, :to_key, :group_values,
|
|
71
|
+
:except, :find_each, :ransack
|
|
72
72
|
|
|
73
73
|
define_singleton_method(:name) { name }
|
|
74
74
|
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require "active_admin/resource"
|
|
2
|
+
require "active_admin/resource/model"
|
|
3
|
+
|
|
4
|
+
module ActiveAdmin
|
|
5
|
+
class ResourceController < BaseController
|
|
6
|
+
module PolymorphicRoutes
|
|
7
|
+
def polymorphic_url(record_or_hash_or_array, options = {})
|
|
8
|
+
super(map_named_resources_for(record_or_hash_or_array), options)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def polymorphic_path(record_or_hash_or_array, options = {})
|
|
12
|
+
super(map_named_resources_for(record_or_hash_or_array), options)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def map_named_resources_for(record_or_hash_or_array)
|
|
18
|
+
return record_or_hash_or_array unless record_or_hash_or_array.is_a?(Array)
|
|
19
|
+
|
|
20
|
+
record_or_hash_or_array.map { |record| to_named_resource(record) }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def to_named_resource(record)
|
|
24
|
+
if record.is_a?(resource_class)
|
|
25
|
+
return ActiveAdmin::Model.new(active_admin_config, record)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
if record.is_a?(parent.class)
|
|
29
|
+
return ActiveAdmin::Model.new(active_admin_config.belongs_to_config.resource, record)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
record
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -133,7 +133,7 @@ module ActiveAdmin
|
|
|
133
133
|
# action.
|
|
134
134
|
#
|
|
135
135
|
def action(set, name, options = {}, &block)
|
|
136
|
-
warn "Warning: method `#{name}` already defined" if controller.method_defined?(name)
|
|
136
|
+
warn "Warning: method `#{name}` already defined in #{controller.name}" if controller.method_defined?(name)
|
|
137
137
|
|
|
138
138
|
set << ControllerAction.new(name, options)
|
|
139
139
|
title = options.delete(:title)
|