activeadmin 2.5.0 → 2.8.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 +120 -6
- data/CONTRIBUTING.md +11 -57
- data/README.md +2 -2
- data/app/assets/javascripts/active_admin/base.js +26 -18
- data/app/assets/stylesheets/active_admin/_header.scss +37 -3
- data/app/assets/stylesheets/active_admin/components/_comments.scss +2 -2
- data/app/assets/stylesheets/active_admin/mixins/_variables.scss +3 -0
- data/app/javascript/active_admin/base.js +9 -0
- 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/layouts/active_admin_logged_out.html.erb +15 -5
- data/config/locales/ar.yml +6 -6
- 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/lv.yml +2 -2
- data/config/locales/vi.yml +6 -5
- data/docs/0-installation.md +26 -2
- data/docs/11-decorators.md +16 -5
- data/docs/2-resource-customization.md +10 -1
- data/docs/3-index-pages.md +1 -1
- data/docs/9-batch-actions.md +2 -2
- data/docs/Gemfile +2 -2
- data/docs/Gemfile.lock +93 -84
- data/docs/_includes/top-menu.html +1 -1
- data/docs/documentation.md +1 -1
- data/docs/index.html +6 -6
- data/lib/active_admin.rb +60 -60
- data/lib/active_admin/application.rb +13 -13
- data/lib/active_admin/application_settings.rb +3 -3
- data/lib/active_admin/authorization_adapter.rb +3 -3
- data/lib/active_admin/base_controller.rb +4 -4
- data/lib/active_admin/base_controller/authorization.rb +13 -12
- data/lib/active_admin/batch_actions/controller.rb +3 -3
- data/lib/active_admin/batch_actions/resource_extension.rb +9 -8
- data/lib/active_admin/batch_actions/views/batch_action_form.rb +3 -3
- data/lib/active_admin/batch_actions/views/batch_action_selector.rb +6 -6
- data/lib/active_admin/batch_actions/views/selection_cells.rb +3 -3
- data/lib/active_admin/cancan_adapter.rb +1 -1
- data/lib/active_admin/collection_decorator.rb +31 -0
- data/lib/active_admin/csv_builder.rb +11 -7
- data/lib/active_admin/dependency.rb +11 -11
- data/lib/active_admin/devise.rb +5 -5
- data/lib/active_admin/dsl.rb +1 -1
- data/lib/active_admin/dynamic_settings_node.rb +2 -2
- data/lib/active_admin/engine.rb +3 -3
- data/lib/active_admin/filters.rb +7 -7
- data/lib/active_admin/filters/active.rb +1 -1
- data/lib/active_admin/filters/active_filter.rb +5 -4
- data/lib/active_admin/filters/active_sidebar.rb +5 -5
- data/lib/active_admin/filters/forms.rb +6 -6
- data/lib/active_admin/filters/formtastic_addons.rb +1 -6
- data/lib/active_admin/filters/resource_extension.rb +1 -1
- data/lib/active_admin/form_builder.rb +21 -19
- data/lib/active_admin/generators/boilerplate.rb +1 -1
- data/lib/active_admin/helpers/optional_display.rb +2 -2
- data/lib/active_admin/inputs/datepicker_input.rb +1 -1
- data/lib/active_admin/inputs/filters/base.rb +1 -1
- data/lib/active_admin/inputs/filters/base/search_method_select.rb +4 -4
- data/lib/active_admin/inputs/filters/boolean_input.rb +1 -1
- data/lib/active_admin/inputs/filters/check_boxes_input.rb +1 -1
- data/lib/active_admin/inputs/filters/date_range_input.rb +12 -9
- data/lib/active_admin/inputs/filters/select_input.rb +2 -2
- data/lib/active_admin/localizers.rb +1 -1
- data/lib/active_admin/localizers/resource_localizer.rb +3 -3
- data/lib/active_admin/menu.rb +6 -3
- data/lib/active_admin/menu_item.rb +7 -7
- data/lib/active_admin/namespace.rb +12 -12
- data/lib/active_admin/namespace_settings.rb +8 -5
- data/lib/active_admin/order_clause.rb +1 -1
- data/lib/active_admin/orm/active_record.rb +1 -1
- data/lib/active_admin/orm/active_record/comments.rb +19 -19
- data/lib/active_admin/orm/active_record/comments/comment.rb +3 -3
- data/lib/active_admin/orm/active_record/comments/views.rb +2 -2
- data/lib/active_admin/orm/active_record/comments/views/active_admin_comments.rb +19 -19
- data/lib/active_admin/page.rb +1 -1
- data/lib/active_admin/pundit_adapter.rb +5 -5
- data/lib/active_admin/resource.rb +17 -17
- data/lib/active_admin/resource/action_items.rb +5 -5
- data/lib/active_admin/resource/attributes.rb +1 -1
- data/lib/active_admin/resource/belongs_to.rb +2 -2
- data/lib/active_admin/resource/controllers.rb +1 -1
- data/lib/active_admin/resource/menu.rb +4 -4
- data/lib/active_admin/resource/naming.rb +5 -5
- data/lib/active_admin/resource/routes.rb +5 -5
- data/lib/active_admin/resource/scope_to.rb +7 -7
- data/lib/active_admin/resource/sidebars.rb +1 -1
- data/lib/active_admin/resource_controller.rb +12 -11
- data/lib/active_admin/resource_controller/data_access.rb +1 -1
- data/lib/active_admin/resource_controller/decorators.rb +6 -26
- data/lib/active_admin/resource_controller/streaming.rb +7 -6
- data/lib/active_admin/resource_dsl.rb +5 -5
- data/lib/active_admin/scope.rb +6 -6
- data/lib/active_admin/version.rb +1 -1
- data/lib/active_admin/view_factory.rb +17 -17
- data/lib/active_admin/view_helpers.rb +1 -1
- data/lib/active_admin/view_helpers/breadcrumb_helper.rb +3 -3
- data/lib/active_admin/view_helpers/display_helper.rb +5 -5
- data/lib/active_admin/view_helpers/download_format_links_helper.rb +1 -1
- data/lib/active_admin/view_helpers/fields_for.rb +2 -2
- data/lib/active_admin/views.rb +1 -1
- data/lib/active_admin/views/components/active_admin_form.rb +5 -5
- data/lib/active_admin/views/components/attributes_table.rb +5 -5
- data/lib/active_admin/views/components/blank_slate.rb +1 -1
- data/lib/active_admin/views/components/dropdown_menu.rb +8 -8
- data/lib/active_admin/views/components/index_list.rb +3 -3
- data/lib/active_admin/views/components/menu.rb +1 -1
- data/lib/active_admin/views/components/menu_item.rb +4 -4
- data/lib/active_admin/views/components/paginated_collection.rb +18 -18
- data/lib/active_admin/views/components/panel.rb +1 -1
- data/lib/active_admin/views/components/scopes.rb +7 -5
- data/lib/active_admin/views/components/site_title.rb +1 -1
- data/lib/active_admin/views/components/status_tag.rb +11 -11
- data/lib/active_admin/views/components/table_for.rb +17 -17
- data/lib/active_admin/views/components/tabs.rb +3 -3
- data/lib/active_admin/views/footer.rb +2 -1
- data/lib/active_admin/views/header.rb +2 -2
- data/lib/active_admin/views/index_as_blog.rb +1 -1
- data/lib/active_admin/views/index_as_grid.rb +1 -1
- data/lib/active_admin/views/index_as_table.rb +16 -16
- data/lib/active_admin/views/pages/base.rb +14 -10
- data/lib/active_admin/views/pages/index.rb +14 -13
- data/lib/active_admin/views/tabbed_navigation.rb +2 -2
- data/lib/active_admin/views/title_bar.rb +1 -1
- data/lib/activeadmin.rb +1 -1
- data/lib/generators/active_admin/assets/assets_generator.rb +2 -2
- data/lib/generators/active_admin/assets/templates/active_admin.scss +2 -2
- data/lib/generators/active_admin/devise/devise_generator.rb +5 -5
- data/lib/generators/active_admin/install/install_generator.rb +14 -8
- data/lib/generators/active_admin/install/templates/active_admin.rb.erb +9 -2
- data/lib/generators/active_admin/page/page_generator.rb +1 -1
- data/lib/generators/active_admin/resource/resource_generator.rb +3 -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 +26 -0
- data/lib/ransack_ext.rb +8 -8
- metadata +20 -8
@@ -15,7 +15,7 @@ module ActiveAdmin
|
|
15
15
|
|
16
16
|
module OptionalDisplay
|
17
17
|
def display_on?(action, render_context = self)
|
18
|
-
return false if @options[:only]
|
18
|
+
return false if @options[:only] && !@options[:only].include?(action.to_sym)
|
19
19
|
return false if @options[:except] && @options[:except].include?(action.to_sym)
|
20
20
|
|
21
21
|
case condition = @options[:if]
|
@@ -31,7 +31,7 @@ module ActiveAdmin
|
|
31
31
|
private
|
32
32
|
|
33
33
|
def normalize_display_options!
|
34
|
-
@options[:only]
|
34
|
+
@options[:only] = Array(@options[:only]) if @options[:only]
|
35
35
|
@options[:except] = Array(@options[:except]) if @options[:except]
|
36
36
|
end
|
37
37
|
end
|
@@ -3,7 +3,7 @@ module ActiveAdmin
|
|
3
3
|
class DatepickerInput < ::Formtastic::Inputs::StringInput
|
4
4
|
def input_html_options
|
5
5
|
super.tap do |options|
|
6
|
-
options[:class] = [options[:class], "datepicker"].compact.join(
|
6
|
+
options[:class] = [options[:class], "datepicker"].compact.join(" ")
|
7
7
|
options[:data] ||= {}
|
8
8
|
options[:data].merge! datepicker_options
|
9
9
|
end
|
@@ -31,15 +31,15 @@ module ActiveAdmin
|
|
31
31
|
|
32
32
|
def wrapper_html_options
|
33
33
|
opts = super
|
34
|
-
(opts[:class] ||=
|
34
|
+
(opts[:class] ||= "") << " select_and_search" unless seems_searchable?
|
35
35
|
opts
|
36
36
|
end
|
37
37
|
|
38
38
|
def to_html
|
39
39
|
input_wrapping do
|
40
|
-
label_html
|
40
|
+
label_html << # your label
|
41
41
|
select_html << # the dropdown that holds the available search methods
|
42
|
-
input_html
|
42
|
+
input_html # your input field
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -48,7 +48,7 @@ module ActiveAdmin
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def select_html
|
51
|
-
template.select_tag
|
51
|
+
template.select_tag "", template.options_for_select(filter_options, current_filter)
|
52
52
|
end
|
53
53
|
|
54
54
|
def filters
|
@@ -22,17 +22,20 @@ module ActiveAdmin
|
|
22
22
|
column && column.type == :date ? "#{method}_lteq" : "#{method}_lteq_datetime"
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
26
|
-
current_value = begin
|
27
|
-
#cast value to date object before rendering input
|
28
|
-
@object.public_send(input_name).to_s.to_date
|
29
|
-
rescue
|
30
|
-
nil
|
31
|
-
end
|
25
|
+
def input_html_options
|
32
26
|
{ size: 12,
|
33
27
|
class: "datepicker",
|
34
|
-
maxlength: 10
|
35
|
-
|
28
|
+
maxlength: 10 }.merge(options[:input_html] || {})
|
29
|
+
end
|
30
|
+
|
31
|
+
def input_html_options_for(input_name, placeholder)
|
32
|
+
current_value = begin
|
33
|
+
#cast value to date object before rendering input
|
34
|
+
@object.public_send(input_name).to_s.to_date
|
35
|
+
rescue
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
{ placeholder: placeholder,
|
36
39
|
value: current_value ? current_value.strftime("%Y-%m-%d") : "" }.merge(input_html_options)
|
37
40
|
end
|
38
41
|
|
@@ -7,7 +7,7 @@ module ActiveAdmin
|
|
7
7
|
def input_name
|
8
8
|
return method if seems_searchable?
|
9
9
|
|
10
|
-
searchable_method_name + (multiple? ?
|
10
|
+
searchable_method_name + (multiple? ? "_in" : "_eq")
|
11
11
|
end
|
12
12
|
|
13
13
|
def searchable_method_name
|
@@ -22,7 +22,7 @@ module ActiveAdmin
|
|
22
22
|
|
23
23
|
# Provide the AA translation to the blank input field.
|
24
24
|
def include_blank
|
25
|
-
I18n.t
|
25
|
+
I18n.t "active_admin.any" if super
|
26
26
|
end
|
27
27
|
|
28
28
|
def input_html_options_name
|
@@ -19,16 +19,16 @@ module ActiveAdmin
|
|
19
19
|
|
20
20
|
def translate(key, options = {})
|
21
21
|
scope = options.delete(:scope)
|
22
|
-
specific_key = array_to_key(
|
22
|
+
specific_key = array_to_key("resources", @model_name, scope, key)
|
23
23
|
defaults = [array_to_key(scope, key), key.to_s.titleize]
|
24
|
-
::I18n.t specific_key, options.reverse_merge(model: @model, default: defaults, scope:
|
24
|
+
::I18n.t specific_key, **options.reverse_merge(model: @model, default: defaults, scope: "active_admin")
|
25
25
|
end
|
26
26
|
alias_method :t, :translate
|
27
27
|
|
28
28
|
protected
|
29
29
|
|
30
30
|
def array_to_key(*arr)
|
31
|
-
arr.flatten.compact.join(
|
31
|
+
arr.flatten.compact.join(".").to_sym
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
data/lib/active_admin/menu.rb
CHANGED
@@ -47,7 +47,10 @@ module ActiveAdmin
|
|
47
47
|
# menu.add parent: 'Dashboard', label: 'My Child Dashboard'
|
48
48
|
#
|
49
49
|
def add(options)
|
50
|
-
|
50
|
+
parent_chain = Array.wrap(options.delete(:parent))
|
51
|
+
|
52
|
+
item = if parent = parent_chain.shift
|
53
|
+
options[:parent] = parent_chain if parent_chain.any?
|
51
54
|
(self[parent] || add(label: parent)).add options
|
52
55
|
else
|
53
56
|
_add options.merge parent: self
|
@@ -60,7 +63,7 @@ module ActiveAdmin
|
|
60
63
|
|
61
64
|
# Whether any children match the given item.
|
62
65
|
def include?(item)
|
63
|
-
@children.values.include? item
|
66
|
+
@children.values.include?(item) || @children.values.any? { |child| child.include?(item) }
|
64
67
|
end
|
65
68
|
|
66
69
|
# Used in the UI to visually distinguish which menu item is selected.
|
@@ -87,7 +90,7 @@ module ActiveAdmin
|
|
87
90
|
def normalize_id(id)
|
88
91
|
case id
|
89
92
|
when String, Symbol, ActiveModel::Name
|
90
|
-
id.to_s.downcase.tr
|
93
|
+
id.to_s.downcase.tr " ", "_"
|
91
94
|
when ActiveAdmin::Resource::Name
|
92
95
|
id.param_key
|
93
96
|
else
|
@@ -45,13 +45,13 @@ module ActiveAdmin
|
|
45
45
|
#
|
46
46
|
def initialize(options = {})
|
47
47
|
super() # MenuNode
|
48
|
-
@label
|
49
|
-
@dirty_id
|
50
|
-
@url
|
51
|
-
@priority
|
52
|
-
@html_options
|
53
|
-
@should_display = options[:if]
|
54
|
-
@parent
|
48
|
+
@label = options[:label]
|
49
|
+
@dirty_id = options[:id] || options[:label]
|
50
|
+
@url = options[:url] || "#"
|
51
|
+
@priority = options[:priority] || 10
|
52
|
+
@html_options = options[:html_options] || {}
|
53
|
+
@should_display = options[:if] || proc { true }
|
54
|
+
@parent = options[:parent]
|
55
55
|
|
56
56
|
yield(self) if block_given? # Builder style syntax
|
57
57
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "active_admin/resource_collection"
|
2
2
|
|
3
3
|
module ActiveAdmin
|
4
4
|
|
@@ -31,7 +31,7 @@ module ActiveAdmin
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
RegisterEvent =
|
34
|
+
RegisterEvent = "active_admin.namespace.register".freeze
|
35
35
|
|
36
36
|
attr_reader :application, :resources, :menus
|
37
37
|
|
@@ -149,10 +149,10 @@ module ActiveAdmin
|
|
149
149
|
def add_logout_button_to_menu(menu, priority = 20, html_options = {})
|
150
150
|
if logout_link_path
|
151
151
|
html_options = html_options.reverse_merge(method: logout_link_method || :get)
|
152
|
-
menu.add id:
|
153
|
-
|
154
|
-
|
155
|
-
|
152
|
+
menu.add id: "logout", priority: priority, html_options: html_options,
|
153
|
+
label: -> { I18n.t "active_admin.logout" },
|
154
|
+
url: -> { render_or_call_method_or_proc_on self, active_admin_namespace.logout_link_path },
|
155
|
+
if: :current_active_admin_user?
|
156
156
|
end
|
157
157
|
end
|
158
158
|
|
@@ -164,10 +164,10 @@ module ActiveAdmin
|
|
164
164
|
#
|
165
165
|
def add_current_user_to_menu(menu, priority = 10, html_options = {})
|
166
166
|
if current_user_method
|
167
|
-
menu.add id:
|
168
|
-
|
169
|
-
|
170
|
-
|
167
|
+
menu.add id: "current_user", priority: priority, html_options: html_options,
|
168
|
+
label: -> { display_name current_active_admin_user },
|
169
|
+
url: -> { auto_url_for(current_active_admin_user) },
|
170
|
+
if: :current_active_admin_user?
|
171
171
|
end
|
172
172
|
end
|
173
173
|
|
@@ -211,8 +211,8 @@ module ActiveAdmin
|
|
211
211
|
|
212
212
|
def unload_resources!
|
213
213
|
resources.each do |resource|
|
214
|
-
parent = (module_name ||
|
215
|
-
name
|
214
|
+
parent = (module_name || "Object").constantize
|
215
|
+
name = resource.controller_name.split("::").last
|
216
216
|
parent.send(:remove_const, name) if parent.const_defined?(name, false)
|
217
217
|
|
218
218
|
# Remove circular references
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "active_admin/dynamic_settings_node"
|
2
2
|
|
3
3
|
module ActiveAdmin
|
4
4
|
class NamespaceSettings < DynamicSettingsNode
|
@@ -57,7 +57,7 @@ module ActiveAdmin
|
|
57
57
|
register :filters, true
|
58
58
|
|
59
59
|
# The namespace root
|
60
|
-
register :root_to,
|
60
|
+
register :root_to, "dashboard#index"
|
61
61
|
|
62
62
|
# Options that are passed to root_to
|
63
63
|
register :root_to_options, {}
|
@@ -73,7 +73,7 @@ module ActiveAdmin
|
|
73
73
|
register :create_another, false
|
74
74
|
|
75
75
|
# Default CSV options
|
76
|
-
register :csv_options, { col_sep:
|
76
|
+
register :csv_options, { col_sep: ",", byte_order_mark: "\xEF\xBB\xBF" }
|
77
77
|
|
78
78
|
# Default Download Links options
|
79
79
|
register :download_links, true
|
@@ -102,7 +102,7 @@ module ActiveAdmin
|
|
102
102
|
]
|
103
103
|
|
104
104
|
# Set flash message keys that shouldn't show in ActiveAdmin
|
105
|
-
register :flash_keys_to_except, [
|
105
|
+
register :flash_keys_to_except, ["timedout"]
|
106
106
|
|
107
107
|
# Include association filters by default
|
108
108
|
register :include_default_association_filters, true
|
@@ -118,6 +118,9 @@ module ActiveAdmin
|
|
118
118
|
:title,
|
119
119
|
:email,
|
120
120
|
]
|
121
|
-
register :filter_method_for_large_association,
|
121
|
+
register :filter_method_for_large_association, "_starts_with"
|
122
|
+
|
123
|
+
# Switch between asset pipeline and webpacker assets
|
124
|
+
register :use_webpacker, false
|
122
125
|
end
|
123
126
|
end
|
@@ -1,21 +1,21 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "active_admin/orm/active_record/comments/views"
|
2
|
+
require "active_admin/orm/active_record/comments/show_page_helper"
|
3
|
+
require "active_admin/orm/active_record/comments/namespace_helper"
|
4
|
+
require "active_admin/orm/active_record/comments/resource_helper"
|
5
5
|
|
6
6
|
# Add the comments configuration
|
7
|
-
ActiveAdmin::Application.inheritable_setting :comments,
|
8
|
-
ActiveAdmin::Application.inheritable_setting :comments_registration_name,
|
9
|
-
ActiveAdmin::Application.inheritable_setting :comments_order,
|
10
|
-
ActiveAdmin::Application.inheritable_setting :comments_menu,
|
7
|
+
ActiveAdmin::Application.inheritable_setting :comments, true
|
8
|
+
ActiveAdmin::Application.inheritable_setting :comments_registration_name, "Comment"
|
9
|
+
ActiveAdmin::Application.inheritable_setting :comments_order, "created_at ASC"
|
10
|
+
ActiveAdmin::Application.inheritable_setting :comments_menu, {}
|
11
11
|
|
12
12
|
# Insert helper modules
|
13
13
|
ActiveAdmin::Namespace.send :include, ActiveAdmin::Comments::NamespaceHelper
|
14
|
-
ActiveAdmin::Resource.send
|
14
|
+
ActiveAdmin::Resource.send :include, ActiveAdmin::Comments::ResourceHelper
|
15
15
|
ActiveAdmin.application.view_factory.show_page.send :include, ActiveAdmin::Comments::ShowPageHelper
|
16
16
|
|
17
17
|
# Load the model as soon as it's referenced. By that point, Rails & Kaminari will be ready
|
18
|
-
ActiveAdmin.autoload :Comment,
|
18
|
+
ActiveAdmin.autoload :Comment, "active_admin/orm/active_record/comments/comment"
|
19
19
|
|
20
20
|
# Hint i18n-tasks about model and attribute translations used by default install
|
21
21
|
# i18n-tasks-use t('activerecord.models.comment')
|
@@ -36,7 +36,7 @@ ActiveAdmin.after_load do |app|
|
|
36
36
|
|
37
37
|
menu namespace.comments ? namespace.comments_menu : false
|
38
38
|
|
39
|
-
config.comments
|
39
|
+
config.comments = false # Don't allow comments on comments
|
40
40
|
config.batch_actions = false # The default destroy batch action isn't showing up anyway...
|
41
41
|
|
42
42
|
scope :all, show_count: false
|
@@ -51,7 +51,7 @@ ActiveAdmin.after_load do |app|
|
|
51
51
|
# Store the author and namespace
|
52
52
|
before_save do |comment|
|
53
53
|
comment.namespace = active_admin_config.namespace.name
|
54
|
-
comment.author
|
54
|
+
comment.author = current_active_admin_user
|
55
55
|
end
|
56
56
|
|
57
57
|
controller do
|
@@ -67,7 +67,7 @@ ActiveAdmin.after_load do |app|
|
|
67
67
|
redirect_back fallback_location: active_admin_root
|
68
68
|
end
|
69
69
|
failure.html do
|
70
|
-
flash[:error] = I18n.t
|
70
|
+
flash[:error] = I18n.t "active_admin.comments.errors.empty_text"
|
71
71
|
redirect_back fallback_location: active_admin_root
|
72
72
|
end
|
73
73
|
end
|
@@ -88,12 +88,12 @@ ActiveAdmin.after_load do |app|
|
|
88
88
|
permit_params :body, :namespace, :resource_id, :resource_type
|
89
89
|
|
90
90
|
index do
|
91
|
-
column I18n.t(
|
92
|
-
column I18n.t(
|
93
|
-
column I18n.t(
|
94
|
-
column I18n.t(
|
95
|
-
column I18n.t(
|
96
|
-
column I18n.t(
|
91
|
+
column I18n.t("active_admin.comments.resource_type"), :resource_type
|
92
|
+
column I18n.t("active_admin.comments.author_type"), :author_type
|
93
|
+
column I18n.t("active_admin.comments.resource"), :resource
|
94
|
+
column I18n.t("active_admin.comments.author"), :author
|
95
|
+
column I18n.t("active_admin.comments.body"), :body
|
96
|
+
column I18n.t("active_admin.comments.created_at"), :created_at
|
97
97
|
actions
|
98
98
|
end
|
99
99
|
end
|
@@ -4,7 +4,7 @@ module ActiveAdmin
|
|
4
4
|
self.table_name = "#{table_name_prefix}active_admin_comments#{table_name_suffix}"
|
5
5
|
|
6
6
|
belongs_to :resource, polymorphic: true, optional: true
|
7
|
-
belongs_to :author,
|
7
|
+
belongs_to :author, polymorphic: true
|
8
8
|
|
9
9
|
validates_presence_of :body, :namespace, :resource
|
10
10
|
|
@@ -18,8 +18,8 @@ module ActiveAdmin
|
|
18
18
|
def self.find_for_resource_in_namespace(resource, namespace)
|
19
19
|
where(
|
20
20
|
resource_type: resource_type(resource),
|
21
|
-
resource_id:
|
22
|
-
namespace:
|
21
|
+
resource_id: resource.id,
|
22
|
+
namespace: namespace.to_s
|
23
23
|
).order(ActiveAdmin.application.namespaces[namespace.to_sym].comments_order)
|
24
24
|
end
|
25
25
|
|
@@ -1,2 +1,2 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "active_admin/views"
|
2
|
+
require "active_admin/orm/active_record/comments/views/active_admin_comments"
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "active_admin/views"
|
2
|
+
require "active_admin/views/components/panel"
|
3
3
|
|
4
4
|
module ActiveAdmin
|
5
5
|
module Comments
|
@@ -22,13 +22,13 @@ module ActiveAdmin
|
|
22
22
|
protected
|
23
23
|
|
24
24
|
def title
|
25
|
-
I18n.t
|
25
|
+
I18n.t "active_admin.comments.title_content", count: @comments.total_count
|
26
26
|
end
|
27
27
|
|
28
28
|
def build_comments
|
29
29
|
if @comments.any?
|
30
30
|
@comments.each(&method(:build_comment))
|
31
|
-
div page_entries_info(@comments).html_safe, class:
|
31
|
+
div page_entries_info(@comments).html_safe, class: "pagination_information"
|
32
32
|
else
|
33
33
|
build_empty_message
|
34
34
|
end
|
@@ -42,56 +42,56 @@ module ActiveAdmin
|
|
42
42
|
|
43
43
|
def build_comment(comment)
|
44
44
|
div for: comment do
|
45
|
-
div class:
|
46
|
-
h4 class:
|
47
|
-
comment.author ? auto_link(comment.author) : I18n.t(
|
45
|
+
div class: "active_admin_comment_meta" do
|
46
|
+
h4 class: "active_admin_comment_author" do
|
47
|
+
comment.author ? auto_link(comment.author) : I18n.t("active_admin.comments.author_missing")
|
48
48
|
end
|
49
49
|
span pretty_format comment.created_at
|
50
50
|
if authorized?(ActiveAdmin::Auth::DESTROY, comment)
|
51
|
-
text_node link_to I18n.t(
|
51
|
+
text_node link_to I18n.t("active_admin.comments.delete"), comments_url(comment.id), method: :delete, data: { confirm: I18n.t("active_admin.comments.delete_confirmation") }
|
52
52
|
end
|
53
53
|
end
|
54
|
-
div class:
|
54
|
+
div class: "active_admin_comment_body" do
|
55
55
|
simple_format comment.body
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
60
|
def build_empty_message
|
61
|
-
span I18n.t(
|
61
|
+
span I18n.t("active_admin.comments.no_comments_yet"), class: "empty"
|
62
62
|
end
|
63
63
|
|
64
64
|
def comments_url(*args)
|
65
65
|
parts = []
|
66
66
|
parts << active_admin_namespace.name unless active_admin_namespace.root?
|
67
67
|
parts << active_admin_namespace.comments_registration_name.underscore
|
68
|
-
parts <<
|
69
|
-
send parts.join(
|
68
|
+
parts << "path"
|
69
|
+
send parts.join("_"), *args
|
70
70
|
end
|
71
71
|
|
72
72
|
def comment_form_url
|
73
73
|
parts = []
|
74
74
|
parts << active_admin_namespace.name unless active_admin_namespace.root?
|
75
75
|
parts << active_admin_namespace.comments_registration_name.underscore.pluralize
|
76
|
-
parts <<
|
77
|
-
send parts.join
|
76
|
+
parts << "path"
|
77
|
+
send parts.join "_"
|
78
78
|
end
|
79
79
|
|
80
80
|
def build_comment_form
|
81
81
|
active_admin_form_for(ActiveAdmin::Comment.new, url: comment_form_url) do |f|
|
82
82
|
f.inputs do
|
83
|
-
f.input :resource_type, as: :hidden,
|
84
|
-
f.input :resource_id,
|
85
|
-
f.input :body,
|
83
|
+
f.input :resource_type, as: :hidden, input_html: { value: ActiveAdmin::Comment.resource_type(parent.resource) }
|
84
|
+
f.input :resource_id, as: :hidden, input_html: { value: parent.resource.id }
|
85
|
+
f.input :body, label: false, input_html: { size: "80x8" }
|
86
86
|
end
|
87
87
|
f.actions do
|
88
|
-
f.action :submit, label: I18n.t(
|
88
|
+
f.action :submit, label: I18n.t("active_admin.comments.add")
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
93
|
def default_id_for_prefix
|
94
|
-
|
94
|
+
"active_admin_comments_for"
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|