obitum-rails_admin 0.0.1 → 0.0.2
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.
- data/Gemfile +1 -8
- data/README.md +6 -2
- data/app/assets/javascripts/rails_admin/custom/ui.js +5 -5
- data/app/assets/javascripts/rails_admin/jquery-ui-1.8.16.custom.js +4727 -4727
- data/app/assets/javascripts/rails_admin/jquery.colorpicker.js +484 -484
- data/app/assets/javascripts/rails_admin/jquery.pjax.js +250 -85
- data/app/assets/javascripts/rails_admin/jquery.ui.timepicker.js +1371 -1219
- data/app/assets/javascripts/rails_admin/ra.filter-box.js +30 -30
- data/app/assets/javascripts/rails_admin/ra.filtering-select.js +11 -11
- data/app/assets/javascripts/rails_admin/ra.nested-form-hooks.coffee +40 -0
- data/app/assets/javascripts/rails_admin/ra.remote-form.js +41 -39
- data/app/assets/javascripts/rails_admin/rails_admin.js.erb +4 -3
- data/app/assets/javascripts/rails_admin/themes/default/ui.js +6 -6
- data/app/assets/javascripts/rails_admin/ui.js.coffee +44 -16
- data/app/assets/stylesheets/rails_admin/base/README +2 -2
- data/app/assets/stylesheets/rails_admin/base/theming.css.scss +226 -113
- data/app/assets/stylesheets/rails_admin/custom/mixins.css.scss +1 -1
- data/app/assets/stylesheets/rails_admin/custom/theming.css.scss +2 -2
- data/app/assets/stylesheets/rails_admin/custom/variables.css.scss +3 -3
- data/app/assets/stylesheets/rails_admin/imports.css.scss.erb +36 -1
- data/app/assets/stylesheets/rails_admin/jquery.ui.timepicker.css.scss +16 -0
- data/app/assets/stylesheets/rails_admin/ra.filtering-multiselect.css.scss +2 -2
- data/app/assets/stylesheets/rails_admin/themes/default/mixins.css.scss +1 -1
- data/app/assets/stylesheets/rails_admin/themes/default/theming.css.scss +2 -2
- data/app/assets/stylesheets/rails_admin/themes/default/variables.css.scss +3 -3
- data/app/controllers/rails_admin/application_controller.rb +13 -18
- data/app/controllers/rails_admin/main_controller.rb +15 -16
- data/app/helpers/rails_admin/application_helper.rb +67 -41
- data/app/helpers/rails_admin/form_builder.rb +31 -29
- data/app/helpers/rails_admin/main_helper.rb +4 -4
- data/app/views/layouts/rails_admin/_secondary_navigation.html.haml +12 -11
- data/app/views/layouts/rails_admin/application.html.haml +29 -29
- data/app/views/rails_admin/main/_dashboard_history.html.haml +1 -1
- data/app/views/rails_admin/main/_delete_notice.html.haml +4 -5
- data/app/views/rails_admin/main/_form_colorpicker.html.haml +2 -1
- data/app/views/rails_admin/main/_form_datetime.html.haml +1 -1
- data/app/views/rails_admin/main/_form_enumeration.html.haml +1 -1
- data/app/views/rails_admin/main/_form_field.html.haml +1 -1
- data/app/views/rails_admin/main/_form_file_upload.html.haml +3 -2
- data/app/views/rails_admin/main/_form_filtering_multiselect.html.haml +6 -4
- data/app/views/rails_admin/main/_form_filtering_select.html.haml +6 -5
- data/app/views/rails_admin/main/_form_nested_many.html.haml +41 -6
- data/app/views/rails_admin/main/_form_nested_one.html.haml +34 -5
- data/app/views/rails_admin/main/_form_text.html.haml +3 -3
- data/app/views/rails_admin/main/_submit_buttons.html.haml +6 -4
- data/app/views/rails_admin/main/bulk_delete.html.haml +7 -3
- data/app/views/rails_admin/main/dashboard.html.haml +4 -4
- data/app/views/rails_admin/main/delete.html.haml +7 -3
- data/app/views/rails_admin/main/edit.html.haml +1 -1
- data/app/views/rails_admin/main/export.html.haml +57 -53
- data/app/views/rails_admin/main/history.html.haml +8 -8
- data/app/views/rails_admin/main/index.html.haml +22 -21
- data/app/views/rails_admin/main/new.html.haml +1 -1
- data/app/views/rails_admin/main/show.html.haml +2 -2
- data/config/initializers/active_record_extensions.rb +2 -2
- data/config/initializers/haml.rb +0 -1
- data/config/locales/rails_admin.en.yml +5 -5
- data/lib/generators/rails_admin/templates/initializer.erb +7 -7
- data/lib/rails_admin/abstract_model.rb +36 -53
- data/lib/rails_admin/adapters/active_record/abstract_object.rb +32 -0
- data/lib/rails_admin/adapters/active_record.rb +56 -137
- data/lib/rails_admin/config/actions/base.rb +40 -28
- data/lib/rails_admin/config/actions/bulk_delete.rb +10 -11
- data/lib/rails_admin/config/actions/dashboard.rb +9 -5
- data/lib/rails_admin/config/actions/delete.rb +12 -9
- data/lib/rails_admin/config/actions/edit.rb +13 -9
- data/lib/rails_admin/config/actions/export.rb +9 -6
- data/lib/rails_admin/config/actions/history_index.rb +9 -5
- data/lib/rails_admin/config/actions/history_show.rb +9 -5
- data/lib/rails_admin/config/actions/index.rb +23 -13
- data/lib/rails_admin/config/actions/new.rb +14 -10
- data/lib/rails_admin/config/actions/show.rb +10 -5
- data/lib/rails_admin/config/actions/show_in_app.rb +9 -4
- data/lib/rails_admin/config/actions.rb +16 -16
- data/lib/rails_admin/config/configurable.rb +92 -0
- data/lib/rails_admin/config/fields/association.rb +6 -23
- data/lib/rails_admin/config/fields/base.rb +58 -40
- data/lib/rails_admin/config/fields/factories/belongs_to_association.rb +26 -0
- data/lib/rails_admin/config/fields/factories/carrierwave.rb +21 -2
- data/lib/rails_admin/config/fields/factories/devise.rb +9 -12
- data/lib/rails_admin/config/fields/factories/dragonfly.rb +13 -7
- data/lib/rails_admin/config/fields/factories/paperclip.rb +14 -15
- data/lib/rails_admin/config/fields/group.rb +16 -3
- data/lib/rails_admin/config/fields/types/belongs_to_association.rb +2 -2
- data/lib/rails_admin/config/fields/types/carrierwave.rb +0 -9
- data/lib/rails_admin/config/fields/types/color.rb +3 -3
- data/lib/rails_admin/config/fields/types/dragonfly.rb +1 -19
- data/lib/rails_admin/config/fields/types/file_upload.rb +7 -11
- data/lib/rails_admin/config/fields/types/has_many_association.rb +1 -6
- data/lib/rails_admin/config/fields/types/has_one_association.rb +4 -4
- data/lib/rails_admin/config/fields/types/paperclip.rb +0 -18
- data/lib/rails_admin/config/fields/types/password.rb +2 -2
- data/lib/rails_admin/config/fields/types/polymorphic_association.rb +2 -2
- data/lib/rails_admin/config/fields/types/text.rb +2 -2
- data/lib/rails_admin/config/fields.rb +7 -17
- data/lib/rails_admin/config/has_fields.rb +9 -9
- data/lib/rails_admin/config/has_groups.rb +2 -2
- data/lib/rails_admin/config/hideable.rb +2 -2
- data/lib/rails_admin/config/model.rb +23 -17
- data/lib/rails_admin/config/proxyable/proxy.rb +43 -0
- data/lib/rails_admin/config/proxyable.rb +12 -0
- data/lib/rails_admin/config/sections/base.rb +14 -4
- data/lib/rails_admin/config.rb +38 -9
- data/lib/rails_admin/extension.rb +1 -1
- data/lib/rails_admin/extensions/history/auditing_adapter.rb +6 -6
- data/lib/rails_admin/extensions/history/history.rb +2 -1
- data/lib/rails_admin/extensions/paper_trail/auditing_adapter.rb +13 -13
- data/lib/rails_admin/support/csv_converter.rb +6 -6
- data/lib/rails_admin/version.rb +1 -1
- data/lib/rails_admin.rb +0 -5
- data/spec/controllers/main_controller_spec.rb +7 -7
- data/spec/dummy_app/Gemfile +10 -7
- data/spec/dummy_app/Rakefile +1 -1
- data/spec/dummy_app/app/assets/images/rails.png +0 -0
- data/spec/dummy_app/app/assets/javascripts/application.js +15 -0
- data/spec/dummy_app/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy_app/app/controllers/players_controller.rb +1 -1
- data/spec/dummy_app/app/models/cms/basic_page.rb +1 -1
- data/spec/dummy_app/app/models/division.rb +5 -1
- data/spec/dummy_app/app/models/field_test.rb +4 -4
- data/spec/dummy_app/app/models/nested_field_test.rb +3 -0
- data/spec/dummy_app/app/models/player.rb +3 -3
- data/spec/dummy_app/app/views/layouts/application.html.erb +3 -2
- data/spec/dummy_app/app/views/players/show.html.haml +1 -1
- data/spec/dummy_app/config/application.rb +20 -5
- data/spec/dummy_app/config/database.yml +5 -2
- data/spec/dummy_app/config/environments/development.rb +11 -1
- data/spec/dummy_app/config/environments/production.rb +19 -3
- data/spec/dummy_app/config/environments/test.rb +5 -7
- data/spec/dummy_app/config/initializers/devise.rb +6 -0
- data/spec/dummy_app/config/initializers/inflections.rb +5 -0
- data/spec/dummy_app/config/initializers/secret_token.rb +1 -1
- data/spec/dummy_app/{foo/test/dummy/config → config}/initializers/wrap_parameters.rb +1 -1
- data/spec/dummy_app/config/routes.rb +1 -1
- data/spec/dummy_app/db/migrate/00000000000006_devise_create_users.rb +35 -5
- data/spec/dummy_app/db/migrate/20120118122004_add_categories.rb +1 -1
- data/spec/dummy_app/doc/README_FOR_APP +2 -0
- data/spec/dummy_app/public/404.html +26 -0
- data/spec/dummy_app/{foo/test/dummy/public → public}/422.html +0 -0
- data/spec/dummy_app/{foo/test/dummy/public → public}/500.html +0 -1
- data/spec/dummy_app/public/favicon.ico +0 -0
- data/spec/dummy_app/public/robots.txt +5 -0
- data/spec/helpers/application_helper_spec.rb +107 -42
- data/spec/{requests → integration}/authorization/cancan_spec.rb +4 -5
- data/spec/{requests → integration}/basic/bulk_action/rails_admin_basic_bulk_action_spec.rb +0 -0
- data/spec/{requests → integration}/basic/bulk_destroy/rails_admin_basic_bulk_destroy_spec.rb +3 -16
- data/spec/{requests → integration}/basic/create/rails_admin_basic_create_spec.rb +0 -2
- data/spec/{requests → integration}/basic/create/rails_admin_namespaced_model_create_spec.rb +0 -16
- data/spec/{requests → integration}/basic/delete/rails_admin_basic_delete_spec.rb +0 -0
- data/spec/{requests → integration}/basic/destroy/rails_admin_basic_destroy_spec.rb +0 -0
- data/spec/{requests → integration}/basic/edit/rails_admin_basic_edit_spec.rb +2 -2
- data/spec/{requests → integration}/basic/export/rails_admin_basic_export_spec.rb +1 -1
- data/spec/{requests → integration}/basic/list/rails_admin_basic_list_spec.rb +12 -38
- data/spec/{requests → integration}/basic/new/rails_admin_basic_new_spec.rb +0 -0
- data/spec/{requests → integration}/basic/new/rails_admin_namespaced_model_new_spec.rb +0 -0
- data/spec/{requests → integration}/basic/show/rails_admin_basic_show_spec.rb +1 -2
- data/spec/{requests → integration}/basic/update/rails_admin_basic_update_spec.rb +2 -2
- data/spec/{requests → integration}/config/edit/rails_admin_config_edit_spec.rb +65 -24
- data/spec/{requests → integration}/config/list/rails_admin_config_list_spec.rb +2 -2
- data/spec/{requests → integration}/config/show/rails_admin_config_show_spec.rb +20 -0
- data/spec/{requests → integration}/history/rails_admin_history_spec.rb +3 -3
- data/spec/{requests → integration}/rails_admin_spec.rb +8 -41
- data/spec/{requests → integration}/relation_spec.rb +0 -0
- data/spec/spec_helper.rb +13 -31
- data/spec/{lib → unit/adapters/active_record}/abstract_object_spec.rb +17 -5
- data/spec/unit/adapters/active_record_spec.rb +53 -0
- data/spec/{requests/actions.rb → unit/config/actions_spec.rb} +47 -31
- data/spec/unit/config/fields/base_spec.rb +291 -0
- data/spec/unit/config/model_spec.rb +75 -0
- data/spec/unit/config/sections_spec.rb +123 -0
- data/spec/{lib/rails_admin_spec.rb → unit/config_spec.rb} +65 -93
- metadata +127 -223
- data/app/assets/javascripts/rails_admin/jquery_nested_form.js +0 -58
- data/app/views/layouts/rails_admin/_navigation.html.haml +0 -17
- data/lib/rails_admin/abstract_object.rb +0 -28
- data/lib/rails_admin/config/base.rb +0 -111
- data/lib/rails_admin/config/proxy.rb +0 -40
- data/lib/rails_admin/generic_support.rb +0 -18
- data/spec/dummy_app/config/initializers/quiet_assets.rb +0 -10
- data/spec/dummy_app/foo/Gemfile +0 -17
- data/spec/dummy_app/foo/MIT-LICENSE +0 -20
- data/spec/dummy_app/foo/README.rdoc +0 -3
- data/spec/dummy_app/foo/Rakefile +0 -39
- data/spec/dummy_app/foo/app/assets/javascripts/foo/application.js +0 -9
- data/spec/dummy_app/foo/app/assets/stylesheets/foo/application.css +0 -7
- data/spec/dummy_app/foo/app/controllers/foo/application_controller.rb +0 -4
- data/spec/dummy_app/foo/app/helpers/foo/application_helper.rb +0 -4
- data/spec/dummy_app/foo/app/models/foo/bar.rb +0 -4
- data/spec/dummy_app/foo/app/views/layouts/foo/application.html.erb +0 -14
- data/spec/dummy_app/foo/config/routes.rb +0 -2
- data/spec/dummy_app/foo/foo.gemspec +0 -23
- data/spec/dummy_app/foo/lib/foo/engine.rb +0 -5
- data/spec/dummy_app/foo/lib/foo/version.rb +0 -3
- data/spec/dummy_app/foo/lib/foo.rb +0 -4
- data/spec/dummy_app/foo/lib/tasks/foo_tasks.rake +0 -4
- data/spec/dummy_app/foo/script/rails +0 -6
- data/spec/dummy_app/foo/test/dummy/Rakefile +0 -7
- data/spec/dummy_app/foo/test/dummy/app/assets/javascripts/application.js +0 -9
- data/spec/dummy_app/foo/test/dummy/app/assets/stylesheets/application.css +0 -7
- data/spec/dummy_app/foo/test/dummy/app/controllers/application_controller.rb +0 -3
- data/spec/dummy_app/foo/test/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy_app/foo/test/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy_app/foo/test/dummy/config/application.rb +0 -45
- data/spec/dummy_app/foo/test/dummy/config/boot.rb +0 -10
- data/spec/dummy_app/foo/test/dummy/config/database.yml +0 -25
- data/spec/dummy_app/foo/test/dummy/config/environment.rb +0 -5
- data/spec/dummy_app/foo/test/dummy/config/environments/development.rb +0 -30
- data/spec/dummy_app/foo/test/dummy/config/environments/production.rb +0 -60
- data/spec/dummy_app/foo/test/dummy/config/environments/test.rb +0 -39
- data/spec/dummy_app/foo/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy_app/foo/test/dummy/config/initializers/inflections.rb +0 -10
- data/spec/dummy_app/foo/test/dummy/config/initializers/mime_types.rb +0 -5
- data/spec/dummy_app/foo/test/dummy/config/initializers/secret_token.rb +0 -7
- data/spec/dummy_app/foo/test/dummy/config/initializers/session_store.rb +0 -8
- data/spec/dummy_app/foo/test/dummy/config/locales/en.yml +0 -5
- data/spec/dummy_app/foo/test/dummy/config/routes.rb +0 -4
- data/spec/dummy_app/foo/test/dummy/config.ru +0 -4
- data/spec/dummy_app/foo/test/dummy/db/schema.rb +0 -21
- data/spec/dummy_app/foo/test/dummy/public/404.html +0 -26
- data/spec/dummy_app/foo/test/dummy/public/favicon.ico +0 -0
- data/spec/dummy_app/foo/test/dummy/script/rails +0 -6
- data/spec/dummy_app/foo/test/fixtures/foo/bars.yml +0 -11
- data/spec/dummy_app/foo/test/foo_test.rb +0 -7
- data/spec/dummy_app/foo/test/integration/navigation_test.rb +0 -10
- data/spec/dummy_app/foo/test/test_helper.rb +0 -10
- data/spec/dummy_app/foo/test/unit/foo/bar_test.rb +0 -9
- data/spec/generator_helpers.rb +0 -30
- data/spec/generators/install_generator_spec.rb +0 -85
- data/spec/generators/uninstall_generator_spec.rb +0 -35
- data/spec/lib/custom_field.rb +0 -7
- data/spec/requests/config/navigation/rails_admin_config_navigation_spec.rb +0 -107
- data/spec/requests/config/rails_admin_config_spec.rb +0 -227
@@ -14,7 +14,7 @@ module RailsAdmin
|
|
14
14
|
def self.column_names
|
15
15
|
@column_names
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def parse_input(params)
|
19
19
|
params[name] = params[name].presence
|
20
20
|
end
|
@@ -27,7 +27,7 @@ module RailsAdmin
|
|
27
27
|
def value
|
28
28
|
""
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
register_instance_option :visible do
|
32
32
|
self.section.is_a?(RailsAdmin::Config::Sections::Edit)
|
33
33
|
end
|
@@ -38,7 +38,7 @@ module RailsAdmin
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def associated_collection(type)
|
41
|
-
return [] if type.
|
41
|
+
return [] if type.blank?
|
42
42
|
config = RailsAdmin.config(type)
|
43
43
|
config.abstract_model.all.map do |object|
|
44
44
|
[object.send(config.object_label_method), object.id]
|
@@ -46,7 +46,7 @@ module RailsAdmin
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def associated_model_config
|
49
|
-
@associated_model_config ||= association[:
|
49
|
+
@associated_model_config ||= association[:parent_model_proc].call.map{|type| RailsAdmin.config(type) }.select{|config| !config.excluded? }
|
50
50
|
end
|
51
51
|
|
52
52
|
def polymorphic_type_collection
|
@@ -18,7 +18,7 @@ module RailsAdmin
|
|
18
18
|
# If you want to have a different toolbar configuration for CKEditor
|
19
19
|
# create your own custom config.js and override this configuration
|
20
20
|
register_instance_option(:ckeditor_config_js) do
|
21
|
-
"/
|
21
|
+
"/assets/ckeditor/config.js"
|
22
22
|
end
|
23
23
|
|
24
24
|
register_instance_option(:html_attributes) do
|
@@ -27,7 +27,7 @@ module RailsAdmin
|
|
27
27
|
:rows => "3"
|
28
28
|
}
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
register_instance_option(:partial) do
|
32
32
|
:form_text
|
33
33
|
end
|
@@ -8,24 +8,14 @@ module RailsAdmin
|
|
8
8
|
mattr_reader :default_factory
|
9
9
|
@@default_factory = lambda do |parent, properties, fields|
|
10
10
|
# If it's an association
|
11
|
-
if properties.has_key?(:
|
11
|
+
if properties.has_key?(:parent_model_proc)
|
12
12
|
association = parent.abstract_model.associations.find {|a| a[:name].to_s == properties[:name].to_s}
|
13
13
|
field = RailsAdmin::Config::Fields::Types.load("#{association[:polymorphic] ? :polymorphic : properties[:type]}_association").new(parent, properties[:name], association)
|
14
|
-
|
15
|
-
|
16
|
-
# If it's a column
|
17
|
-
elsif !properties.has_key?(:parent_model)
|
18
|
-
fields << (field = RailsAdmin::Config::Fields::Types.load(properties[:type]).new(parent, properties[:name], properties))
|
19
|
-
# hide _type columns (handled as associations)
|
20
|
-
if parent.abstract_model.belongs_to_associations.find {|a| a[:foreign_type] == properties[:name] }
|
21
|
-
field.hide
|
22
|
-
end
|
23
|
-
# hide _id column
|
24
|
-
if parent.abstract_model.belongs_to_associations.find {|a| a[:child_key] == properties[:name] }
|
25
|
-
field.hide
|
26
|
-
field.filterable(false) # filtering is handled on the association itself
|
27
|
-
end
|
14
|
+
else
|
15
|
+
field = RailsAdmin::Config::Fields::Types.load(properties[:type]).new(parent, properties[:name], properties)
|
28
16
|
end
|
17
|
+
fields << field
|
18
|
+
field
|
29
19
|
end
|
30
20
|
|
31
21
|
# Registry of field factories.
|
@@ -55,7 +45,6 @@ module RailsAdmin
|
|
55
45
|
# @see RailsAdmin::Config::Fields.registry
|
56
46
|
def self.factory(parent)
|
57
47
|
fields = []
|
58
|
-
return fields unless parent.abstract_model.model_store_exists?
|
59
48
|
# Load fields for all properties (columns)
|
60
49
|
|
61
50
|
parent.abstract_model.properties.each do |properties|
|
@@ -66,7 +55,7 @@ module RailsAdmin
|
|
66
55
|
end
|
67
56
|
end
|
68
57
|
# Load fields for all associations (relations)
|
69
|
-
parent.abstract_model.associations.each do |association|
|
58
|
+
parent.abstract_model.associations.select{|a| a[:type] != :belongs_to }.each do |association| # :belongs_to are created by factory for belongs_to fields
|
70
59
|
# Unless a previous factory has already loaded current field as well
|
71
60
|
unless fields.find {|f| f.name == association[:name] }
|
72
61
|
# Loop through factories until one returns true
|
@@ -95,3 +84,4 @@ require 'rails_admin/config/fields/factories/devise'
|
|
95
84
|
require 'rails_admin/config/fields/factories/paperclip'
|
96
85
|
require 'rails_admin/config/fields/factories/dragonfly'
|
97
86
|
require 'rails_admin/config/fields/factories/carrierwave'
|
87
|
+
require 'rails_admin/config/fields/factories/belongs_to_association'
|
@@ -80,7 +80,7 @@ module RailsAdmin
|
|
80
80
|
# If a block is passed it will be evaluated in the context of each field
|
81
81
|
def fields(*field_names,&block)
|
82
82
|
return all_fields if field_names.empty? && !block
|
83
|
-
|
83
|
+
|
84
84
|
if field_names.empty?
|
85
85
|
defined = _fields.select {|f| f.defined }
|
86
86
|
defined = _fields if defined.empty?
|
@@ -101,28 +101,28 @@ module RailsAdmin
|
|
101
101
|
def fields_of_type(type, &block)
|
102
102
|
_fields.select {|f| type == f.type }.map! {|f| f.instance_eval &block } if block
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
# Accessor for all fields
|
106
106
|
def all_fields
|
107
107
|
((ro_fields = _fields(true)).select(&:defined).presence || ro_fields).map{|f| f.section = self; f }
|
108
108
|
end
|
109
|
-
|
109
|
+
|
110
110
|
# Get all fields defined as visible, in the correct order.
|
111
111
|
def visible_fields
|
112
112
|
i = 0
|
113
|
-
all_fields.map {|f| f.with(bindings) }.select(&:visible).sort_by{|f| [f.order, i += 1] } # stable sort, damn
|
113
|
+
all_fields.map {|f| f.with(bindings) }.select(&:visible?).sort_by{|f| [f.order, i += 1] } # stable sort, damn
|
114
114
|
end
|
115
|
-
|
115
|
+
|
116
116
|
protected
|
117
|
-
|
118
|
-
# Raw fields.
|
117
|
+
|
118
|
+
# Raw fields.
|
119
119
|
# Recursively returns parent section's raw fields
|
120
120
|
# Duping it if accessed for modification.
|
121
121
|
def _fields(readonly = false)
|
122
122
|
return @_fields if @_fields
|
123
123
|
return @_ro_fields if readonly && @_ro_fields
|
124
|
-
|
125
|
-
unless self.class == RailsAdmin::Config::Sections::Base
|
124
|
+
|
125
|
+
unless self.class == RailsAdmin::Config::Sections::Base
|
126
126
|
# parent is RailsAdmin::Config::Model, recursion is on Section's classes
|
127
127
|
@_ro_fields ||= parent.send(self.class.superclass.to_s.underscore.split('/').last)._fields(true).freeze
|
128
128
|
else # recursion tail
|
@@ -2,7 +2,7 @@ require 'rails_admin/config/fields/group'
|
|
2
2
|
|
3
3
|
module RailsAdmin
|
4
4
|
module Config
|
5
|
-
module HasGroups
|
5
|
+
module HasGroups
|
6
6
|
# Accessor for a group
|
7
7
|
#
|
8
8
|
# If group with given name does not yet exist it will be created. If a
|
@@ -16,7 +16,7 @@ module RailsAdmin
|
|
16
16
|
|
17
17
|
# Reader for groups that are marked as visible
|
18
18
|
def visible_groups
|
19
|
-
parent.groups.map {|f| f.section = self; f.with(bindings) }.select(&:visible).select{|g| g.visible_fields.present?}
|
19
|
+
parent.groups.map {|f| f.section = self; f.with(bindings) }.select(&:visible?).select{|g| g.visible_fields.present?}
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -9,12 +9,12 @@ module RailsAdmin
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
# Reader whether
|
12
|
+
# Reader whether object is hidden.
|
13
13
|
def hidden?
|
14
14
|
not visible
|
15
15
|
end
|
16
16
|
|
17
|
-
# Writer to hide
|
17
|
+
# Writer to hide object.
|
18
18
|
def hide(&block)
|
19
19
|
visible block ? proc { false == (instance_eval &block) } : false
|
20
20
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rails_admin/config'
|
2
|
-
require 'rails_admin/config/
|
2
|
+
require 'rails_admin/config/proxyable'
|
3
|
+
require 'rails_admin/config/configurable'
|
3
4
|
require 'rails_admin/config/hideable'
|
4
5
|
require 'rails_admin/config/has_groups'
|
5
6
|
require 'rails_admin/config/fields/group'
|
@@ -12,14 +13,20 @@ require 'rails_admin/config/actions'
|
|
12
13
|
module RailsAdmin
|
13
14
|
module Config
|
14
15
|
# Model specific configuration object.
|
15
|
-
class Model
|
16
|
+
class Model
|
17
|
+
include RailsAdmin::Config::Proxyable
|
18
|
+
include RailsAdmin::Config::Configurable
|
16
19
|
include RailsAdmin::Config::Hideable
|
17
20
|
include RailsAdmin::Config::Sections
|
18
|
-
|
21
|
+
|
19
22
|
attr_reader :abstract_model
|
20
23
|
attr_accessor :groups
|
21
|
-
|
24
|
+
attr_reader :parent, :root
|
25
|
+
|
22
26
|
def initialize(entity)
|
27
|
+
@parent = nil
|
28
|
+
@root = self
|
29
|
+
|
23
30
|
@abstract_model = begin
|
24
31
|
if entity.kind_of?(RailsAdmin::AbstractModel)
|
25
32
|
entity
|
@@ -29,15 +36,11 @@ module RailsAdmin
|
|
29
36
|
RailsAdmin::AbstractModel.new(entity.class)
|
30
37
|
end
|
31
38
|
end
|
32
|
-
|
33
39
|
@groups = [ RailsAdmin::Config::Fields::Group.new(self, :default).tap {|g| g.label{I18n.translate("admin.form.basic_info")} } ]
|
34
|
-
@bindings = {}
|
35
|
-
@parent = nil
|
36
|
-
@root = self
|
37
40
|
end
|
38
41
|
|
39
42
|
def excluded?
|
40
|
-
@excluded ||= !RailsAdmin::AbstractModel.all.map(&:
|
43
|
+
@excluded ||= !RailsAdmin::AbstractModel.all.map(&:model_name).include?(abstract_model.try(:model_name))
|
41
44
|
end
|
42
45
|
|
43
46
|
def object_label
|
@@ -48,28 +51,31 @@ module RailsAdmin
|
|
48
51
|
# Unless configured in a model config block, it'll try to use :name followed by :title methods, then
|
49
52
|
# any methods that may have been added to the label_methods array via Configuration.
|
50
53
|
# Failing all of these, it'll return the class name followed by the model's id.
|
51
|
-
register_instance_option
|
54
|
+
register_instance_option :object_label_method do
|
52
55
|
@object_label_method ||= Config.label_methods.find { |method| (@dummy_object ||= abstract_model.model.new).respond_to? method } || :rails_admin_default_object_label_method
|
53
56
|
end
|
54
57
|
|
55
|
-
register_instance_option
|
58
|
+
register_instance_option :label do
|
56
59
|
(@label ||= {})[::I18n.locale] ||= abstract_model.model.model_name.human(:default => abstract_model.model.model_name.demodulize.underscore.humanize)
|
57
60
|
end
|
58
61
|
|
59
|
-
register_instance_option
|
62
|
+
register_instance_option :label_plural do
|
60
63
|
(@label_plural ||= {})[::I18n.locale] ||= abstract_model.model.model_name.human(:count => 2, :default => label.pluralize)
|
61
64
|
end
|
62
65
|
|
63
|
-
register_instance_option
|
66
|
+
register_instance_option :weight do
|
64
67
|
0
|
65
68
|
end
|
66
69
|
|
67
|
-
|
68
|
-
|
70
|
+
# parent node in navigation/breadcrumb
|
71
|
+
register_instance_option :parent do
|
72
|
+
@parent_model ||= begin
|
73
|
+
(klass = abstract_model.model.superclass).to_s.in?(['Object', 'BasicObject', 'ActiveRecord::Base']) ? nil : klass
|
74
|
+
end
|
69
75
|
end
|
70
76
|
|
71
|
-
register_instance_option
|
72
|
-
|
77
|
+
register_instance_option :navigation_label do
|
78
|
+
@navigation_label ||= (parent_module = abstract_model.model.parent) != Object ? parent_module.to_s : nil
|
73
79
|
end
|
74
80
|
|
75
81
|
# Act as a proxy for the base section configuration that actually
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module RailsAdmin
|
2
|
+
module Config
|
3
|
+
module Proxyable
|
4
|
+
|
5
|
+
class Proxy
|
6
|
+
|
7
|
+
instance_methods.each {|m| undef_method m unless m =~ /^(__|instance_eval|object_id)/ }
|
8
|
+
|
9
|
+
attr_reader :bindings
|
10
|
+
|
11
|
+
def initialize(object, bindings = {})
|
12
|
+
@object = object
|
13
|
+
@bindings = bindings
|
14
|
+
end
|
15
|
+
|
16
|
+
# Bind variables to be used by the configuration options
|
17
|
+
def bind(key, value = nil)
|
18
|
+
if key.kind_of?(Hash)
|
19
|
+
@bindings = key
|
20
|
+
else
|
21
|
+
@bindings[key] = value
|
22
|
+
end
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def method_missing(name, *args, &block)
|
27
|
+
if @object.respond_to?(name)
|
28
|
+
reset = @object.instance_variable_get("@bindings")
|
29
|
+
begin
|
30
|
+
@object.instance_variable_set("@bindings", @bindings)
|
31
|
+
response = @object.__send__(name, *args, &block)
|
32
|
+
ensure
|
33
|
+
@object.instance_variable_set("@bindings", @reset)
|
34
|
+
end
|
35
|
+
response
|
36
|
+
else
|
37
|
+
super(name, *args, &block)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
require 'rails_admin/config/
|
1
|
+
require 'rails_admin/config/proxyable'
|
2
|
+
require 'rails_admin/config/configurable'
|
2
3
|
require 'rails_admin/config/has_fields'
|
3
4
|
require 'rails_admin/config/has_groups'
|
4
5
|
|
@@ -6,12 +7,21 @@ module RailsAdmin
|
|
6
7
|
module Config
|
7
8
|
module Sections
|
8
9
|
# Configuration of the show view for a new object
|
9
|
-
class Base
|
10
|
+
class Base
|
11
|
+
include RailsAdmin::Config::Proxyable
|
12
|
+
include RailsAdmin::Config::Configurable
|
13
|
+
|
10
14
|
include RailsAdmin::Config::HasFields
|
11
15
|
include RailsAdmin::Config::HasGroups
|
12
|
-
|
16
|
+
|
17
|
+
attr_reader :abstract_model
|
18
|
+
attr_reader :parent, :root
|
19
|
+
|
13
20
|
def initialize(parent)
|
14
|
-
|
21
|
+
@parent = parent
|
22
|
+
@root = parent.root
|
23
|
+
|
24
|
+
@abstract_model = root.abstract_model
|
15
25
|
end
|
16
26
|
end
|
17
27
|
end
|
data/lib/rails_admin/config.rb
CHANGED
@@ -19,7 +19,7 @@ module RailsAdmin
|
|
19
19
|
DEFAULT_ATTR_ACCESSIBLE_ROLE = Proc.new { :default }
|
20
20
|
|
21
21
|
DEFAULT_AUTHORIZE = Proc.new {}
|
22
|
-
|
22
|
+
|
23
23
|
DEFAULT_AUDIT = Proc.new {}
|
24
24
|
|
25
25
|
DEFAULT_CURRENT_USER = Proc.new do
|
@@ -99,7 +99,7 @@ module RailsAdmin
|
|
99
99
|
@attr_accessible_role = blk if blk
|
100
100
|
@attr_accessible_role || DEFAULT_ATTR_ACCESSIBLE_ROLE
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
# Setup auditing/history/versioning provider that observe objects lifecycle
|
104
104
|
def audit_with(*args, &block)
|
105
105
|
extension = args.shift
|
@@ -112,7 +112,7 @@ module RailsAdmin
|
|
112
112
|
end
|
113
113
|
@audit || DEFAULT_AUDIT
|
114
114
|
end
|
115
|
-
|
115
|
+
|
116
116
|
# Setup authorization to be run as a before filter
|
117
117
|
# This is run inside the controller instance so you can setup any authorization you need to.
|
118
118
|
#
|
@@ -191,6 +191,28 @@ module RailsAdmin
|
|
191
191
|
end
|
192
192
|
end
|
193
193
|
|
194
|
+
# pool of all found model names from the whole application
|
195
|
+
def models_pool
|
196
|
+
possible =
|
197
|
+
included_models.map(&:to_s).presence || (
|
198
|
+
@@system_models ||= # memoization for tests
|
199
|
+
([Rails.application] + Rails::Application::Railties.engines).map do |app|
|
200
|
+
(app.paths['app/models'] + app.config.autoload_paths).map do |load_path|
|
201
|
+
Dir.glob(app.root.join(load_path)).map do |load_dir|
|
202
|
+
Dir.glob(load_dir + "/**/*.rb").map do |filename|
|
203
|
+
# app/models/module/class.rb => module/class.rb => module/class => Module::Class
|
204
|
+
lchomp(filename, "#{app.root.join(load_dir)}/").chomp('.rb').camelize
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end.flatten
|
209
|
+
)
|
210
|
+
|
211
|
+
excluded = (excluded_models.map(&:to_s) + ['RailsAdmin::History'])
|
212
|
+
|
213
|
+
(possible - excluded).uniq.sort
|
214
|
+
end
|
215
|
+
|
194
216
|
# Loads a model configuration instance from the registry or registers
|
195
217
|
# a new one if one is yet to be added.
|
196
218
|
#
|
@@ -206,7 +228,7 @@ module RailsAdmin
|
|
206
228
|
def model(entity, &block)
|
207
229
|
key = begin
|
208
230
|
if entity.kind_of?(RailsAdmin::AbstractModel)
|
209
|
-
entity.model.name.to_sym
|
231
|
+
entity.model.try(:name).try :to_sym
|
210
232
|
elsif entity.kind_of?(Class)
|
211
233
|
entity.name.to_sym
|
212
234
|
elsif entity.kind_of?(String) || entity.kind_of?(Symbol)
|
@@ -219,7 +241,7 @@ module RailsAdmin
|
|
219
241
|
config.instance_eval(&block) if block
|
220
242
|
config
|
221
243
|
end
|
222
|
-
|
244
|
+
|
223
245
|
def default_hidden_fields=(fields)
|
224
246
|
if fields.is_a?(Array)
|
225
247
|
@default_hidden_fields = {}
|
@@ -229,12 +251,12 @@ module RailsAdmin
|
|
229
251
|
@default_hidden_fields = fields
|
230
252
|
end
|
231
253
|
end
|
232
|
-
|
254
|
+
|
233
255
|
# Returns action configuration object
|
234
256
|
def actions(&block)
|
235
257
|
RailsAdmin::Config::Actions.instance_eval(&block) if block
|
236
258
|
end
|
237
|
-
|
259
|
+
|
238
260
|
# Returns all model configurations
|
239
261
|
#
|
240
262
|
# If a block is given it is evaluated in the context of configuration
|
@@ -280,11 +302,18 @@ module RailsAdmin
|
|
280
302
|
# Get all models that are configured as visible sorted by their weight and label.
|
281
303
|
#
|
282
304
|
# @see RailsAdmin::Config::Hideable
|
283
|
-
|
284
|
-
|
305
|
+
|
306
|
+
def visible_models(bindings)
|
307
|
+
models.map{|m| m.with(bindings) }.select{|m| m.visible? && bindings[:controller].authorized?(:index, m.abstract_model)}.sort do |a, b|
|
285
308
|
(weight_order = a.weight <=> b.weight) == 0 ? a.label.downcase <=> b.label.downcase : weight_order
|
286
309
|
end
|
287
310
|
end
|
311
|
+
|
312
|
+
private
|
313
|
+
|
314
|
+
def lchomp(base, arg)
|
315
|
+
base.to_s.reverse.chomp(arg.to_s.reverse).reverse
|
316
|
+
end
|
288
317
|
end
|
289
318
|
|
290
319
|
# Set default values for configuration options on load
|
@@ -21,7 +21,7 @@ module RailsAdmin
|
|
21
21
|
if(configuration = options[:configuration])
|
22
22
|
CONFIGURATION_ADAPTERS[extension_key] = extension_definition::ConfigurationAdapter
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
if(configuration = options[:auditing])
|
26
26
|
AUDITING_ADAPTERS[extension_key] = extension_definition::AuditingAdapter
|
27
27
|
end
|
@@ -7,23 +7,23 @@ module RailsAdmin
|
|
7
7
|
@user_class = user_class
|
8
8
|
require 'rails_admin/extensions/history/history'
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def latest
|
12
12
|
::RailsAdmin::History.latest
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def delete_object(message, object, model, user)
|
16
16
|
::RailsAdmin::History.create_history_item(message, object, model, user)
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def update_object(model, object, associations_before, associations_after, modified_associations, old_object, user)
|
20
20
|
::RailsAdmin::History.create_update_history(model, object, associations_before, associations_after, modified_associations, old_object, user)
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def create_object(message, object, abstract_model, user)
|
24
24
|
::RailsAdmin::History.create_history_item(message, object, abstract_model, user)
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def listing_for_model(model, query, sort, sort_reverse, all, page, per_page = (RailsAdmin::Config.default_items_per_page || 20))
|
28
28
|
::RailsAdmin::History.history_for_model(model, query, sort, sort_reverse, all, page, per_page)
|
29
29
|
end
|
@@ -34,4 +34,4 @@ module RailsAdmin
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
37
|
-
end
|
37
|
+
end
|
@@ -6,28 +6,28 @@ module RailsAdmin
|
|
6
6
|
@version = version
|
7
7
|
@user_class = user_class
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def message
|
11
11
|
"#{@version.event} #{@version.item_type} id #{@version.item_id}"
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def created_at
|
15
15
|
@version.created_at
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def table
|
19
19
|
@version.item_type
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def username
|
23
23
|
@user_class.find_by_id(@version.whodunnit).try(:email) || @version.whodunnit
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def item
|
27
27
|
@version.item_id
|
28
28
|
end
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
class AuditingAdapter
|
32
32
|
COLUMN_MAPPING = {
|
33
33
|
:table => :item_type,
|
@@ -36,29 +36,29 @@ module RailsAdmin
|
|
36
36
|
:created_at => :created_at,
|
37
37
|
:message => :event
|
38
38
|
}
|
39
|
-
|
39
|
+
|
40
40
|
def initialize(controller, user_class = User)
|
41
41
|
raise "PaperTrail not found" unless defined?(PaperTrail)
|
42
42
|
@controller = controller
|
43
43
|
@user_class = user_class
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def latest
|
47
47
|
Version.limit(100).map{|version| VersionProxy.new(version, @user_class)}
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
def delete_object(message, object, model, user)
|
51
51
|
# do nothing
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def update_object(model, object, associations_before, associations_after, modified_associations, old_object, user)
|
55
55
|
# do nothing
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
def create_object(message, object, abstract_model, user)
|
59
59
|
# do nothing
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
def listing_for_model(model, query, sort, sort_reverse, all, page, per_page = (RailsAdmin::Config.default_items_per_page || 20))
|
63
63
|
if sort.present?
|
64
64
|
sort = COLUMN_MAPPING[sort.to_sym]
|
@@ -89,4 +89,4 @@ module RailsAdmin
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
92
|
-
end
|
92
|
+
end
|
@@ -13,17 +13,17 @@ module RailsAdmin
|
|
13
13
|
|
14
14
|
@model = objects.first.class
|
15
15
|
@abstract_model = RailsAdmin::AbstractModel.new(@model)
|
16
|
-
@model_config =
|
16
|
+
@model_config = @abstract_model.config
|
17
17
|
@methods = [(schema[:only] || []) + (schema[:methods] || [])].flatten.compact
|
18
18
|
@fields = @model_config.export.fields.select{|f| @methods.include? f.name }
|
19
19
|
@empty = ::I18n.t('admin.export.empty_value_for_associated_objects')
|
20
20
|
@associations = {}
|
21
21
|
|
22
22
|
(schema.delete(:include) || {}).each do |key, values|
|
23
|
-
association = @
|
24
|
-
|
25
|
-
abstract_model =
|
26
|
-
|
23
|
+
association = @model_config.export.fields.find{|f| f.name == key && f.association?}
|
24
|
+
model_config = association.associated_model_config
|
25
|
+
abstract_model = model_config.abstract_model
|
26
|
+
model = abstract_model.model
|
27
27
|
methods = [(values[:only] || []) + (values[:methods] || [])].flatten.compact
|
28
28
|
fields = model_config.export.fields.select{|f| methods.include? f.name }
|
29
29
|
|
@@ -65,7 +65,7 @@ module RailsAdmin
|
|
65
65
|
end +
|
66
66
|
@associations.map do |association_name, option_hash|
|
67
67
|
option_hash[:fields].map do |field|
|
68
|
-
output(::I18n.t('admin.export.csv.header_for_association_methods', :name => field.label, :association =>
|
68
|
+
output(::I18n.t('admin.export.csv.header_for_association_methods', :name => field.label, :association => option_hash[:association].label))
|
69
69
|
end
|
70
70
|
end.flatten
|
71
71
|
end
|
data/lib/rails_admin/version.rb
CHANGED