administrate 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of administrate might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/assets/images/administrate/search.svg +2 -2
- data/app/assets/images/administrate/sort_arrow.svg +1 -1
- data/app/assets/javascripts/administrate/components/has_many_form.js +1 -1
- data/app/assets/stylesheets/administrate/application.scss +3 -8
- data/app/assets/stylesheets/administrate/base/_forms.scss +56 -44
- data/app/assets/stylesheets/administrate/base/_layout.scss +20 -0
- data/app/assets/stylesheets/administrate/base/_lists.scss +9 -21
- data/app/assets/stylesheets/administrate/base/_tables.scss +9 -6
- data/app/assets/stylesheets/administrate/base/_typography.scss +12 -57
- data/app/assets/stylesheets/administrate/components/_app-container.scss +7 -0
- data/app/assets/stylesheets/administrate/components/_attributes.scss +1 -1
- data/app/assets/stylesheets/administrate/components/_buttons.scss +36 -0
- data/app/assets/stylesheets/administrate/components/_cells.scss +31 -37
- data/app/assets/stylesheets/administrate/components/_field-unit.scss +17 -0
- data/app/assets/stylesheets/administrate/components/_flashes.scss +16 -0
- data/app/assets/stylesheets/administrate/components/_form-actions.scss +3 -0
- data/app/assets/stylesheets/administrate/components/_header.scss +9 -8
- data/app/assets/stylesheets/administrate/components/_main-content.scss +6 -0
- data/app/assets/stylesheets/administrate/components/_pagination.scss +3 -2
- data/app/assets/stylesheets/administrate/components/_search.scss +9 -10
- data/app/assets/stylesheets/administrate/components/_sidebar.scss +22 -0
- data/app/assets/stylesheets/administrate/components/_table.scss +7 -3
- data/app/assets/stylesheets/administrate/{mixins → library}/_data_label.scss +2 -2
- data/app/assets/stylesheets/administrate/library/_variables.scss +57 -0
- data/app/assets/stylesheets/docs.scss +92 -0
- data/app/controllers/administrate/application_controller.rb +4 -3
- data/app/controllers/docs_controller.rb +9 -0
- data/app/helpers/administrate/application_helper.rb +16 -0
- data/app/views/administrate/application/_collection.html.erb +17 -12
- data/app/views/administrate/application/_flashes.html.erb +1 -1
- data/app/views/administrate/application/_form.html.erb +6 -8
- data/app/views/administrate/application/_sidebar.html.erb +1 -1
- data/app/views/administrate/application/edit.html.erb +3 -3
- data/app/views/administrate/application/index.html.erb +7 -6
- data/app/views/administrate/application/new.html.erb +2 -2
- data/app/views/administrate/application/show.html.erb +3 -3
- data/app/views/fields/belongs_to/_form.html.erb +8 -4
- 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/boolean/_form.html.erb +6 -2
- data/app/views/fields/date_time/_form.html.erb +6 -2
- data/app/views/fields/email/_form.html.erb +6 -2
- data/app/views/fields/has_many/_form.html.erb +8 -5
- data/app/views/fields/has_one/_form.html.erb +3 -1
- data/app/views/fields/has_one/_index.html.erb +1 -1
- data/app/views/fields/has_one/_show.html.erb +1 -1
- data/app/views/fields/image/_form.html.erb +6 -2
- data/app/views/fields/number/_form.html.erb +6 -2
- data/app/views/fields/polymorphic/_form.html.erb +3 -1
- data/app/views/fields/polymorphic/_index.html.erb +1 -1
- data/app/views/fields/polymorphic/_show.html.erb +1 -1
- data/app/views/fields/string/_form.html.erb +6 -2
- data/app/views/fields/text/_form.html.erb +6 -2
- data/app/views/layouts/administrate/application.html.erb +11 -11
- data/app/views/layouts/docs.html.erb +39 -0
- data/config/locales/administrate.de.yml +2 -2
- data/config/locales/administrate.it.yml +23 -0
- data/config/locales/administrate.uk.yml +23 -0
- data/lib/administrate/engine.rb +2 -2
- data/lib/administrate/fields/deferred.rb +3 -1
- data/lib/administrate/generator_helpers.rb +13 -0
- data/lib/administrate/resource_resolver.rb +5 -3
- data/lib/administrate/search.rb +3 -0
- data/lib/administrate/version.rb +1 -1
- data/lib/administrate/view_generator.rb +3 -0
- data/lib/generators/administrate/assets/assets_generator.rb +13 -0
- data/lib/generators/administrate/assets/images_generator.rb +17 -0
- data/lib/generators/administrate/assets/javascripts_generator.rb +17 -0
- data/lib/generators/administrate/assets/stylesheets_generator.rb +17 -0
- data/lib/generators/administrate/dashboard/USAGE +1 -1
- data/lib/generators/administrate/dashboard/dashboard_generator.rb +23 -4
- data/lib/generators/administrate/dashboard/templates/dashboard.rb.erb +7 -1
- data/lib/generators/administrate/install/install_generator.rb +17 -51
- data/lib/generators/administrate/manifest/manifest_generator.rb +65 -0
- data/lib/generators/administrate/{install → manifest}/templates/dashboard_manifest.rb.erb +0 -0
- data/lib/generators/administrate/views/layout_generator.rb +22 -0
- data/lib/generators/administrate/views/sidebar_generator.rb +15 -0
- data/lib/generators/administrate/views/views_generator.rb +4 -4
- metadata +28 -37
- data/app/assets/stylesheets/administrate/_sidebar.scss +0 -27
- data/app/assets/stylesheets/administrate/base/_base.scss +0 -24
- data/app/assets/stylesheets/administrate/base/_buttons.scss +0 -11
- data/app/assets/stylesheets/administrate/base/_grid-settings.scss +0 -15
- data/app/assets/stylesheets/administrate/base/_variables.scss +0 -106
- data/app/assets/stylesheets/administrate/base/extends/_button.scss +0 -23
- data/app/assets/stylesheets/administrate/base/extends/_clearfix.scss +0 -3
- data/app/assets/stylesheets/administrate/base/extends/_errors.scss +0 -11
- data/app/assets/stylesheets/administrate/base/extends/_flashes.scss +0 -34
- data/app/assets/stylesheets/administrate/base/extends/_hide-text.scss +0 -3
- data/app/assets/stylesheets/administrate/components/_components.scss +0 -8
- data/app/assets/stylesheets/administrate/components/_date_time_picker.scss +0 -3
- data/app/assets/stylesheets/administrate/components/_form.scss +0 -41
- data/app/assets/stylesheets/administrate/layout.scss +0 -29
- data/app/assets/stylesheets/administrate/mixins/_mixins.scss +0 -2
- data/app/assets/stylesheets/administrate/mixins/_shadow.scss +0 -35
- data/lib/administrate/namespace.rb +0 -3
@@ -0,0 +1,23 @@
|
|
1
|
+
---
|
2
|
+
uk:
|
3
|
+
administrate:
|
4
|
+
actions:
|
5
|
+
confirm: Ви впевнені?
|
6
|
+
destroy: Видалити
|
7
|
+
edit: Редагувати
|
8
|
+
show: Показати
|
9
|
+
controller:
|
10
|
+
create:
|
11
|
+
success: "%{resource} було успішно створено."
|
12
|
+
destroy:
|
13
|
+
success: "%{resource} було успішно видалено."
|
14
|
+
update:
|
15
|
+
success: "%{resource} було успішно оновлено."
|
16
|
+
fields:
|
17
|
+
has_many:
|
18
|
+
more: "%{count} із %{total_count}"
|
19
|
+
none: Немає
|
20
|
+
polymorphic:
|
21
|
+
not_supported: Поліморфні відношення у формах не підтримуються.
|
22
|
+
has_one:
|
23
|
+
not_supported: HasOne відношення у формах не підтримуються.
|
data/lib/administrate/engine.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require "datetime_picker_rails"
|
2
|
-
require "inline_svg"
|
3
2
|
require "jquery-rails"
|
4
3
|
require "kaminari"
|
5
4
|
require "momentjs-rails"
|
@@ -9,7 +8,6 @@ require "sass-rails"
|
|
9
8
|
require "selectize-rails"
|
10
9
|
require "sprockets/railtie"
|
11
10
|
|
12
|
-
require "administrate/namespace"
|
13
11
|
require "administrate/page/form"
|
14
12
|
require "administrate/page/show"
|
15
13
|
require "administrate/page/collection"
|
@@ -20,5 +18,7 @@ require "administrate/search"
|
|
20
18
|
module Administrate
|
21
19
|
class Engine < ::Rails::Engine
|
22
20
|
isolate_namespace Administrate
|
21
|
+
|
22
|
+
Engine.config.assets.precompile << /\.(?:svg)\z/
|
23
23
|
end
|
24
24
|
end
|
@@ -15,7 +15,9 @@ module Administrate
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def ==(other)
|
18
|
-
|
18
|
+
other.respond_to?(:deferred_class) &&
|
19
|
+
deferred_class == other.deferred_class &&
|
20
|
+
options == other.options
|
19
21
|
end
|
20
22
|
|
21
23
|
def searchable?
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require "administrate/namespace"
|
2
|
-
|
3
1
|
module Administrate
|
4
2
|
class ResourceResolver
|
5
3
|
def initialize(controller_path)
|
@@ -10,6 +8,10 @@ module Administrate
|
|
10
8
|
Object.const_get(resource_class_name + "Dashboard")
|
11
9
|
end
|
12
10
|
|
11
|
+
def namespace
|
12
|
+
controller_path.split("/").first
|
13
|
+
end
|
14
|
+
|
13
15
|
def resource_class
|
14
16
|
Object.const_get(resource_class_name)
|
15
17
|
end
|
@@ -33,7 +35,7 @@ module Administrate
|
|
33
35
|
end
|
34
36
|
|
35
37
|
def controller_path_parts
|
36
|
-
controller_path.singularize.split("/")
|
38
|
+
controller_path.singularize.split("/")[1..-1]
|
37
39
|
end
|
38
40
|
|
39
41
|
attr_reader :controller_path
|
data/lib/administrate/search.rb
CHANGED
data/lib/administrate/version.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "administrate/view_generator"
|
2
|
+
|
3
|
+
module Administrate
|
4
|
+
module Generators
|
5
|
+
class AssetsGenerator < Administrate::ViewGenerator
|
6
|
+
def copy_assets
|
7
|
+
call_generator("administrate:assets:images")
|
8
|
+
call_generator("administrate:assets:javascripts")
|
9
|
+
call_generator("administrate:assets:stylesheets")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "rails/generators/base"
|
2
|
+
|
3
|
+
module Administrate
|
4
|
+
module Generators
|
5
|
+
module Assets
|
6
|
+
class ImagesGenerator < Rails::Generators::Base
|
7
|
+
IMAGES_PATH = "app/assets/images/administrate"
|
8
|
+
|
9
|
+
source_root File.expand_path("../../../../../", __FILE__)
|
10
|
+
|
11
|
+
def copy_images
|
12
|
+
directory IMAGES_PATH, IMAGES_PATH
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "rails/generators/base"
|
2
|
+
|
3
|
+
module Administrate
|
4
|
+
module Generators
|
5
|
+
module Assets
|
6
|
+
class JavascriptsGenerator < Rails::Generators::Base
|
7
|
+
JAVASCRIPTS_PATH = "app/assets/javascripts/administrate"
|
8
|
+
|
9
|
+
source_root File.expand_path("../../../../../", __FILE__)
|
10
|
+
|
11
|
+
def copy_javascripts
|
12
|
+
directory JAVASCRIPTS_PATH, JAVASCRIPTS_PATH
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "rails/generators/base"
|
2
|
+
|
3
|
+
module Administrate
|
4
|
+
module Generators
|
5
|
+
module Assets
|
6
|
+
class StylesheetsGenerator < Rails::Generators::Base
|
7
|
+
STYLESHEETS_PATH = "app/assets/stylesheets/administrate"
|
8
|
+
|
9
|
+
source_root File.expand_path("../../../../../", __FILE__)
|
10
|
+
|
11
|
+
def copy_stylesheets
|
12
|
+
directory STYLESHEETS_PATH, STYLESHEETS_PATH
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -7,6 +7,7 @@ module Administrate
|
|
7
7
|
boolean: "Field::Boolean",
|
8
8
|
date: "Field::DateTime",
|
9
9
|
datetime: "Field::DateTime",
|
10
|
+
enum: "Field::String",
|
10
11
|
float: "Field::Number",
|
11
12
|
integer: "Field::Number",
|
12
13
|
time: "Field::DateTime",
|
@@ -15,6 +16,7 @@ module Administrate
|
|
15
16
|
}
|
16
17
|
|
17
18
|
ATTRIBUTE_OPTIONS_MAPPING = {
|
19
|
+
enum: { searchable: false },
|
18
20
|
float: { decimals: 2 },
|
19
21
|
}
|
20
22
|
|
@@ -25,14 +27,18 @@ module Administrate
|
|
25
27
|
source_root File.expand_path("../templates", __FILE__)
|
26
28
|
|
27
29
|
def create_dashboard_definition
|
28
|
-
template
|
30
|
+
template(
|
31
|
+
"dashboard.rb.erb",
|
32
|
+
Rails.root.join("app/dashboards/#{file_name}_dashboard.rb"),
|
33
|
+
)
|
29
34
|
end
|
30
35
|
|
31
36
|
def create_resource_controller
|
32
|
-
|
33
|
-
"controller.rb.erb",
|
37
|
+
destination = Rails.root.join(
|
34
38
|
"app/controllers/admin/#{file_name.pluralize}_controller.rb",
|
35
39
|
)
|
40
|
+
|
41
|
+
template("controller.rb.erb", destination)
|
36
42
|
end
|
37
43
|
|
38
44
|
private
|
@@ -61,7 +67,7 @@ module Administrate
|
|
61
67
|
end
|
62
68
|
|
63
69
|
def field_type(attribute)
|
64
|
-
type =
|
70
|
+
type = column_type_for_attribute(attribute.to_s)
|
65
71
|
|
66
72
|
if type
|
67
73
|
ATTRIBUTE_TYPE_MAPPING.fetch(type, DEFAULT_FIELD_TYPE) +
|
@@ -71,6 +77,19 @@ module Administrate
|
|
71
77
|
end
|
72
78
|
end
|
73
79
|
|
80
|
+
def column_type_for_attribute(attr)
|
81
|
+
if enum_column?(attr)
|
82
|
+
:enum
|
83
|
+
else
|
84
|
+
klass.column_types[attr].type
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def enum_column?(attr)
|
89
|
+
klass.respond_to?(:defined_enums) &&
|
90
|
+
klass.defined_enums.keys.include?(attr)
|
91
|
+
end
|
92
|
+
|
74
93
|
def association_type(attribute)
|
75
94
|
relationship = klass.reflections[attribute.to_s]
|
76
95
|
if relationship.has_one?
|
@@ -28,7 +28,13 @@ class <%= class_name %>Dashboard < Administrate::BaseDashboard
|
|
28
28
|
|
29
29
|
# SHOW_PAGE_ATTRIBUTES
|
30
30
|
# an array of attributes that will be displayed on the model's show page.
|
31
|
-
SHOW_PAGE_ATTRIBUTES =
|
31
|
+
SHOW_PAGE_ATTRIBUTES = [
|
32
|
+
<%=
|
33
|
+
attributes.map do |attr|
|
34
|
+
" :#{attr},"
|
35
|
+
end.join("\n")
|
36
|
+
%>
|
37
|
+
]
|
32
38
|
|
33
39
|
# FORM_ATTRIBUTES
|
34
40
|
# an array of attributes that will be displayed
|
@@ -1,9 +1,10 @@
|
|
1
|
-
Rails.application.eager_load!
|
2
1
|
require "rails/generators/base"
|
2
|
+
require "administrate/generator_helpers"
|
3
3
|
|
4
4
|
module Administrate
|
5
5
|
module Generators
|
6
6
|
class InstallGenerator < Rails::Generators::Base
|
7
|
+
include Administrate::GeneratorHelpers
|
7
8
|
source_root File.expand_path("../templates", __FILE__)
|
8
9
|
|
9
10
|
def create_dashboard_controller
|
@@ -13,79 +14,44 @@ module Administrate
|
|
13
14
|
)
|
14
15
|
end
|
15
16
|
|
16
|
-
def create_dashboard_manifest
|
17
|
-
template(
|
18
|
-
"dashboard_manifest.rb.erb",
|
19
|
-
"app/dashboards/dashboard_manifest.rb"
|
20
|
-
)
|
21
|
-
end
|
22
|
-
|
23
17
|
def insert_dashboard_routes
|
24
|
-
|
18
|
+
unless File.read(rails_routes_file_path).include?(dashboard_routes)
|
19
|
+
route(dashboard_routes)
|
20
|
+
end
|
25
21
|
end
|
26
22
|
|
27
23
|
def run_dashboard_generators
|
28
24
|
singular_dashboard_resources.each do |resource|
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def warn_about_invalid_models
|
34
|
-
namespaced_models.each do |invalid_model|
|
35
|
-
puts "WARNING: Unable to generate a dashboard for #{invalid_model}."
|
36
|
-
puts " Administrate does not yet support namespaced models."
|
37
|
-
end
|
38
|
-
|
39
|
-
models_without_tables.each do |invalid_model|
|
40
|
-
puts "WARNING: Unable to generate a dashboard for #{invalid_model}."
|
41
|
-
puts " It is not connected to a database table."
|
42
|
-
end
|
43
|
-
|
44
|
-
unnamed_constants.each do |invalid_model|
|
45
|
-
puts "NOTICE: Skipping dynamically generated model #{invalid_model}."
|
25
|
+
call_generator("administrate:dashboard", resource)
|
46
26
|
end
|
47
27
|
end
|
48
28
|
|
49
29
|
private
|
50
30
|
|
51
31
|
def singular_dashboard_resources
|
52
|
-
dashboard_resources.map(&:singularize)
|
32
|
+
dashboard_resources.map(&:to_s).map(&:singularize)
|
53
33
|
end
|
54
34
|
|
55
35
|
def dashboard_resources
|
56
|
-
|
57
|
-
model.to_s.pluralize.underscore
|
58
|
-
end
|
36
|
+
manifest::DASHBOARDS
|
59
37
|
end
|
60
38
|
|
61
|
-
def
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
def database_models
|
66
|
-
ActiveRecord::Base.descendants
|
67
|
-
end
|
68
|
-
|
69
|
-
def invalid_database_models
|
70
|
-
models_without_tables + namespaced_models + unnamed_constants
|
71
|
-
end
|
72
|
-
|
73
|
-
def models_without_tables
|
74
|
-
database_models.reject(&:table_exists?)
|
75
|
-
end
|
76
|
-
|
77
|
-
def namespaced_models
|
78
|
-
database_models.select { |model| model.to_s.include?("::") }
|
79
|
-
end
|
39
|
+
def manifest
|
40
|
+
unless defined?(DashboardManifest)
|
41
|
+
call_generator("administrate:manifest")
|
42
|
+
end
|
80
43
|
|
81
|
-
|
82
|
-
ActiveRecord::Base.descendants.reject { |d| d.name == d.to_s }
|
44
|
+
DashboardManifest
|
83
45
|
end
|
84
46
|
|
85
47
|
def dashboard_routes
|
86
48
|
File.read(routes_file_path)
|
87
49
|
end
|
88
50
|
|
51
|
+
def rails_routes_file_path
|
52
|
+
Rails.root.join("config/routes.rb")
|
53
|
+
end
|
54
|
+
|
89
55
|
def routes_file_path
|
90
56
|
File.expand_path(find_in_source_paths("routes.rb"))
|
91
57
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
Rails.application.eager_load!
|
2
|
+
require "rails/generators/base"
|
3
|
+
|
4
|
+
module Administrate
|
5
|
+
module Generators
|
6
|
+
class ManifestGenerator < Rails::Generators::Base
|
7
|
+
source_root File.expand_path("../templates", __FILE__)
|
8
|
+
|
9
|
+
def create_dashboard_manifest
|
10
|
+
template(
|
11
|
+
"dashboard_manifest.rb.erb",
|
12
|
+
Rails.root.join("app/dashboards/dashboard_manifest.rb"),
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
def warn_about_invalid_models
|
17
|
+
namespaced_models.each do |invalid_model|
|
18
|
+
puts "WARNING: Unable to generate a dashboard for #{invalid_model}."
|
19
|
+
puts " Administrate does not yet support namespaced models."
|
20
|
+
end
|
21
|
+
|
22
|
+
models_without_tables.each do |invalid_model|
|
23
|
+
puts "WARNING: Unable to generate a dashboard for #{invalid_model}."
|
24
|
+
puts " It is not connected to a database table."
|
25
|
+
end
|
26
|
+
|
27
|
+
unnamed_constants.each do |invalid_model|
|
28
|
+
puts "NOTICE: Skipping dynamically generated model #{invalid_model}."
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def dashboard_resources
|
35
|
+
valid_dashboard_models.map do |model|
|
36
|
+
model.to_s.pluralize.underscore
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def valid_dashboard_models
|
41
|
+
database_models - invalid_database_models
|
42
|
+
end
|
43
|
+
|
44
|
+
def database_models
|
45
|
+
ActiveRecord::Base.descendants
|
46
|
+
end
|
47
|
+
|
48
|
+
def invalid_database_models
|
49
|
+
models_without_tables + namespaced_models + unnamed_constants
|
50
|
+
end
|
51
|
+
|
52
|
+
def models_without_tables
|
53
|
+
database_models.reject(&:table_exists?)
|
54
|
+
end
|
55
|
+
|
56
|
+
def namespaced_models
|
57
|
+
database_models.select { |model| model.to_s.include?("::") }
|
58
|
+
end
|
59
|
+
|
60
|
+
def unnamed_constants
|
61
|
+
ActiveRecord::Base.descendants.reject { |d| d.name == d.to_s }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|