administrate 0.9.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/administrate/components/{has_many_form.js → associative.js} +1 -0
- data/app/assets/javascripts/administrate/components/date_time_picker.js +10 -2
- data/app/assets/javascripts/administrate/components/table.js +1 -1
- data/app/assets/stylesheets/administrate/base/_tables.scss +3 -0
- data/app/assets/stylesheets/administrate/base/_typography.scss +1 -1
- data/app/assets/stylesheets/administrate/components/_attributes.scss +1 -1
- data/app/assets/stylesheets/administrate/components/_buttons.scss +8 -0
- data/app/assets/stylesheets/administrate/components/_cells.scss +2 -0
- data/app/assets/stylesheets/administrate/components/_field-unit.scss +13 -4
- data/app/assets/stylesheets/administrate/components/_flashes.scss +0 -8
- data/app/assets/stylesheets/administrate/components/_navigation.scss +2 -3
- data/app/assets/stylesheets/administrate/library/_variables.scss +10 -8
- data/app/controllers/administrate/application_controller.rb +42 -13
- data/app/controllers/concerns/administrate/punditize.rb +3 -3
- data/app/helpers/administrate/application_helper.rb +59 -14
- data/app/views/administrate/application/_collection.html.erb +7 -6
- data/app/views/administrate/application/_flashes.html.erb +1 -1
- data/app/views/administrate/application/_form.html.erb +2 -2
- data/app/views/administrate/application/{_icons.erb → _icons.html.erb} +0 -0
- data/app/views/administrate/application/_navigation.html.erb +5 -3
- data/app/views/administrate/application/index.html.erb +2 -0
- data/app/views/administrate/application/show.html.erb +1 -1
- data/app/views/fields/belongs_to/_index.html.erb +1 -1
- data/app/views/fields/belongs_to/_show.html.erb +1 -1
- data/app/views/fields/date/_form.html.erb +24 -0
- data/app/views/fields/date/_index.html.erb +21 -0
- data/app/views/fields/date/_show.html.erb +21 -0
- data/app/views/fields/date_time/_form.html.erb +1 -1
- data/app/views/fields/date_time/_index.html.erb +1 -1
- data/app/views/fields/has_many/_form.html.erb +2 -2
- data/app/views/fields/has_many/_show.html.erb +8 -5
- data/app/views/fields/has_one/_form.html.erb +1 -1
- data/app/views/fields/password/_form.html.erb +23 -0
- data/app/views/fields/password/_index.html.erb +18 -0
- data/app/views/fields/password/_show.html.erb +18 -0
- data/app/views/fields/polymorphic/_form.html.erb +0 -3
- data/app/views/fields/select/_form.html.erb +22 -10
- data/app/views/fields/string/_show.html.erb +2 -2
- data/app/views/fields/text/_show.html.erb +2 -3
- data/app/views/fields/time/_form.html.erb +23 -0
- data/app/views/fields/time/_index.html.erb +17 -0
- data/app/views/fields/time/_show.html.erb +17 -0
- data/app/views/fields/url/_form.html.erb +23 -0
- data/app/views/fields/url/_index.html.erb +20 -0
- data/app/views/fields/url/_show.html.erb +20 -0
- data/app/views/layouts/administrate/application.html.erb +1 -1
- data/config/locales/administrate.ar.yml +2 -0
- data/config/locales/administrate.bs.yml +2 -0
- data/config/locales/administrate.ca.yml +2 -0
- data/config/locales/administrate.da.yml +2 -0
- data/config/locales/administrate.de.yml +2 -0
- data/config/locales/administrate.en.yml +2 -0
- data/config/locales/administrate.es.yml +3 -1
- data/config/locales/administrate.fr.yml +2 -0
- data/config/locales/administrate.id.yml +30 -0
- data/config/locales/administrate.it.yml +2 -0
- data/config/locales/administrate.ja.yml +4 -2
- data/config/locales/administrate.ko.yml +12 -10
- data/config/locales/administrate.nl.yml +3 -1
- data/config/locales/administrate.pl.yml +2 -0
- data/config/locales/administrate.pt-BR.yml +2 -0
- data/config/locales/administrate.pt.yml +2 -0
- data/config/locales/administrate.ru.yml +4 -2
- data/config/locales/administrate.sq.yml +30 -0
- data/config/locales/administrate.sv.yml +2 -0
- data/config/locales/administrate.uk.yml +2 -0
- data/config/locales/administrate.vi.yml +2 -0
- data/config/locales/administrate.zh-CN.yml +4 -2
- data/config/locales/administrate.zh-TW.yml +6 -4
- data/docs/adding_controllers_without_related_model.md +36 -0
- data/docs/adding_custom_field_types.md +3 -1
- data/docs/authentication.md +3 -1
- data/docs/authorization.md +5 -3
- data/docs/contributing.md +1 -0
- data/docs/customizing_attribute_partials.md +5 -2
- data/docs/customizing_controller_actions.md +32 -2
- data/docs/customizing_dashboards.md +103 -13
- data/docs/customizing_page_views.md +23 -5
- data/docs/getting_started.md +22 -51
- data/docs/rails_api.md +45 -0
- data/lib/administrate/base_dashboard.rb +33 -8
- data/lib/administrate/custom_dashboard.rb +15 -0
- data/lib/administrate/engine.rb +1 -1
- data/lib/administrate/field/associative.rb +5 -5
- data/lib/administrate/field/base.rb +13 -13
- data/lib/administrate/field/belongs_to.rb +3 -1
- data/lib/administrate/field/date.rb +20 -0
- data/lib/administrate/field/date_time.rb +1 -1
- data/lib/administrate/field/deferred.rb +19 -0
- data/lib/administrate/field/has_many.rb +16 -9
- data/lib/administrate/field/has_one.rb +7 -7
- data/lib/administrate/field/password.rb +25 -0
- data/lib/administrate/field/polymorphic.rb +6 -6
- data/lib/administrate/field/select.rb +6 -1
- data/lib/administrate/field/time.rb +8 -0
- data/lib/administrate/field/url.rb +21 -0
- data/lib/administrate/namespace.rb +5 -1
- data/lib/administrate/order.rb +17 -7
- data/lib/administrate/page/base.rb +9 -3
- data/lib/administrate/page/collection.rb +5 -1
- data/lib/administrate/page/form.rb +1 -1
- data/lib/administrate/search.rb +126 -11
- data/lib/administrate/version.rb +1 -1
- data/lib/administrate/view_generator.rb +2 -2
- data/lib/generators/administrate/dashboard/dashboard_generator.rb +19 -6
- data/lib/generators/administrate/dashboard/templates/controller.rb.erb +33 -8
- data/lib/generators/administrate/dashboard/templates/dashboard.rb.erb +18 -6
- data/lib/generators/administrate/install/templates/application_controller.rb.erb +3 -3
- data/lib/generators/administrate/routes/routes_generator.rb +18 -13
- data/lib/generators/administrate/views/layout_generator.rb +1 -0
- metadata +47 -31
- data/config/secrets.yml +0 -14
@@ -1,6 +1,7 @@
|
|
1
1
|
require "administrate/field/belongs_to"
|
2
2
|
require "administrate/field/boolean"
|
3
3
|
require "administrate/field/date_time"
|
4
|
+
require "administrate/field/date"
|
4
5
|
require "administrate/field/email"
|
5
6
|
require "administrate/field/has_many"
|
6
7
|
require "administrate/field/has_one"
|
@@ -9,11 +10,26 @@ require "administrate/field/polymorphic"
|
|
9
10
|
require "administrate/field/select"
|
10
11
|
require "administrate/field/string"
|
11
12
|
require "administrate/field/text"
|
13
|
+
require "administrate/field/time"
|
14
|
+
require "administrate/field/url"
|
15
|
+
require "administrate/field/password"
|
12
16
|
|
13
17
|
module Administrate
|
14
18
|
class BaseDashboard
|
15
19
|
include Administrate
|
16
20
|
|
21
|
+
DASHBOARD_SUFFIX = "Dashboard".freeze
|
22
|
+
|
23
|
+
class << self
|
24
|
+
def model
|
25
|
+
to_s.chomp(DASHBOARD_SUFFIX).classify.constantize
|
26
|
+
end
|
27
|
+
|
28
|
+
def resource_name(opts)
|
29
|
+
model.model_name.human(opts)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
17
33
|
def attribute_types
|
18
34
|
self.class::ATTRIBUTE_TYPES
|
19
35
|
end
|
@@ -30,6 +46,10 @@ module Administrate
|
|
30
46
|
end
|
31
47
|
end
|
32
48
|
|
49
|
+
def all_attributes
|
50
|
+
attribute_types.keys
|
51
|
+
end
|
52
|
+
|
33
53
|
def form_attributes
|
34
54
|
self.class::FORM_ATTRIBUTES
|
35
55
|
end
|
@@ -52,15 +72,12 @@ module Administrate
|
|
52
72
|
"#{resource.class} ##{resource.id}"
|
53
73
|
end
|
54
74
|
|
55
|
-
def
|
56
|
-
|
57
|
-
|
58
|
-
collection_attributes.map do |key|
|
59
|
-
field = self.class::ATTRIBUTE_TYPES[key]
|
75
|
+
def collection_includes
|
76
|
+
attribute_includes(collection_attributes)
|
77
|
+
end
|
60
78
|
|
61
|
-
|
62
|
-
|
63
|
-
end.compact
|
79
|
+
def item_includes
|
80
|
+
attribute_includes(show_page_attributes)
|
64
81
|
end
|
65
82
|
|
66
83
|
private
|
@@ -68,5 +85,13 @@ module Administrate
|
|
68
85
|
def attribute_not_found_message(attr)
|
69
86
|
"Attribute #{attr} could not be found in #{self.class}::ATTRIBUTE_TYPES"
|
70
87
|
end
|
88
|
+
|
89
|
+
def attribute_includes(attributes)
|
90
|
+
attributes.map do |key|
|
91
|
+
field = self.class::ATTRIBUTE_TYPES[key]
|
92
|
+
|
93
|
+
key if field.associative?
|
94
|
+
end.compact
|
95
|
+
end
|
71
96
|
end
|
72
97
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Administrate
|
2
|
+
class CustomDashboard
|
3
|
+
include Administrate
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def resource_name(_opts)
|
7
|
+
named_resource.pluralize.titleize
|
8
|
+
end
|
9
|
+
|
10
|
+
def resource(resource_name)
|
11
|
+
define_singleton_method(:named_resource) { resource_name }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/administrate/engine.rb
CHANGED
@@ -7,16 +7,16 @@ module Administrate
|
|
7
7
|
associated_dashboard.display_resource(data)
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
def associated_class
|
11
|
+
associated_class_name.constantize
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
11
15
|
|
12
16
|
def associated_dashboard
|
13
17
|
"#{associated_class_name}Dashboard".constantize.new
|
14
18
|
end
|
15
19
|
|
16
|
-
def associated_class
|
17
|
-
associated_class_name.constantize
|
18
|
-
end
|
19
|
-
|
20
20
|
def associated_class_name
|
21
21
|
options.fetch(:class_name, attribute.to_s.singularize.camelcase)
|
22
22
|
end
|
@@ -12,10 +12,22 @@ module Administrate
|
|
12
12
|
field_type.dasherize
|
13
13
|
end
|
14
14
|
|
15
|
+
def self.associative?
|
16
|
+
self < Associative
|
17
|
+
end
|
18
|
+
|
15
19
|
def self.searchable?
|
16
20
|
false
|
17
21
|
end
|
18
22
|
|
23
|
+
def self.field_type
|
24
|
+
to_s.split("::").last.underscore
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.permitted_attribute(attr, _options = nil)
|
28
|
+
attr
|
29
|
+
end
|
30
|
+
|
19
31
|
def initialize(attribute, data, page, options = {})
|
20
32
|
@attribute = attribute
|
21
33
|
@data = data
|
@@ -24,10 +36,6 @@ module Administrate
|
|
24
36
|
@options = options
|
25
37
|
end
|
26
38
|
|
27
|
-
def self.permitted_attribute(attr, _options = nil)
|
28
|
-
attr
|
29
|
-
end
|
30
|
-
|
31
39
|
def html_class
|
32
40
|
self.class.html_class
|
33
41
|
end
|
@@ -40,15 +48,7 @@ module Administrate
|
|
40
48
|
"/fields/#{self.class.field_type}/#{page}"
|
41
49
|
end
|
42
50
|
|
43
|
-
attr_reader :attribute, :data, :page, :resource
|
44
|
-
|
45
|
-
protected
|
46
|
-
|
47
|
-
attr_reader :options
|
48
|
-
|
49
|
-
def self.field_type
|
50
|
-
to_s.split("::").last.underscore
|
51
|
-
end
|
51
|
+
attr_reader :attribute, :data, :options, :page, :resource
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
@@ -24,8 +24,10 @@ module Administrate
|
|
24
24
|
private
|
25
25
|
|
26
26
|
def candidate_resources
|
27
|
+
scope = options[:scope] ? options[:scope].call : associated_class.all
|
28
|
+
|
27
29
|
order = options.delete(:order)
|
28
|
-
order ?
|
30
|
+
order ? scope.reorder(order) : scope
|
29
31
|
end
|
30
32
|
|
31
33
|
def display_candidate_resource(resource)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative "base"
|
2
|
+
|
3
|
+
module Administrate
|
4
|
+
module Field
|
5
|
+
class Date < Base
|
6
|
+
def date
|
7
|
+
I18n.localize(
|
8
|
+
data.to_date,
|
9
|
+
format: format,
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def format
|
16
|
+
options.fetch(:format, :default)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -21,10 +21,29 @@ module Administrate
|
|
21
21
|
options == other.options
|
22
22
|
end
|
23
23
|
|
24
|
+
def associative?
|
25
|
+
deferred_class.associative?
|
26
|
+
end
|
27
|
+
|
24
28
|
def searchable?
|
25
29
|
options.fetch(:searchable, deferred_class.searchable?)
|
26
30
|
end
|
27
31
|
|
32
|
+
def searchable_field
|
33
|
+
ActiveSupport::Deprecation.warn(
|
34
|
+
"searchable_field is deprecated, use searchable_fields instead",
|
35
|
+
)
|
36
|
+
options.fetch(:searchable_field)
|
37
|
+
end
|
38
|
+
|
39
|
+
def searchable_fields
|
40
|
+
if options.key?(:searchable_field)
|
41
|
+
[searchable_field]
|
42
|
+
else
|
43
|
+
options.fetch(:searchable_fields)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
28
47
|
def permitted_attribute(attr, _options = nil)
|
29
48
|
options.fetch(:foreign_key,
|
30
49
|
deferred_class.permitted_attribute(attr, options))
|
@@ -11,8 +11,8 @@ module Administrate
|
|
11
11
|
{ "#{attr.to_s.singularize}_ids".to_sym => [] }
|
12
12
|
end
|
13
13
|
|
14
|
-
def associated_collection
|
15
|
-
Administrate::Page::Collection.new(associated_dashboard)
|
14
|
+
def associated_collection(order = self.order)
|
15
|
+
Administrate::Page::Collection.new(associated_dashboard, order: order)
|
16
16
|
end
|
17
17
|
|
18
18
|
def attribute_key
|
@@ -39,7 +39,7 @@ module Administrate
|
|
39
39
|
self.class.permitted_attribute(attribute)
|
40
40
|
end
|
41
41
|
|
42
|
-
def resources(page = 1)
|
42
|
+
def resources(page = 1, order = self.order)
|
43
43
|
resources = order.apply(data).page(page).per(limit)
|
44
44
|
includes.any? ? resources.includes(*includes) : resources
|
45
45
|
end
|
@@ -49,13 +49,24 @@ module Administrate
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def data
|
52
|
-
@data ||= associated_class.none
|
52
|
+
@data ||= associated_class.none
|
53
|
+
end
|
54
|
+
|
55
|
+
def order_from_params(params)
|
56
|
+
Administrate::Order.new(
|
57
|
+
params.fetch(:order, sort_by),
|
58
|
+
params.fetch(:direction, direction),
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
62
|
+
def order
|
63
|
+
@order ||= Administrate::Order.new(sort_by, direction)
|
53
64
|
end
|
54
65
|
|
55
66
|
private
|
56
67
|
|
57
68
|
def includes
|
58
|
-
associated_dashboard.
|
69
|
+
associated_dashboard.collection_includes
|
59
70
|
end
|
60
71
|
|
61
72
|
def candidate_resources
|
@@ -71,10 +82,6 @@ module Administrate
|
|
71
82
|
associated_dashboard.display_resource(resource)
|
72
83
|
end
|
73
84
|
|
74
|
-
def order
|
75
|
-
@_order ||= Administrate::Order.new(sort_by, direction)
|
76
|
-
end
|
77
|
-
|
78
85
|
def sort_by
|
79
86
|
options[:sort_by]
|
80
87
|
end
|
@@ -3,13 +3,6 @@ require_relative "associative"
|
|
3
3
|
module Administrate
|
4
4
|
module Field
|
5
5
|
class HasOne < Associative
|
6
|
-
def nested_form
|
7
|
-
@nested_form ||= Administrate::Page::Form.new(
|
8
|
-
resolver.dashboard_class.new,
|
9
|
-
data || resolver.resource_class.new,
|
10
|
-
)
|
11
|
-
end
|
12
|
-
|
13
6
|
def self.permitted_attribute(attr, options = nil)
|
14
7
|
associated_class_name =
|
15
8
|
if options
|
@@ -24,6 +17,13 @@ module Administrate
|
|
24
17
|
{ "#{attr}_attributes": related_dashboard_attributes }
|
25
18
|
end
|
26
19
|
|
20
|
+
def nested_form
|
21
|
+
@nested_form ||= Administrate::Page::Form.new(
|
22
|
+
resolver.dashboard_class.new,
|
23
|
+
data || resolver.resource_class.new,
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
27
|
private
|
28
28
|
|
29
29
|
def resolver
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative "base"
|
2
|
+
|
3
|
+
module Administrate
|
4
|
+
module Field
|
5
|
+
class Password < Field::Base
|
6
|
+
def self.searchable?
|
7
|
+
false
|
8
|
+
end
|
9
|
+
|
10
|
+
def truncate
|
11
|
+
data.to_s.gsub(/./, character)[0...truncation_length]
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def truncation_length
|
17
|
+
options.fetch(:truncate, 50)
|
18
|
+
end
|
19
|
+
|
20
|
+
def character
|
21
|
+
options.fetch(:character, "•")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -3,6 +3,10 @@ require_relative "associative"
|
|
3
3
|
module Administrate
|
4
4
|
module Field
|
5
5
|
class Polymorphic < BelongsTo
|
6
|
+
def self.permitted_attribute(attr, _options = nil)
|
7
|
+
{ attr => %i{type value} }
|
8
|
+
end
|
9
|
+
|
6
10
|
def associated_resource_grouped_options
|
7
11
|
classes.map do |klass|
|
8
12
|
[klass.to_s, candidate_resources_for(klass).map do |resource|
|
@@ -11,10 +15,6 @@ module Administrate
|
|
11
15
|
end
|
12
16
|
end
|
13
17
|
|
14
|
-
def self.permitted_attribute(attr, _options = nil)
|
15
|
-
{ attr => %i{type value} }
|
16
|
-
end
|
17
|
-
|
18
18
|
def permitted_attribute
|
19
19
|
{ attribute => %i{type value} }
|
20
20
|
end
|
@@ -23,14 +23,14 @@ module Administrate
|
|
23
23
|
data ? data.to_global_id : nil
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
private
|
27
27
|
|
28
28
|
def associated_dashboard(klass = data.class)
|
29
29
|
"#{klass.name}Dashboard".constantize.new
|
30
30
|
end
|
31
31
|
|
32
32
|
def classes
|
33
|
-
options.fetch(:classes
|
33
|
+
options.fetch(:classes, [])
|
34
34
|
end
|
35
35
|
|
36
36
|
private
|
@@ -14,7 +14,12 @@ module Administrate
|
|
14
14
|
private
|
15
15
|
|
16
16
|
def collection
|
17
|
-
|
17
|
+
values = options.fetch(:collection, [])
|
18
|
+
if values.respond_to? :call
|
19
|
+
return values.arity.positive? ? values.call(self) : values.call
|
20
|
+
end
|
21
|
+
|
22
|
+
@collection ||= values
|
18
23
|
end
|
19
24
|
end
|
20
25
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative "base"
|
2
|
+
|
3
|
+
module Administrate
|
4
|
+
module Field
|
5
|
+
class Url < Field::Base
|
6
|
+
def self.searchable?
|
7
|
+
true
|
8
|
+
end
|
9
|
+
|
10
|
+
def truncate
|
11
|
+
data.to_s[0...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
|