administrate 0.20.1 → 1.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/Rakefile +9 -9
- data/app/assets/builds/administrate/application.css +2614 -0
- data/app/assets/builds/administrate/application.css.map +1 -0
- data/app/assets/builds/administrate/application.js +31661 -0
- data/app/assets/builds/administrate/application.js.map +7 -0
- data/app/assets/builds/administrate-internal/docs.css +102 -0
- data/app/assets/builds/administrate-internal/docs.css.map +1 -0
- data/app/assets/config/administrate_manifest.js +2 -0
- data/app/assets/javascripts/administrate/add_jquery.js +4 -0
- data/app/assets/javascripts/administrate/application.js +9 -4
- data/app/assets/javascripts/administrate/controllers/application.js +9 -0
- data/app/assets/javascripts/administrate/controllers/index.js +9 -0
- data/app/assets/javascripts/administrate/controllers/select_controller.js +25 -0
- data/app/assets/javascripts/administrate/{components/table.js → controllers/table_controller.js} +9 -9
- data/app/assets/javascripts/administrate/controllers/tooltip_controller.js +24 -0
- data/app/assets/javascripts/administrate/vendor/css-anchor-positioning.js +9310 -0
- data/app/assets/stylesheets/administrate/application.scss +3 -3
- data/app/assets/stylesheets/administrate/base/_forms.scss +4 -4
- data/app/assets/stylesheets/administrate/base/_layout.scss +5 -0
- data/app/assets/stylesheets/administrate/base/_tables.scss +1 -1
- data/app/assets/stylesheets/administrate/base/_typography.scss +15 -1
- data/app/assets/stylesheets/administrate/components/_attributes.scss +1 -0
- data/app/assets/stylesheets/administrate/components/_buttons.scss +37 -12
- data/app/assets/stylesheets/administrate/components/_cells.scss +26 -19
- data/app/assets/stylesheets/administrate/components/_field-unit.scss +3 -3
- data/app/assets/stylesheets/administrate/components/_main-content.scss +1 -1
- data/app/assets/stylesheets/administrate/components/_navigation.scss +3 -3
- data/app/assets/stylesheets/administrate/components/_search.scss +55 -14
- data/app/assets/stylesheets/administrate/library/_variables.scss +7 -3
- data/app/assets/stylesheets/administrate/reset/_normalize.scss +7 -1
- data/app/assets/stylesheets/{docs.scss → administrate-internal/docs.scss} +25 -23
- data/app/controllers/administrate/application_controller.rb +27 -39
- data/app/controllers/concerns/administrate/punditize.rb +4 -12
- data/app/helpers/administrate/application_helper.rb +13 -5
- data/app/views/administrate/application/_collection.html.erb +30 -20
- data/app/views/administrate/application/_collection_header_actions.html.erb +1 -1
- data/app/views/administrate/application/_collection_item_actions.html.erb +4 -4
- data/app/views/administrate/application/_form.html.erb +1 -1
- data/app/views/administrate/application/_icons.html.erb +14 -6
- data/app/views/administrate/application/_index_header.html.erb +23 -0
- data/app/views/administrate/application/_javascript.html.erb +1 -1
- data/app/views/administrate/application/edit.html.erb +15 -3
- data/app/views/administrate/application/index.html.erb +20 -11
- data/app/views/administrate/application/new.html.erb +16 -4
- data/app/views/administrate/application/show.html.erb +35 -23
- data/app/views/fields/belongs_to/_form.html.erb +3 -2
- data/app/views/fields/has_many/_form.html.erb +2 -2
- data/app/views/fields/has_one/_form.html.erb +6 -0
- data/app/views/fields/polymorphic/_form.html.erb +1 -1
- data/app/views/fields/rich_text/_form.html.erb +22 -0
- data/app/views/fields/rich_text/_index.html.erb +18 -0
- data/app/views/fields/rich_text/_show.html.erb +18 -0
- data/app/views/fields/select/_form.html.erb +2 -1
- data/app/views/fields/text/_form.html.erb +1 -1
- data/app/views/layouts/administrate/application.html.erb +1 -2
- data/docs/customizing_dashboards.md +214 -11
- data/docs/customizing_page_views.md +47 -0
- data/docs/guides/scoping_has_many_relations.md +2 -2
- data/docs/guides/switching_templates_with_view_variants.md +45 -0
- data/docs/guides.md +1 -0
- data/docs/migrating-to-v1.md +34 -0
- data/lib/administrate/base_dashboard.rb +6 -11
- data/lib/administrate/engine.rb +7 -6
- data/lib/administrate/field/associative.rb +8 -23
- data/lib/administrate/field/base.rb +40 -5
- data/lib/administrate/field/belongs_to.rb +8 -8
- data/lib/administrate/field/date.rb +6 -2
- data/lib/administrate/field/date_time.rb +3 -4
- data/lib/administrate/field/deferred.rb +14 -18
- data/lib/administrate/field/has_many.rb +25 -6
- data/lib/administrate/field/has_one.rb +11 -15
- data/lib/administrate/field/number.rb +2 -2
- data/lib/administrate/field/password.rb +4 -0
- data/lib/administrate/field/polymorphic.rb +4 -4
- data/lib/administrate/field/rich_text.rb +21 -0
- data/lib/administrate/field/select.rb +4 -0
- data/lib/administrate/field/time.rb +5 -4
- data/lib/administrate/generator_helpers.rb +1 -1
- data/lib/administrate/namespace/resource.rb +1 -1
- data/lib/administrate/namespace.rb +10 -10
- data/lib/administrate/order.rb +37 -33
- data/lib/administrate/page/base.rb +2 -7
- data/lib/administrate/page/collection.rb +2 -2
- data/lib/administrate/page/form.rb +1 -1
- data/lib/administrate/page/show.rb +1 -1
- data/lib/administrate/resource_resolver.rb +1 -1
- data/lib/administrate/search.rb +14 -16
- data/lib/administrate/version.rb +1 -1
- data/lib/administrate/view_generator.rb +4 -3
- data/lib/administrate.rb +0 -38
- data/lib/generators/administrate/dashboard/dashboard_generator.rb +12 -9
- data/lib/generators/administrate/field/field_generator.rb +2 -2
- data/lib/generators/administrate/install/install_generator.rb +3 -2
- data/lib/generators/administrate/routes/routes_generator.rb +6 -5
- data/lib/generators/administrate/views/field_generator.rb +2 -2
- data/lib/generators/administrate/views/index_generator.rb +5 -0
- data/lib/generators/administrate/views/layout_generator.rb +1 -1
- metadata +35 -76
- data/app/assets/javascripts/administrate/components/associative.js +0 -5
- data/app/assets/javascripts/administrate/components/select.js +0 -3
- data/app/assets/stylesheets/administrate/utilities/_text-color.scss +0 -3
- data/lib/generators/administrate/assets/assets_generator.rb +0 -12
- data/lib/generators/administrate/assets/javascripts_generator.rb +0 -17
- data/lib/generators/administrate/assets/stylesheets_generator.rb +0 -17
data/lib/administrate/engine.rb
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
require "jquery-rails"
|
|
2
1
|
require "kaminari"
|
|
3
|
-
require "sassc-rails"
|
|
4
|
-
require "selectize-rails"
|
|
5
|
-
require "sprockets/railtie"
|
|
6
2
|
|
|
7
3
|
require "administrate/namespace/resource"
|
|
8
4
|
require "administrate/not_authorized_error"
|
|
@@ -13,7 +9,6 @@ require "administrate/order"
|
|
|
13
9
|
require "administrate/resource_resolver"
|
|
14
10
|
require "administrate/search"
|
|
15
11
|
require "administrate/namespace"
|
|
16
|
-
require "administrate/namespace/resource"
|
|
17
12
|
|
|
18
13
|
module Administrate
|
|
19
14
|
class Engine < ::Rails::Engine
|
|
@@ -25,10 +20,16 @@ module Administrate
|
|
|
25
20
|
initializer "administrate.assets.precompile" do |app|
|
|
26
21
|
app.config.assets.precompile += [
|
|
27
22
|
"administrate/application.js",
|
|
28
|
-
"administrate/application.css"
|
|
23
|
+
"administrate/application.css"
|
|
29
24
|
]
|
|
30
25
|
end
|
|
31
26
|
|
|
27
|
+
initializer "administrate.action_text" do
|
|
28
|
+
ActiveSupport.on_load :action_text_rich_text do
|
|
29
|
+
require "administrate/field/rich_text"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
32
33
|
def self.add_javascript(script)
|
|
33
34
|
@@javascripts << script
|
|
34
35
|
end
|
|
@@ -37,51 +37,36 @@ module Administrate
|
|
|
37
37
|
|
|
38
38
|
def associated_class_name
|
|
39
39
|
if option_given?(:class_name)
|
|
40
|
-
|
|
40
|
+
options.fetch(:class_name)
|
|
41
41
|
else
|
|
42
42
|
self.class.associated_class_name(
|
|
43
43
|
resource.class,
|
|
44
|
-
attribute
|
|
44
|
+
attribute
|
|
45
45
|
)
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
+
def html_controller
|
|
50
|
+
"select"
|
|
51
|
+
end
|
|
52
|
+
|
|
49
53
|
private
|
|
50
54
|
|
|
51
55
|
def associated_dashboard
|
|
52
56
|
"#{associated_class_name}Dashboard".constantize.new
|
|
53
57
|
end
|
|
54
58
|
|
|
55
|
-
def primary_key
|
|
56
|
-
# Deprecated, renamed `association_primary_key`
|
|
57
|
-
Administrate.warn_of_deprecated_method(self.class, :primary_key)
|
|
58
|
-
association_primary_key
|
|
59
|
-
end
|
|
60
|
-
|
|
61
59
|
def association_primary_key
|
|
62
|
-
|
|
63
|
-
deprecated_option(:primary_key)
|
|
64
|
-
else
|
|
65
|
-
self.class.association_primary_key_for(resource.class, attribute)
|
|
66
|
-
end
|
|
60
|
+
self.class.association_primary_key_for(resource.class, attribute)
|
|
67
61
|
end
|
|
68
62
|
|
|
69
63
|
def foreign_key
|
|
70
|
-
|
|
71
|
-
deprecated_option(:foreign_key)
|
|
72
|
-
else
|
|
73
|
-
self.class.foreign_key_for(resource.class, attribute)
|
|
74
|
-
end
|
|
64
|
+
self.class.foreign_key_for(resource.class, attribute)
|
|
75
65
|
end
|
|
76
66
|
|
|
77
67
|
def option_given?(name)
|
|
78
68
|
options.key?(name)
|
|
79
69
|
end
|
|
80
|
-
|
|
81
|
-
def deprecated_option(name)
|
|
82
|
-
Administrate.warn_of_deprecated_option(name)
|
|
83
|
-
options.fetch(name)
|
|
84
|
-
end
|
|
85
70
|
end
|
|
86
71
|
end
|
|
87
72
|
end
|
|
@@ -24,6 +24,10 @@ module Administrate
|
|
|
24
24
|
false
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
+
def self.sortable?
|
|
28
|
+
true
|
|
29
|
+
end
|
|
30
|
+
|
|
27
31
|
def self.field_type
|
|
28
32
|
to_s.split("::").last.underscore
|
|
29
33
|
end
|
|
@@ -32,37 +36,68 @@ module Administrate
|
|
|
32
36
|
attr
|
|
33
37
|
end
|
|
34
38
|
|
|
39
|
+
def self.partial_prefixes
|
|
40
|
+
@partial_prefixes ||=
|
|
41
|
+
if superclass.respond_to?(:partial_prefixes)
|
|
42
|
+
local_partial_prefixes + superclass.partial_prefixes
|
|
43
|
+
else
|
|
44
|
+
local_partial_prefixes
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def self.local_partial_prefixes
|
|
49
|
+
["fields/#{field_type}"]
|
|
50
|
+
end
|
|
51
|
+
|
|
35
52
|
def initialize(attribute, data, page, options = {})
|
|
36
53
|
@attribute = attribute
|
|
37
|
-
@data = data
|
|
38
54
|
@page = page
|
|
39
55
|
@resource = options.delete(:resource)
|
|
40
56
|
@options = options
|
|
57
|
+
@data = read_value(data)
|
|
41
58
|
end
|
|
42
59
|
|
|
43
60
|
def html_class
|
|
44
61
|
self.class.html_class
|
|
45
62
|
end
|
|
46
63
|
|
|
64
|
+
def html_controller
|
|
65
|
+
nil
|
|
66
|
+
end
|
|
67
|
+
|
|
47
68
|
def name
|
|
48
69
|
attribute.to_s
|
|
49
70
|
end
|
|
50
71
|
|
|
51
|
-
def
|
|
52
|
-
|
|
72
|
+
def read_value(data)
|
|
73
|
+
if options.key?(:getter)
|
|
74
|
+
if options[:getter].respond_to?(:call)
|
|
75
|
+
options[:getter].call(self)
|
|
76
|
+
else
|
|
77
|
+
resource.try(options[:getter])
|
|
78
|
+
end
|
|
79
|
+
elsif data.nil?
|
|
80
|
+
resource.try(attribute)
|
|
81
|
+
else
|
|
82
|
+
data
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def partial_prefixes
|
|
87
|
+
self.class.partial_prefixes
|
|
53
88
|
end
|
|
54
89
|
|
|
55
90
|
def required?
|
|
56
91
|
return false unless resource.class.respond_to?(:validators_on)
|
|
57
92
|
|
|
58
93
|
resource.class.validators_on(attribute).any? do |v|
|
|
59
|
-
next false unless v.
|
|
94
|
+
next false unless v.instance_of?(ActiveRecord::Validations::PresenceValidator)
|
|
60
95
|
|
|
61
96
|
options = v.options
|
|
62
97
|
next false if options.include?(:if)
|
|
63
98
|
next false if options.include?(:unless)
|
|
64
99
|
|
|
65
|
-
if on_option = options[:on]
|
|
100
|
+
if (on_option = options[:on])
|
|
66
101
|
if on_option == :create && !resource.persisted?
|
|
67
102
|
next true
|
|
68
103
|
end
|
|
@@ -5,12 +5,7 @@ module Administrate
|
|
|
5
5
|
class BelongsTo < Associative
|
|
6
6
|
def self.permitted_attribute(attr, options = {})
|
|
7
7
|
resource_class = options[:resource_class]
|
|
8
|
-
|
|
9
|
-
foreign_key_for(resource_class, attr)
|
|
10
|
-
else
|
|
11
|
-
Administrate.warn_of_missing_resource_class
|
|
12
|
-
:"#{attr}_id"
|
|
13
|
-
end
|
|
8
|
+
foreign_key_for(resource_class, attr)
|
|
14
9
|
end
|
|
15
10
|
|
|
16
11
|
def self.eager_load?
|
|
@@ -25,7 +20,7 @@ module Administrate
|
|
|
25
20
|
candidate_resources.map do |resource|
|
|
26
21
|
[
|
|
27
22
|
display_candidate_resource(resource),
|
|
28
|
-
resource.send(association_primary_key)
|
|
23
|
+
resource.send(association_primary_key)
|
|
29
24
|
]
|
|
30
25
|
end
|
|
31
26
|
end
|
|
@@ -41,7 +36,12 @@ module Administrate
|
|
|
41
36
|
private
|
|
42
37
|
|
|
43
38
|
def candidate_resources
|
|
44
|
-
scope =
|
|
39
|
+
scope =
|
|
40
|
+
if options[:scope]
|
|
41
|
+
options[:scope].arity.positive? ? options[:scope].call(self) : options[:scope].call
|
|
42
|
+
else
|
|
43
|
+
associated_class.all
|
|
44
|
+
end
|
|
45
45
|
|
|
46
46
|
order = options.delete(:order)
|
|
47
47
|
order ? scope.reorder(order) : scope
|
|
@@ -5,8 +5,8 @@ module Administrate
|
|
|
5
5
|
class Date < Base
|
|
6
6
|
def date
|
|
7
7
|
I18n.localize(
|
|
8
|
-
data.to_date,
|
|
9
|
-
format: format
|
|
8
|
+
data.in_time_zone(timezone).to_date,
|
|
9
|
+
format: format
|
|
10
10
|
)
|
|
11
11
|
end
|
|
12
12
|
|
|
@@ -15,6 +15,10 @@ module Administrate
|
|
|
15
15
|
def format
|
|
16
16
|
options.fetch(:format, :default)
|
|
17
17
|
end
|
|
18
|
+
|
|
19
|
+
def timezone
|
|
20
|
+
options.fetch(:timezone, ::Time.zone)
|
|
21
|
+
end
|
|
18
22
|
end
|
|
19
23
|
end
|
|
20
24
|
end
|
|
@@ -6,15 +6,14 @@ module Administrate
|
|
|
6
6
|
def date
|
|
7
7
|
I18n.localize(
|
|
8
8
|
data.in_time_zone(timezone).to_date,
|
|
9
|
-
format: format
|
|
9
|
+
format: format
|
|
10
10
|
)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def datetime
|
|
14
14
|
I18n.localize(
|
|
15
15
|
data.in_time_zone(timezone),
|
|
16
|
-
format: format
|
|
17
|
-
default: data,
|
|
16
|
+
format: format
|
|
18
17
|
)
|
|
19
18
|
end
|
|
20
19
|
|
|
@@ -25,7 +24,7 @@ module Administrate
|
|
|
25
24
|
end
|
|
26
25
|
|
|
27
26
|
def timezone
|
|
28
|
-
options.fetch(:timezone, ::Time.zone
|
|
27
|
+
options.fetch(:timezone, ::Time.zone)
|
|
29
28
|
end
|
|
30
29
|
end
|
|
31
30
|
end
|
|
@@ -21,6 +21,10 @@ module Administrate
|
|
|
21
21
|
options == other.options
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
+
def getter
|
|
25
|
+
options.fetch(:getter, nil)
|
|
26
|
+
end
|
|
27
|
+
|
|
24
28
|
def associative?
|
|
25
29
|
deferred_class.associative?
|
|
26
30
|
end
|
|
@@ -30,31 +34,23 @@ module Administrate
|
|
|
30
34
|
end
|
|
31
35
|
|
|
32
36
|
def searchable?
|
|
33
|
-
options.
|
|
37
|
+
if options.key?(:getter)
|
|
38
|
+
false
|
|
39
|
+
else
|
|
40
|
+
options.fetch(:searchable, deferred_class.searchable?)
|
|
41
|
+
end
|
|
34
42
|
end
|
|
35
43
|
|
|
36
|
-
def
|
|
37
|
-
|
|
38
|
-
"searchable_field is deprecated, use searchable_fields instead",
|
|
39
|
-
)
|
|
40
|
-
options.fetch(:searchable_field)
|
|
44
|
+
def searchable_fields
|
|
45
|
+
options.fetch(:searchable_fields)
|
|
41
46
|
end
|
|
42
47
|
|
|
43
|
-
def
|
|
44
|
-
|
|
45
|
-
[searchable_field]
|
|
46
|
-
else
|
|
47
|
-
options.fetch(:searchable_fields)
|
|
48
|
-
end
|
|
48
|
+
def sortable?
|
|
49
|
+
options.fetch(:sortable, deferred_class.sortable?)
|
|
49
50
|
end
|
|
50
51
|
|
|
51
52
|
def permitted_attribute(attr, opts = {})
|
|
52
|
-
|
|
53
|
-
Administrate.warn_of_deprecated_option(:foreign_key)
|
|
54
|
-
options.fetch(:foreign_key)
|
|
55
|
-
else
|
|
56
|
-
deferred_class.permitted_attribute(attr, options.merge(opts))
|
|
57
|
-
end
|
|
53
|
+
deferred_class.permitted_attribute(attr, options.merge(opts))
|
|
58
54
|
end
|
|
59
55
|
|
|
60
56
|
delegate :html_class, to: :deferred_class
|
|
@@ -18,14 +18,14 @@ module Administrate
|
|
|
18
18
|
# be `country_ids` instead.
|
|
19
19
|
#
|
|
20
20
|
# See https://github.com/rails/rails/blob/b30a23f53b52e59d31358f7b80385ee5c2ba3afe/activerecord/lib/active_record/associations/builder/collection_association.rb#L48
|
|
21
|
-
{
|
|
21
|
+
{"#{attr.to_s.singularize}_ids": []}
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def associated_collection(order = self.order)
|
|
25
25
|
Administrate::Page::Collection.new(
|
|
26
26
|
associated_dashboard,
|
|
27
27
|
order: order,
|
|
28
|
-
collection_attributes: options[:collection_attributes]
|
|
28
|
+
collection_attributes: options[:collection_attributes]
|
|
29
29
|
)
|
|
30
30
|
end
|
|
31
31
|
|
|
@@ -37,7 +37,7 @@ module Administrate
|
|
|
37
37
|
candidate_resources.map do |associated_resource|
|
|
38
38
|
[
|
|
39
39
|
display_candidate_resource(associated_resource),
|
|
40
|
-
associated_resource.send(association_primary_key)
|
|
40
|
+
associated_resource.send(association_primary_key)
|
|
41
41
|
]
|
|
42
42
|
end
|
|
43
43
|
end
|
|
@@ -59,7 +59,7 @@ module Administrate
|
|
|
59
59
|
def permitted_attribute
|
|
60
60
|
self.class.permitted_attribute(
|
|
61
61
|
attribute,
|
|
62
|
-
resource_class: resource.class
|
|
62
|
+
resource_class: resource.class
|
|
63
63
|
)
|
|
64
64
|
end
|
|
65
65
|
|
|
@@ -72,7 +72,7 @@ module Administrate
|
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
def more_than_limit?
|
|
75
|
-
paginate? && data.
|
|
75
|
+
paginate? && data.size > limit
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
def data
|
|
@@ -83,11 +83,20 @@ module Administrate
|
|
|
83
83
|
Administrate::Order.new(
|
|
84
84
|
params.fetch(:order, sort_by),
|
|
85
85
|
params.fetch(:direction, direction),
|
|
86
|
+
sorting_column: sorting_column(
|
|
87
|
+
associated_dashboard_attribute(params.fetch(:order, sort_by))
|
|
88
|
+
)
|
|
86
89
|
)
|
|
87
90
|
end
|
|
88
91
|
|
|
89
92
|
def order
|
|
90
|
-
@order ||= Administrate::Order.new(
|
|
93
|
+
@order ||= Administrate::Order.new(
|
|
94
|
+
sort_by,
|
|
95
|
+
direction,
|
|
96
|
+
sorting_column: sorting_column(
|
|
97
|
+
associated_dashboard_attribute(sort_by)
|
|
98
|
+
)
|
|
99
|
+
)
|
|
91
100
|
end
|
|
92
101
|
|
|
93
102
|
private
|
|
@@ -109,6 +118,16 @@ module Administrate
|
|
|
109
118
|
associated_dashboard.display_resource(resource)
|
|
110
119
|
end
|
|
111
120
|
|
|
121
|
+
def sorting_column(dashboard_attribute)
|
|
122
|
+
return unless dashboard_attribute.try(:options)
|
|
123
|
+
|
|
124
|
+
dashboard_attribute.options.fetch(:sorting_column, nil)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def associated_dashboard_attribute(attribute)
|
|
128
|
+
associated_dashboard.attribute_types[attribute.to_sym] if attribute
|
|
129
|
+
end
|
|
130
|
+
|
|
112
131
|
def sort_by
|
|
113
132
|
options[:sort_by]
|
|
114
133
|
end
|
|
@@ -7,23 +7,15 @@ module Administrate
|
|
|
7
7
|
resource_class = options[:resource_class]
|
|
8
8
|
final_associated_class_name =
|
|
9
9
|
if options.key?(:class_name)
|
|
10
|
-
Administrate.warn_of_deprecated_option(:class_name)
|
|
11
10
|
options.fetch(:class_name)
|
|
12
|
-
elsif resource_class
|
|
13
|
-
associated_class_name(resource_class, attr)
|
|
14
11
|
else
|
|
15
|
-
|
|
16
|
-
if options
|
|
17
|
-
attr.to_s.singularize.camelcase
|
|
18
|
-
else
|
|
19
|
-
attr
|
|
20
|
-
end
|
|
12
|
+
associated_class_name(resource_class, attr)
|
|
21
13
|
end
|
|
22
14
|
related_dashboard_attributes =
|
|
23
|
-
Administrate::ResourceResolver
|
|
24
|
-
new("admin/#{final_associated_class_name}")
|
|
25
|
-
dashboard_class.new.permitted_attributes + [:id]
|
|
26
|
-
{
|
|
15
|
+
Administrate::ResourceResolver
|
|
16
|
+
.new("admin/#{final_associated_class_name}")
|
|
17
|
+
.dashboard_class.new.permitted_attributes + [:id]
|
|
18
|
+
{"#{attr}_attributes": related_dashboard_attributes}
|
|
27
19
|
end
|
|
28
20
|
|
|
29
21
|
def self.eager_load?
|
|
@@ -33,14 +25,14 @@ module Administrate
|
|
|
33
25
|
def nested_form
|
|
34
26
|
@nested_form ||= Administrate::Page::Form.new(
|
|
35
27
|
resolver.dashboard_class.new,
|
|
36
|
-
data || resolver.resource_class.new
|
|
28
|
+
data || resolver.resource_class.new
|
|
37
29
|
)
|
|
38
30
|
end
|
|
39
31
|
|
|
40
32
|
def nested_show
|
|
41
33
|
@nested_show ||= Administrate::Page::Show.new(
|
|
42
34
|
resolver.dashboard_class.new,
|
|
43
|
-
data || resolver.resource_class.new
|
|
35
|
+
data || resolver.resource_class.new
|
|
44
36
|
)
|
|
45
37
|
end
|
|
46
38
|
|
|
@@ -48,6 +40,10 @@ module Administrate
|
|
|
48
40
|
data.try(:persisted?)
|
|
49
41
|
end
|
|
50
42
|
|
|
43
|
+
def html_controller
|
|
44
|
+
"select"
|
|
45
|
+
end
|
|
46
|
+
|
|
51
47
|
private
|
|
52
48
|
|
|
53
49
|
def resolver
|
|
@@ -38,8 +38,8 @@ module Administrate
|
|
|
38
38
|
formatter = options[:format][:formatter]
|
|
39
39
|
formatter_options = options[:format][:formatter_options].to_h
|
|
40
40
|
|
|
41
|
-
ActiveSupport::NumberHelper
|
|
42
|
-
try(formatter, result, **formatter_options) || result
|
|
41
|
+
ActiveSupport::NumberHelper
|
|
42
|
+
.try(formatter, result, **formatter_options) || result
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
45
|
end
|
|
@@ -4,23 +4,23 @@ module Administrate
|
|
|
4
4
|
module Field
|
|
5
5
|
class Polymorphic < BelongsTo
|
|
6
6
|
def self.permitted_attribute(attr, _options = {})
|
|
7
|
-
{
|
|
7
|
+
{attr => %i[type value]}
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def associated_resource_grouped_options
|
|
11
11
|
classes.map do |klass|
|
|
12
|
-
[klass.
|
|
12
|
+
[klass.model_name.human, candidate_resources_for(klass).map do |resource|
|
|
13
13
|
[display_candidate_resource(resource), resource.to_global_id]
|
|
14
14
|
end]
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def permitted_attribute
|
|
19
|
-
{
|
|
19
|
+
{attribute => %i[type value]}
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def selected_global_id
|
|
23
|
-
data
|
|
23
|
+
data&.to_global_id
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
private
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require "administrate/field/base"
|
|
2
|
+
|
|
3
|
+
module Administrate
|
|
4
|
+
module Field
|
|
5
|
+
class RichText < Administrate::Field::Base
|
|
6
|
+
def to_s
|
|
7
|
+
data&.to_plain_text
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def truncate
|
|
11
|
+
to_s.truncate(truncation_length)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def truncation_length
|
|
17
|
+
options.fetch(:truncate, 50)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -4,15 +4,16 @@ module Administrate
|
|
|
4
4
|
module Field
|
|
5
5
|
class Time < Base
|
|
6
6
|
def time
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
I18n.localize(
|
|
8
|
+
data,
|
|
9
|
+
format: format
|
|
10
|
+
)
|
|
10
11
|
end
|
|
11
12
|
|
|
12
13
|
private
|
|
13
14
|
|
|
14
15
|
def format
|
|
15
|
-
options
|
|
16
|
+
options.fetch(:format, "%I:%M%p")
|
|
16
17
|
end
|
|
17
18
|
end
|
|
18
19
|
end
|
|
@@ -11,10 +11,16 @@ module Administrate
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def routes
|
|
14
|
-
@routes ||=
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
@routes ||= begin
|
|
15
|
+
prefix = "#{namespace}/".freeze
|
|
16
|
+
Rails.application.routes.routes.filter_map do |route|
|
|
17
|
+
next unless route.defaults[:controller]&.start_with?(prefix)
|
|
18
|
+
|
|
19
|
+
[
|
|
20
|
+
route.defaults[:controller].delete_prefix(prefix),
|
|
21
|
+
route.defaults[:action]
|
|
22
|
+
]
|
|
23
|
+
end
|
|
18
24
|
end
|
|
19
25
|
end
|
|
20
26
|
|
|
@@ -25,11 +31,5 @@ module Administrate
|
|
|
25
31
|
private
|
|
26
32
|
|
|
27
33
|
attr_reader :namespace
|
|
28
|
-
|
|
29
|
-
def all_routes
|
|
30
|
-
Rails.application.routes.routes.map do |route|
|
|
31
|
-
route.defaults.values_at(:controller, :action).map(&:to_s)
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
34
|
end
|
|
35
35
|
end
|