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
@@ -1,73 +1,56 @@
|
|
1
|
-
require 'active_support/core_ext/string/inflections'
|
2
|
-
require 'rails_admin/generic_support'
|
3
|
-
|
4
1
|
module RailsAdmin
|
5
2
|
class AbstractModel
|
6
|
-
cattr_accessor :
|
7
|
-
|
8
|
-
@@all_abstract_models = nil
|
9
|
-
# Returns all models for a given Rails app
|
3
|
+
cattr_accessor :all
|
4
|
+
attr_reader :adapter, :model_name
|
10
5
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
6
|
+
class << self
|
7
|
+
def reset
|
8
|
+
@@all = nil
|
9
|
+
end
|
15
10
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
Dir.glob(app.root.join(load_path)).map do |load_dir|
|
21
|
-
Dir.glob(load_dir + "/**/*.rb").map do |filename|
|
22
|
-
lchomp(filename, "#{app.root.join(load_dir)}/").chomp('.rb').camelize # app/models/module/class.rb => module/class.rb => module/class => Module::Class
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end.flatten
|
27
|
-
excluded_models = (RailsAdmin::Config.excluded_models.map(&:to_s) + ['RailsAdmin::History'])
|
28
|
-
(possible_models - excluded_models).uniq.sort{|x, y| x.to_s <=> y.to_s}.map{|model| lookup(model) }.compact
|
29
|
-
)
|
30
|
-
end
|
11
|
+
def all(adapter = nil)
|
12
|
+
@@all ||= Config.models_pool.map{ |m| new(m) }.compact
|
13
|
+
adapter ? @@all.select{|m| m.adapter == adapter} : @@all
|
14
|
+
end
|
31
15
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
else
|
16
|
+
alias_method :old_new, :new
|
17
|
+
def new(m)
|
18
|
+
m = m.is_a?(Class) ? m : m.constantize
|
19
|
+
(am = old_new(m)).model && am.adapter ? am : nil
|
20
|
+
rescue LoadError, NameError
|
38
21
|
nil
|
39
22
|
end
|
40
|
-
rescue LoadError
|
41
|
-
Rails.logger.error "Error while loading '#{model_name}': #{$!}"
|
42
|
-
nil
|
43
23
|
end
|
44
24
|
|
45
|
-
def initialize(
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
25
|
+
def initialize(m)
|
26
|
+
@model_name = m.to_s
|
27
|
+
# ActiveRecord
|
28
|
+
if m.ancestors.map(&:to_s).include?('ActiveRecord::Base') && !m.abstract_class?
|
29
|
+
@adapter = :active_record
|
30
|
+
require 'rails_admin/adapters/active_record'
|
31
|
+
extend Adapters::ActiveRecord
|
32
|
+
end
|
52
33
|
end
|
53
34
|
|
35
|
+
# do not store a reference to the model, does not play well with ActiveReload/Rails3.2
|
54
36
|
def model
|
55
|
-
@model_name.constantize
|
37
|
+
@model_name.try :constantize
|
56
38
|
end
|
57
39
|
|
58
|
-
|
40
|
+
def config
|
41
|
+
Config.model self
|
42
|
+
end
|
59
43
|
|
60
|
-
def
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
superclasses
|
44
|
+
def to_param
|
45
|
+
model.to_s.split("::").map(&:underscore).join("~")
|
46
|
+
end
|
47
|
+
|
48
|
+
def param_key
|
49
|
+
model.to_s.split("::").map(&:underscore).join("_")
|
67
50
|
end
|
68
51
|
|
69
|
-
def
|
70
|
-
|
52
|
+
def pretty_name
|
53
|
+
model.model_name.human
|
71
54
|
end
|
72
55
|
end
|
73
56
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module RailsAdmin
|
2
|
+
module Adapters
|
3
|
+
module ActiveRecord
|
4
|
+
class AbstractObject
|
5
|
+
# undef almost all of this class's methods so it will pass almost
|
6
|
+
# everything through to its delegate using method_missing (below).
|
7
|
+
instance_methods.each { |m| undef_method m unless m.to_s =~ /(^__|^send$|^object_id$)/ }
|
8
|
+
# ^^^^^
|
9
|
+
# the unnecessary "to_s" above is a workaround for meta_where, see
|
10
|
+
# https://github.com/sferik/rails_admin/issues/374
|
11
|
+
|
12
|
+
attr_accessor :object
|
13
|
+
|
14
|
+
def initialize(object)
|
15
|
+
self.object = object
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_attributes(attributes, role = nil)
|
19
|
+
object.assign_attributes(attributes, :as => role)
|
20
|
+
end
|
21
|
+
|
22
|
+
def save(options = { :validate => true })
|
23
|
+
object.save(options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def method_missing(name, *args, &block)
|
27
|
+
self.object.send(name, *args, &block)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -1,34 +1,26 @@
|
|
1
1
|
require 'active_record'
|
2
|
-
require 'rails_admin/
|
3
|
-
require 'rails_admin/abstract_object'
|
2
|
+
require 'rails_admin/adapters/active_record/abstract_object'
|
4
3
|
|
5
4
|
module RailsAdmin
|
6
5
|
module Adapters
|
7
6
|
module ActiveRecord
|
8
|
-
DISABLED_COLUMN_TYPES = [:tsvector, :blob, :binary]
|
9
|
-
|
7
|
+
DISABLED_COLUMN_TYPES = [:tsvector, :blob, :binary, :spatial]
|
8
|
+
LIKE_OPERATOR = ::ActiveRecord::Base.configurations[Rails.env]['adapter'] == "postgresql" ? 'ILIKE' : 'LIKE'
|
10
9
|
|
11
|
-
def
|
12
|
-
|
13
|
-
RailsAdmin::AbstractModel.all_models.each do |klass|
|
14
|
-
klass.reflect_on_all_associations.select{|r| r.options[:as] }.each do |reflection|
|
15
|
-
(hash[reflection.options[:as].to_sym] ||= []) << klass
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
@@polymorphic_parents[name.to_sym]
|
10
|
+
def new(params = {})
|
11
|
+
AbstractObject.new(model.new(params))
|
20
12
|
end
|
21
13
|
|
22
14
|
def get(id)
|
23
15
|
if object = model.where(model.primary_key => id).first
|
24
|
-
|
16
|
+
AbstractObject.new object
|
25
17
|
else
|
26
18
|
nil
|
27
19
|
end
|
28
20
|
end
|
29
21
|
|
30
|
-
def
|
31
|
-
|
22
|
+
def scoped
|
23
|
+
model.scoped
|
32
24
|
end
|
33
25
|
|
34
26
|
def first(options = {}, scope = nil)
|
@@ -40,56 +32,19 @@ module RailsAdmin
|
|
40
32
|
scope = scope.includes(options[:include]) if options[:include]
|
41
33
|
scope = scope.limit(options[:limit]) if options[:limit]
|
42
34
|
scope = scope.where(model.primary_key => options[:bulk_ids]) if options[:bulk_ids]
|
43
|
-
scope = scope.where(options[:
|
35
|
+
scope = scope.where(query_conditions(options[:query])) if options[:query]
|
36
|
+
scope = scope.where(filter_conditions(options[:filters])) if options[:filters]
|
44
37
|
scope = scope.page(options[:page]).per(options[:per]) if options[:page] && options[:per]
|
45
38
|
scope = scope.reorder("#{options[:sort]} #{options[:sort_reverse] ? 'asc' : 'desc'}") if options[:sort]
|
46
39
|
scope
|
47
40
|
end
|
48
41
|
|
49
|
-
def
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
def create(params = {})
|
54
|
-
model.create(params)
|
55
|
-
end
|
56
|
-
|
57
|
-
def new(params = {})
|
58
|
-
RailsAdmin::AbstractObject.new(model.new(params))
|
42
|
+
def count(options = {}, scope = nil)
|
43
|
+
all(options.merge({:limit => false, :page => false}), scope).count
|
59
44
|
end
|
60
45
|
|
61
46
|
def destroy(objects)
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
def destroy_all!
|
66
|
-
model.all.each do |object|
|
67
|
-
object.destroy
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def has_and_belongs_to_many_associations
|
72
|
-
associations.select do |association|
|
73
|
-
association[:type] == :has_and_belongs_to_many
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def has_many_associations
|
78
|
-
associations.select do |association|
|
79
|
-
association[:type] == :has_many
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def has_one_associations
|
84
|
-
associations.select do |association|
|
85
|
-
association[:type] == :has_one
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def belongs_to_associations
|
90
|
-
associations.select do |association|
|
91
|
-
association[:type] == :belongs_to
|
92
|
-
end
|
47
|
+
Array.wrap(objects).each &:destroy
|
93
48
|
end
|
94
49
|
|
95
50
|
def associations
|
@@ -98,9 +53,9 @@ module RailsAdmin
|
|
98
53
|
:name => association.name.to_sym,
|
99
54
|
:pretty_name => association.name.to_s.tr('_', ' ').capitalize,
|
100
55
|
:type => association.macro,
|
101
|
-
:
|
56
|
+
:parent_model_proc => Proc.new { association_parent_model_lookup(association) },
|
102
57
|
:parent_key => association_parent_key_lookup(association),
|
103
|
-
:
|
58
|
+
:child_model_proc => Proc.new { association_child_model_lookup(association) },
|
104
59
|
:child_key => association_child_key_lookup(association),
|
105
60
|
:foreign_type => association_foreign_type_lookup(association),
|
106
61
|
:as => association_as_lookup(association),
|
@@ -112,12 +67,6 @@ module RailsAdmin
|
|
112
67
|
end
|
113
68
|
end
|
114
69
|
|
115
|
-
def polymorphic_associations
|
116
|
-
(has_many_associations + has_one_associations).select do |association|
|
117
|
-
association[:options][:as]
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
70
|
def properties
|
122
71
|
columns = model.columns.reject {|c| c.type.blank? || DISABLED_COLUMN_TYPES.include?(c.type.to_sym) }
|
123
72
|
columns.map do |property|
|
@@ -132,68 +81,47 @@ module RailsAdmin
|
|
132
81
|
end
|
133
82
|
end
|
134
83
|
|
135
|
-
|
136
|
-
model.table_exists?
|
137
|
-
end
|
84
|
+
private
|
138
85
|
|
139
|
-
def
|
140
|
-
|
141
|
-
@like_operator ||= "LIKE"
|
142
|
-
|
143
|
-
query_statements = []
|
144
|
-
filters_statements = []
|
86
|
+
def query_conditions(query, fields = config.list.fields.select(&:queryable?))
|
87
|
+
statements = []
|
145
88
|
values = []
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
statement, value1, value2 = build_statement(field_infos[:column], field_infos[:type], query, field.search_operator)
|
154
|
-
if statement
|
155
|
-
query_statements << statement
|
156
|
-
values << value1 unless value1.nil?
|
157
|
-
values << value2 unless value2.nil?
|
158
|
-
end
|
159
|
-
end
|
89
|
+
|
90
|
+
fields.each do |field|
|
91
|
+
field.searchable_columns.flatten.each do |column_infos|
|
92
|
+
statement, value1, value2 = build_statement(column_infos[:column], column_infos[:type], query, field.search_operator)
|
93
|
+
statements << statement if statement
|
94
|
+
values << value1 unless value1.nil?
|
95
|
+
values << value2 unless value2.nil?
|
160
96
|
end
|
161
97
|
end
|
162
98
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
99
|
+
[statements.join(' OR '), *values]
|
100
|
+
end
|
101
|
+
|
102
|
+
# filters example => {"string_field"=>{"0055"=>{"o"=>"like", "v"=>"test_value"}}, ...}
|
103
|
+
# "0055" is the filter index, no use here. o is the operator, v the value
|
104
|
+
def filter_conditions(filters, fields = config.list.fields.select(&:filterable?))
|
105
|
+
statements = []
|
106
|
+
values = []
|
167
107
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
field_statements << statement
|
177
|
-
values << value1 unless value1.nil?
|
178
|
-
values << value2 unless value2.nil?
|
179
|
-
end
|
180
|
-
end
|
181
|
-
filters_statements << "(#{field_statements.join(' OR ')})" unless field_statements.empty?
|
108
|
+
filters.each_pair do |field_name, filters_dump|
|
109
|
+
filters_dump.each do |filter_index, filter_dump|
|
110
|
+
field_statements = []
|
111
|
+
fields.find{|f| f.name.to_s == field_name}.searchable_columns.each do |column_infos|
|
112
|
+
statement, value1, value2 = build_statement(column_infos[:column], column_infos[:type], filter_dump[:v], (filter_dump[:o] || 'default'))
|
113
|
+
field_statements << statement if statement.present?
|
114
|
+
values << value1 unless value1.nil?
|
115
|
+
values << value2 unless value2.nil?
|
182
116
|
end
|
117
|
+
statements << "(#{field_statements.join(' OR ')})" unless field_statements.empty?
|
183
118
|
end
|
184
119
|
end
|
185
120
|
|
186
|
-
|
187
|
-
conditions[0] += " AND " unless conditions == [""]
|
188
|
-
conditions[0] += "#{filters_statements.join(" AND ")}" # filters should all be true
|
189
|
-
end
|
190
|
-
|
191
|
-
conditions += values
|
192
|
-
conditions != [""] ? { :conditions => conditions } : {}
|
121
|
+
[statements.join(' AND '), *values]
|
193
122
|
end
|
194
123
|
|
195
124
|
def build_statement(column, type, value, operator)
|
196
|
-
|
197
125
|
# this operator/value has been discarded (but kept in the dom to override the one stored in the various links of the page)
|
198
126
|
return if operator == '_discard' || value == '_discard'
|
199
127
|
|
@@ -232,7 +160,7 @@ module RailsAdmin
|
|
232
160
|
when 'is', '='
|
233
161
|
"#{value}"
|
234
162
|
end
|
235
|
-
["(#{column} #{
|
163
|
+
["(#{column} #{LIKE_OPERATOR} ?)", value]
|
236
164
|
when :datetime, :timestamp, :date
|
237
165
|
return unless operator != 'default'
|
238
166
|
values = case operator
|
@@ -257,23 +185,21 @@ module RailsAdmin
|
|
257
185
|
["(#{column} BETWEEN ? AND ?)", *values]
|
258
186
|
when :enum
|
259
187
|
return if value.blank?
|
260
|
-
["(#{column} IN (?))",
|
188
|
+
["(#{column} IN (?))", Array.wrap(value)]
|
261
189
|
end
|
262
190
|
end
|
263
191
|
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
}
|
274
|
-
else
|
275
|
-
{}
|
192
|
+
@@polymorphic_parents = nil
|
193
|
+
|
194
|
+
def self.polymorphic_parents(name)
|
195
|
+
@@polymorphic_parents ||= {}.tap do |hash|
|
196
|
+
RailsAdmin::AbstractModel.all(:active_record).each do |am|
|
197
|
+
am.model.reflect_on_all_associations.select{|r| r.options[:as] }.each do |reflection|
|
198
|
+
(hash[reflection.options[:as].to_sym] ||= []) << am.model
|
199
|
+
end
|
200
|
+
end
|
276
201
|
end
|
202
|
+
@@polymorphic_parents[name.to_sym]
|
277
203
|
end
|
278
204
|
|
279
205
|
def association_parent_model_lookup(association)
|
@@ -333,14 +259,7 @@ module RailsAdmin
|
|
333
259
|
end
|
334
260
|
|
335
261
|
def association_child_key_lookup(association)
|
336
|
-
|
337
|
-
when :belongs_to
|
338
|
-
association.options[:foreign_key].try(:to_sym) || "#{association.name}_id".to_sym
|
339
|
-
when :has_one, :has_many, :has_and_belongs_to_many
|
340
|
-
association.foreign_key.to_sym
|
341
|
-
else
|
342
|
-
raise "Unknown association type: #{association.macro.inspect}"
|
343
|
-
end
|
262
|
+
association.foreign_key.to_sym
|
344
263
|
end
|
345
264
|
end
|
346
265
|
end
|
@@ -1,101 +1,113 @@
|
|
1
|
-
require 'rails_admin/config/
|
1
|
+
require 'rails_admin/config/proxyable'
|
2
|
+
require 'rails_admin/config/configurable'
|
2
3
|
require 'rails_admin/config/hideable'
|
3
4
|
|
4
5
|
module RailsAdmin
|
5
6
|
module Config
|
6
7
|
module Actions
|
7
|
-
class Base
|
8
|
+
class Base
|
9
|
+
include RailsAdmin::Config::Proxyable
|
10
|
+
include RailsAdmin::Config::Configurable
|
8
11
|
include RailsAdmin::Config::Hideable
|
9
|
-
|
12
|
+
|
13
|
+
# http://twitter.github.com/bootstrap/base-css.html#icons
|
14
|
+
register_instance_option :link_icon do
|
15
|
+
'icon-question-sign'
|
16
|
+
end
|
17
|
+
|
10
18
|
# Should the action be visible
|
11
19
|
register_instance_option :visible? do
|
12
|
-
true
|
20
|
+
authorized? && (bindings[:abstract_model] ? bindings[:abstract_model].config.with(bindings).try(:visible?) : true)
|
13
21
|
end
|
14
|
-
|
22
|
+
|
23
|
+
register_instance_option :authorized? do
|
24
|
+
bindings[:controller] ? bindings[:controller].authorized?(self.authorization_key, bindings[:abstract_model], bindings[:object]) : true
|
25
|
+
end
|
26
|
+
|
15
27
|
# Is the action acting on the root level (Example: /admin/contact)
|
16
28
|
register_instance_option :root? do
|
17
29
|
false
|
18
30
|
end
|
19
|
-
|
20
|
-
# Is the action on a model scope (Example: /admin/
|
31
|
+
|
32
|
+
# Is the action on a model scope (Example: /admin/team/export)
|
21
33
|
register_instance_option :collection? do
|
22
34
|
false
|
23
35
|
end
|
24
|
-
|
25
|
-
# Is the action on an object scope (Example: /admin/
|
36
|
+
|
37
|
+
# Is the action on an object scope (Example: /admin/team/1/edit)
|
26
38
|
register_instance_option :member? do
|
27
39
|
false
|
28
40
|
end
|
29
|
-
|
41
|
+
|
30
42
|
# This block is evaluated in the context of the controller when action is called
|
31
43
|
# You can access:
|
32
|
-
# - @
|
44
|
+
# - @objects if you're on a model scope
|
45
|
+
# - @abstract_model & @model_config if you're on a model or object scope
|
33
46
|
# - @object if you're on an object scope
|
34
47
|
register_instance_option :controller do
|
35
48
|
Proc.new do
|
36
49
|
render :action => @action.template_name
|
37
50
|
end
|
38
51
|
end
|
39
|
-
|
52
|
+
|
40
53
|
# Model scoped actions only. You will need to handle params[:bulk_ids] in controller
|
41
54
|
register_instance_option :bulkable? do
|
42
55
|
false
|
43
56
|
end
|
44
|
-
|
57
|
+
|
45
58
|
# View partial name (called in default :controller block)
|
46
59
|
register_instance_option :template_name do
|
47
60
|
key.to_sym
|
48
61
|
end
|
49
|
-
|
62
|
+
|
50
63
|
# For Cancan and the like
|
51
64
|
register_instance_option :authorization_key do
|
52
65
|
key.to_sym
|
53
66
|
end
|
54
|
-
|
67
|
+
|
55
68
|
# List of methods allowed. Note that you are responsible for correctly handling them in :controller block
|
56
69
|
register_instance_option :http_methods do
|
57
70
|
[:get]
|
58
71
|
end
|
59
|
-
|
72
|
+
|
60
73
|
# Url fragment
|
61
74
|
register_instance_option :route_fragment do
|
62
75
|
custom_key.to_s
|
63
76
|
end
|
64
|
-
|
77
|
+
|
65
78
|
# Controller action name
|
66
79
|
register_instance_option :action_name do
|
67
80
|
custom_key.to_sym
|
68
81
|
end
|
69
|
-
|
82
|
+
|
70
83
|
# I18n key
|
71
84
|
register_instance_option :i18n_key do
|
72
85
|
key
|
73
86
|
end
|
74
|
-
|
87
|
+
|
75
88
|
# User should override only custom_key (action name and route fragment change, allows for duplicate actions)
|
76
89
|
register_instance_option :custom_key do
|
77
90
|
key
|
78
91
|
end
|
79
|
-
|
92
|
+
|
80
93
|
# Breadcrumb parent
|
81
94
|
register_instance_option :breadcrumb_parent do
|
82
|
-
case
|
95
|
+
case
|
83
96
|
when root?
|
84
|
-
:dashboard
|
97
|
+
[:dashboard]
|
85
98
|
when collection?
|
86
|
-
:index
|
99
|
+
[:index, bindings[:abstract_model]]
|
87
100
|
when member?
|
88
|
-
:show
|
101
|
+
[:show, bindings[:abstract_model], bindings[:object]]
|
89
102
|
end
|
90
103
|
end
|
91
|
-
|
92
|
-
|
104
|
+
|
93
105
|
# Off API.
|
94
|
-
|
106
|
+
|
95
107
|
def key
|
96
108
|
self.class.key
|
97
109
|
end
|
98
|
-
|
110
|
+
|
99
111
|
def self.key
|
100
112
|
self.name.to_s.demodulize.underscore.to_sym
|
101
113
|
end
|
@@ -3,50 +3,49 @@ module RailsAdmin
|
|
3
3
|
module Actions
|
4
4
|
class BulkDelete < RailsAdmin::Config::Actions::Base
|
5
5
|
RailsAdmin::Config::Actions.register(self)
|
6
|
-
|
6
|
+
|
7
7
|
register_instance_option :collection do
|
8
8
|
true
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
register_instance_option :http_methods do
|
12
12
|
[:post, :delete]
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
register_instance_option :controller do
|
16
16
|
Proc.new do
|
17
17
|
|
18
18
|
if request.post? # BULK DELETE
|
19
|
-
|
19
|
+
|
20
20
|
@objects = list_entries(@model_config, :destroy)
|
21
|
-
not_found and return if @objects.empty?
|
22
21
|
|
23
22
|
render @action.template_name
|
24
23
|
|
25
24
|
elsif request.delete? # BULK DESTROY
|
26
|
-
|
25
|
+
|
27
26
|
@objects = list_entries(@model_config, :destroy)
|
28
27
|
processed_objects = @abstract_model.destroy(@objects)
|
29
28
|
|
30
29
|
destroyed = processed_objects.select(&:destroyed?)
|
31
30
|
not_destroyed = processed_objects - destroyed
|
32
|
-
|
31
|
+
|
33
32
|
destroyed.each do |object|
|
34
33
|
@auditing_adapter && @auditing_adapter.delete_object("Destroyed #{@model_config.with(:object => object).object_label}", object, @abstract_model, _current_user)
|
35
|
-
end
|
34
|
+
end
|
36
35
|
|
37
36
|
flash[:success] = t("admin.flash.successful", :name => pluralize(destroyed.count, @model_config.label), :action => t("admin.actions.delete.done")) unless destroyed.empty?
|
38
37
|
flash[:error] = t("admin.flash.error", :name => pluralize(not_destroyed.count, @model_config.label), :action => t("admin.actions.delete.done")) unless not_destroyed.empty?
|
39
38
|
|
40
39
|
redirect_to back_or_index
|
41
|
-
|
40
|
+
|
42
41
|
end
|
43
42
|
end
|
44
43
|
end
|
45
|
-
|
44
|
+
|
46
45
|
register_instance_option :authorization_key do
|
47
46
|
:destroy
|
48
47
|
end
|
49
|
-
|
48
|
+
|
50
49
|
register_instance_option :bulkable? do
|
51
50
|
true
|
52
51
|
end
|
@@ -3,19 +3,19 @@ module RailsAdmin
|
|
3
3
|
module Actions
|
4
4
|
class Dashboard < RailsAdmin::Config::Actions::Base
|
5
5
|
RailsAdmin::Config::Actions.register(self)
|
6
|
-
|
6
|
+
|
7
7
|
register_instance_option :root? do
|
8
8
|
true
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
register_instance_option :breadcrumb_parent do
|
12
12
|
nil
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
register_instance_option :controller do
|
16
16
|
Proc.new do
|
17
17
|
@history = @auditing_adapter && @auditing_adapter.latest || []
|
18
|
-
@abstract_models = RailsAdmin::Config.visible_models.map(&:abstract_model)
|
18
|
+
@abstract_models = RailsAdmin::Config.visible_models(:controller => self).map(&:abstract_model)
|
19
19
|
|
20
20
|
@most_recent_changes = {}
|
21
21
|
@count = {}
|
@@ -30,10 +30,14 @@ module RailsAdmin
|
|
30
30
|
render @action.template_name, :status => (flash[:error].present? ? :not_found : 200)
|
31
31
|
end
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
register_instance_option :route_fragment do
|
35
35
|
''
|
36
36
|
end
|
37
|
+
|
38
|
+
register_instance_option :link_icon do
|
39
|
+
'icon-home'
|
40
|
+
end
|
37
41
|
end
|
38
42
|
end
|
39
43
|
end
|