rails_admin 0.0.5 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. data/Gemfile +5 -30
  2. data/README.md +20 -2
  3. data/app/assets/javascripts/rails_admin/ra.filtering-select.js +2 -2
  4. data/app/assets/javascripts/rails_admin/ra.nested-form-hooks.coffee +1 -1
  5. data/app/assets/javascripts/rails_admin/ra.remote-form.js +1 -1
  6. data/app/assets/javascripts/rails_admin/ra.widgets.coffee +43 -3
  7. data/app/assets/javascripts/rails_admin/ui.js.coffee +2 -0
  8. data/app/assets/stylesheets/rails_admin/imports.css.scss.erb +3 -0
  9. data/app/assets/stylesheets/rails_admin/ra.widgets.css.scss +8 -0
  10. data/app/controllers/rails_admin/main_controller.rb +3 -3
  11. data/app/helpers/rails_admin/application_helper.rb +15 -4
  12. data/app/helpers/rails_admin/form_builder.rb +35 -35
  13. data/app/views/layouts/rails_admin/application.html.haml +2 -1
  14. data/app/views/rails_admin/main/_delete_notice.html.haml +9 -8
  15. data/app/views/rails_admin/main/_form_datetime.html.haml +1 -1
  16. data/app/views/rails_admin/main/_form_enumeration.html.haml +18 -1
  17. data/app/views/rails_admin/main/_form_file_upload.html.haml +2 -2
  18. data/app/views/rails_admin/main/_form_text.html.haml +7 -1
  19. data/app/views/rails_admin/main/dashboard.html.haml +26 -25
  20. data/app/views/rails_admin/main/index.html.haml +1 -1
  21. data/config/initializers/active_record_extensions.rb +2 -2
  22. data/config/locales/rails_admin.en.yml +1 -0
  23. data/lib/generators/rails_admin/install_generator.rb +1 -1
  24. data/lib/generators/rails_admin/templates/initializer.erb +66 -67
  25. data/lib/rails_admin/abstract_model.rb +7 -7
  26. data/lib/rails_admin/adapters/active_record.rb +17 -8
  27. data/lib/rails_admin/adapters/mongoid.rb +38 -42
  28. data/lib/rails_admin/adapters/mongoid/extension.rb +1 -1
  29. data/lib/rails_admin/config.rb +15 -1
  30. data/lib/rails_admin/config/actions/base.rb +16 -2
  31. data/lib/rails_admin/config/actions/dashboard.rb +17 -11
  32. data/lib/rails_admin/config/fields.rb +0 -1
  33. data/lib/rails_admin/config/fields/association.rb +2 -3
  34. data/lib/rails_admin/config/fields/base.rb +18 -6
  35. data/lib/rails_admin/config/fields/types/enum.rb +4 -0
  36. data/lib/rails_admin/config/fields/types/string.rb +6 -4
  37. data/lib/rails_admin/config/fields/types/text.rb +19 -2
  38. data/lib/rails_admin/config/model.rb +17 -0
  39. data/lib/rails_admin/config/sections/base.rb +17 -0
  40. data/lib/rails_admin/engine.rb +4 -0
  41. data/lib/rails_admin/extensions/history/auditing_adapter.rb +1 -1
  42. data/lib/rails_admin/extensions/paper_trail/auditing_adapter.rb +4 -4
  43. data/lib/rails_admin/support/csv_converter.rb +3 -3
  44. data/lib/rails_admin/version.rb +2 -2
  45. data/lib/tasks/rails_admin.rake +36 -6
  46. data/spec/controllers/main_controller_spec.rb +52 -9
  47. data/spec/dummy_app/Gemfile +7 -16
  48. data/spec/dummy_app/app/active_record/another_field_test.rb +4 -0
  49. data/spec/dummy_app/app/active_record/ball.rb +1 -1
  50. data/spec/dummy_app/app/active_record/nested_field_test.rb +2 -1
  51. data/spec/dummy_app/app/active_record/team.rb +3 -2
  52. data/spec/dummy_app/app/active_record/user.rb +6 -2
  53. data/spec/dummy_app/app/mongoid/another_field_test.rb +6 -0
  54. data/spec/dummy_app/app/mongoid/ball.rb +1 -1
  55. data/spec/dummy_app/app/mongoid/nested_field_test.rb +2 -1
  56. data/spec/dummy_app/app/mongoid/team.rb +1 -1
  57. data/spec/dummy_app/config/environments/development.rb +2 -2
  58. data/spec/dummy_app/db/migrate/20120720075608_create_another_field_tests.rb +8 -0
  59. data/spec/dummy_app/db/seeds.rb +3 -3
  60. data/spec/dummy_app/db/test.sqlite3 +0 -0
  61. data/spec/dummy_app/log/test.log +53792 -0
  62. data/spec/helpers/application_helper_spec.rb +37 -0
  63. data/spec/helpers/form_builder_spec.rb +17 -0
  64. data/spec/integration/authorization/cancan_spec.rb +21 -13
  65. data/spec/integration/basic/create/rails_admin_namespaced_model_create_spec.rb +1 -8
  66. data/spec/integration/basic/delete/rails_admin_basic_delete_spec.rb +15 -4
  67. data/spec/integration/basic/list/rails_admin_basic_list_spec.rb +9 -12
  68. data/spec/integration/basic/show/rails_admin_basic_show_spec.rb +2 -10
  69. data/spec/integration/basic/update/rails_admin_basic_update_spec.rb +6 -0
  70. data/spec/integration/config/edit/rails_admin_config_edit_spec.rb +241 -300
  71. data/spec/integration/config/list/rails_admin_config_list_spec.rb +3 -81
  72. data/spec/integration/config/show/rails_admin_config_show_spec.rb +2 -2
  73. data/spec/spec_helper.rb +1 -0
  74. data/spec/unit/active_record_extension_spec.rb +16 -0
  75. data/spec/unit/adapters/active_record_spec.rb +11 -9
  76. data/spec/unit/adapters/mongoid_spec.rb +4 -4
  77. data/spec/unit/config/actions/base_spec.rb +32 -0
  78. data/spec/unit/config/fields/base_spec.rb +56 -0
  79. data/spec/unit/config/fields/date_spec.rb +53 -0
  80. data/spec/unit/config/fields/datetime_spec.rb +55 -0
  81. data/spec/unit/config/fields/time_spec.rb +39 -0
  82. data/spec/unit/config/fields/timestamp_spec.rb +20 -0
  83. data/spec/unit/config_spec.rb +1 -1
  84. data/spec/unit/support/csv_converter_spec.rb +16 -0
  85. metadata +44 -35
  86. data/lib/rails_admin/config/fields/factories/serialized.rb +0 -17
  87. data/lib/tasks/prepare_ci_env.rake +0 -27
@@ -21,6 +21,7 @@
21
21
  .span3
22
22
  .well.sidebar-nav
23
23
  %ul.nav.nav-list= main_navigation
24
+ %ul.nav.nav-list= static_navigation
24
25
  .span9
25
26
  .row-fluid
26
- .content{:'data-pjax-container' => true}= render :template => 'layouts/rails_admin/pjax'
27
+ .content{:'data-pjax-container' => true}= render :template => 'layouts/rails_admin/pjax'
@@ -1,18 +1,19 @@
1
1
  - object = delete_notice
2
- - show_enabled = RailsAdmin::Config::Actions.all.map(&:key).include?(:show)
3
2
 
4
3
  %li{:style => 'display:block; margin-top:10px'}
5
4
  %span.label= @abstract_model.pretty_name
6
- - if show_enabled
7
- = link_to @model_config.with(:object => object).object_label, show_path(:model_name => @abstract_model.to_param, :id => object.id)
5
+ - wording = object.send(@model_config.object_label_method)
6
+ - if show_action = action(:show, @abstract_model, object)
7
+ = link_to(wording, url_for(:action => show_action.action_name, :model_name => @abstract_model.to_param, :id => object.id), :class => 'pjax')
8
8
  - else
9
- = @model_config.with(:object => object).object_label
9
+ = wording
10
10
  %ul
11
11
  - @abstract_model.each_associated_children(object) do |association, child|
12
12
  %li
13
13
  - child_config = RailsAdmin.config(child)
14
- = association[:pretty_name]
15
- - if show_enabled
16
- = link_to(child_config.with(:object => child).object_label, show_path(:model_name => child_config.abstract_model.to_param, :id => child.id))
14
+ = @abstract_model.model.human_attribute_name association[:name]
15
+ - wording = child.send(child_config.object_label_method)
16
+ - if child.id && (show_action = action(:show, child_config.abstract_model, child))
17
+ = link_to(wording, url_for(:action => show_action.action_name, :model_name => child_config.abstract_model.to_param, :id => child.id), :class => 'pjax')
17
18
  - else
18
- = child_config.with(:object => child).object_label
19
+ = wording
@@ -1 +1 @@
1
- = form.send field.view_helper, field.method_name, field.html_attributes.reverse_merge({ :data => { :datetimepicker => true, :options => field.js_plugin_options.to_json } }).reverse_merge((hdv = field.html_default_value).nil? ? {} : { :value => hdv })
1
+ = form.send field.view_helper, field.method_name, field.html_attributes.merge({:value => (field.value.present? ? field.value : field.html_default_value)}).reverse_merge({ :data => { :datetimepicker => true, :options => field.js_plugin_options.to_json } })
@@ -1 +1,18 @@
1
- = form.select field.method_name, field.enum, { :include_blank => true }.reverse_merge((hdv = field.html_default_value).nil? ? {} : { :selected => hdv }), field.html_attributes.reverse_merge({ :data => { :enumeration => true }, :placeholder => t('admin.misc.search') })
1
+ - unless field.multiple?
2
+ = form.select field.method_name, field.enum, { :include_blank => true }.reverse_merge((hdv = field.html_default_value).nil? ? {} : { :selected => hdv }), field.html_attributes.reverse_merge({ :data => { :enumeration => true }, :placeholder => t('admin.misc.search') })
3
+ - else
4
+ :ruby
5
+ js_data = {
6
+ :xhr => false,
7
+ :sortable => false,
8
+ :cacheAll => true,
9
+ :regional => {
10
+ :chooseAll => t("admin.misc.chose_all"),
11
+ :chosen => t("admin.misc.chosen", :name => config.label_plural),
12
+ :clearAll => t("admin.misc.clear_all"),
13
+ :search => t("admin.misc.search"),
14
+ :up => t("admin.misc.up"),
15
+ :down => t("admin.misc.down")
16
+ }
17
+ }
18
+ = form.select field.method_name, field.enum, { :selected => field.value, :object => form.object }, field.html_attributes.reverse_merge({:data => { :filteringmultiselect => true, :options => js_data.to_json }, :multiple => true})
@@ -3,11 +3,11 @@
3
3
  .toggle{:style => ('display:none;' if file && field.delete_method && form.object.send(field.delete_method) == '1')}
4
4
  - if value = field.pretty_value
5
5
  = value
6
- = form.file_field(field.name, field.html_attributes.reverse_merge({ :data => { :fileupload => true } }))
6
+ = form.file_field(field.name, field.html_attributes.reverse_merge({ :data => { :fileupload => true }}))
7
7
  - if field.optional? && field.errors.blank? && file && field.delete_method
8
8
  %a.btn.btn-info{:href => '#', :'data-toggle' => 'button', :onclick => "$(this).siblings('[type=checkbox]').click(); $(this).siblings('.toggle').toggle('slow'); jQuery(this).toggleClass('btn-danger btn-info'); return false"}
9
9
  %i.icon-white.icon-trash
10
- = I18n.t('admin.actions.delete.menu').capitalize + " #{field.method_name}"
10
+ = I18n.t('admin.actions.delete.menu').capitalize + " #{field.label.downcase}"
11
11
  = form.check_box(field.delete_method, :style => 'display:none;' )
12
12
  - if field.cache_method
13
13
  = form.hidden_field(field.cache_method)
@@ -4,7 +4,7 @@
4
4
  js_data = {
5
5
  :jspath => field.ckeditor_location ? field.ckeditor_location : field.ckeditor_base_location + "ckeditor.js",
6
6
  :base_location => field.ckeditor_base_location,
7
- :options => {
7
+ :options => {
8
8
  :customConfig => field.ckeditor_config_js ? field.ckeditor_config_js : field.ckeditor_base_location + "config.js"
9
9
  }
10
10
  }
@@ -16,6 +16,12 @@
16
16
  :options => field.codemirror_config,
17
17
  :locations => field.codemirror_assets
18
18
  }
19
+ elsif field.bootstrap_wysihtml5
20
+ richtext = 'bootstrap-wysihtml5'
21
+ js_data = {
22
+ :csspath => field.bootstrap_wysihtml5_css_location,
23
+ :jspath => field.bootstrap_wysihtml5_js_location
24
+ }
19
25
  else
20
26
  richtext = false
21
27
  js_data = {}
@@ -1,29 +1,30 @@
1
- %table.table.table-condensed.table-striped
2
- %thead
3
- %tr
4
- %th.shrink.model-name= t "admin.table_headers.model_name"
5
- %th.shrink.last-used= t "admin.table_headers.last_used"
6
- %th.records= t "admin.table_headers.records"
7
- %th.shrink.controls
8
- %tbody
9
- - @abstract_models.each do |abstract_model|
10
- - if authorized? :index, abstract_model
11
- - index_path = index_path(:model_name => abstract_model.to_param)
12
- - row_class = "#{cycle("odd", "even")}#{" link" if index_path}"
1
+ - if @abstract_models
2
+ %table.table.table-condensed.table-striped
3
+ %thead
4
+ %tr
5
+ %th.shrink.model-name= t "admin.table_headers.model_name"
6
+ %th.shrink.last-used= t "admin.table_headers.last_used"
7
+ %th.records= t "admin.table_headers.records"
8
+ %th.shrink.controls
9
+ %tbody
10
+ - @abstract_models.each do |abstract_model|
11
+ - if authorized? :index, abstract_model
12
+ - index_path = index_path(:model_name => abstract_model.to_param)
13
+ - row_class = "#{cycle("odd", "even")}#{" link" if index_path}"
13
14
 
14
- %tr{:class => row_class, :"data-link" => index_path}
15
- %td
16
- %span.show= link_to abstract_model.config.label_plural, index_path, :class => 'pjax'
17
- %td
18
- - if (last_used = @most_recent_changes[abstract_model.pretty_name])
19
- = time_ago_in_words last_used
20
- = t "admin.misc.ago"
21
- %td
22
- - count = @count[abstract_model.pretty_name]
23
- - percent = count > 0 ? (@max < 2.0 ? count : ((Math.log(count) * 100.0) / Math.log(@max))) : -1
24
- .label.animate-width-to{:class => 'label-'+get_indicator(percent), :'data-animate-length' => ([1.0, percent].max.to_i * 20), :'data-animate-width-to' => "#{[2.0, percent - 1].max.to_i}%", :style => "width:2%"}= @count[abstract_model.pretty_name]
25
- %td.links
26
- %ul.inline= menu_for :collection, abstract_model, nil, true
15
+ %tr{:class => row_class, :"data-link" => index_path}
16
+ %td
17
+ %span.show= link_to abstract_model.config.label_plural, index_path, :class => 'pjax'
18
+ %td
19
+ - if (last_used = @most_recent_changes[abstract_model.pretty_name])
20
+ = time_ago_in_words last_used
21
+ = t "admin.misc.ago"
22
+ %td
23
+ - count = @count[abstract_model.pretty_name]
24
+ - percent = count > 0 ? (@max < 2.0 ? count : ((Math.log(count) * 100.0) / Math.log(@max))) : -1
25
+ .label.animate-width-to{:class => 'label-'+get_indicator(percent), :'data-animate-length' => ([1.0, percent].max.to_i * 20), :'data-animate-width-to' => "#{[2.0, percent - 1].max.to_i}%", :style => "width:2%"}= @count[abstract_model.pretty_name]
26
+ %td.links
27
+ %ul.inline= menu_for :collection, abstract_model, nil, true
27
28
  - if @auditing_adapter && authorized?(:history)
28
29
  #block-tables.block
29
30
  .content
@@ -113,7 +113,7 @@
113
113
  - if property.sortable
114
114
  - sort_location = index_path params.except('sort_reverse').except('page').merge(:sort => property.name).merge(selected && sort_reverse != "true" ? {:sort_reverse => "true"} : {})
115
115
  - sort_direction = selected ? (sort_reverse == 'true' ? "headerSortUp" : "headerSortDown") : nil
116
- %th{:class => "#{property.sortable && "header pjax" || nil} #{property.sortable && sort_direction ? sort_direction : nil} #{property.css_class} #{property.type_css_class}", :'data-href' => (property.sortable && sort_location)}= property.label
116
+ %th{:class => "#{property.sortable && "header pjax" || nil} #{property.sortable && sort_direction ? sort_direction : nil} #{property.css_class} #{property.type_css_class}", :'data-href' => (property.sortable && sort_location), :rel => "tooltip", :title => "#{property.hint}"}= property.label
117
117
  - if other_right
118
118
  %th.other.right.shrink= "..."
119
119
  %th.last.shrink
@@ -1,7 +1,7 @@
1
1
  if defined?(::ActiveRecord)
2
2
  class ActiveRecord::Base
3
3
  def self.rails_admin(&block)
4
- RailsAdmin::Config.model(self, &block)
4
+ RailsAdmin.config(self, &block)
5
5
  end
6
6
 
7
7
  def rails_admin_default_object_label_method
@@ -9,7 +9,7 @@ if defined?(::ActiveRecord)
9
9
  end
10
10
 
11
11
  def safe_send(value)
12
- if self.attributes.find{ |k,v| k.to_s == value.to_s }
12
+ if self.has_attribute?(value)
13
13
  self.read_attribute(value)
14
14
  else
15
15
  self.send(value)
@@ -22,6 +22,7 @@ en:
22
22
  up: "Up"
23
23
  down: "Down"
24
24
  navigation: "Navigation"
25
+ navigation_static_label: "Links"
25
26
  log_out: "Log out"
26
27
  ago: "ago"
27
28
  flash:
@@ -43,7 +43,7 @@ module RailsAdmin
43
43
  generate "devise", model_name
44
44
  else
45
45
  display "And you already set it up, good! We just need to know about your user model name..."
46
- guess = routes.match(/devise_for :(\w+)/)[1].try(:singularize)
46
+ guess = routes.match(/devise_for +:(\w+)/)[1].try(:singularize)
47
47
  display("We found '#{guess}' (should be one of 'user', 'admin', etc.)")
48
48
  model_name = ask_for("Correct Devise model name if needed.", guess, _model_name)
49
49
  unless guess == model_name
@@ -3,99 +3,98 @@
3
3
 
4
4
  RailsAdmin.config do |config|
5
5
 
6
- # If your default_local is different from :en, uncomment the following 2 lines and set your default locale here:
7
- # require 'i18n'
8
- # I18n.default_locale = :de
9
6
 
7
+ ################ Global configuration ################
8
+
9
+ # Set the admin name here (optional second array element will appear in red). For example:
10
+ config.main_app_name = ['<%= Rails.application.engine_name.titleize.chomp(' Application') %>', 'Admin']
11
+ # or for a more dynamic name:
12
+ # config.main_app_name = Proc.new { |controller| [Rails.application.engine_name.titleize, controller.params['action'].titleize] }
13
+
14
+ # RailsAdmin may need a way to know who the current user is]
10
15
  config.current_user_method { current_<%= @model_name.underscore %> } # auto-generated
11
16
 
12
17
  # If you want to track changes on your models:
13
- # config.audit_with :history, <%= @model_name.classify %>
18
+ # config.audit_with :history, '<%= @model_name.classify %>'
14
19
 
15
20
  # Or with a PaperTrail: (you need to install it first)
16
- # config.audit_with :paper_trail, <%= @model_name.classify %>
17
-
18
- # Set the admin name here (optional second array element will appear in a beautiful RailsAdmin red ©)
19
- config.main_app_name = ['<%= Rails.application.engine_name.titleize.chomp(' Application') %>', 'Admin']
20
- # or for a dynamic name:
21
- # config.main_app_name = Proc.new { |controller| [Rails.application.engine_name.titleize, controller.params['action'].titleize] }
22
-
21
+ # config.audit_with :paper_trail, '<%= @model_name.classify %>'
23
22
 
24
- # ==> Global show view settings
25
- # Display empty fields in show views
23
+ # Display empty fields in show views:
26
24
  # config.compact_show_view = false
27
25
 
28
- # ==> Global list view settings
29
26
  # Number of default rows per-page:
30
27
  # config.default_items_per_page = 20
31
28
 
32
- # ==> Included models
33
- # Add all excluded models here:
34
- # config.excluded_models = [<%= RailsAdmin::AbstractModel.all.map{|am| am.model.to_s }.join(', ') %>]
29
+ # Exclude specific models (keep the others):
30
+ # config.excluded_models = [<%= RailsAdmin::AbstractModel.all.map{|am| "'#{am.model}'" }.join(', ') %>]
35
31
 
36
- # Add models here if you want to go 'whitelist mode':
37
- # config.included_models = [<%= RailsAdmin::AbstractModel.all.map{|am| am.model.to_s }.join(', ') %>]
32
+ # Include specific models (exclude the others):
33
+ # config.included_models = [<%= RailsAdmin::AbstractModel.all.map{|am| "'#{am.model}'" }.join(', ') %>]
38
34
 
39
- # Application wide tried label methods for models' instances
35
+ # Label methods for model instances:
40
36
  # config.label_methods << :description # Default is [:name, :title]
41
37
 
42
- # ==> Global models configuration
43
- # config.models do
44
- # # Configuration here will affect all included models in all scopes, handle with care!
45
- #
46
- # list do
47
- # # Configuration here will affect all included models in list sections (same for show, export, edit, update, create)
48
- #
49
- # fields_of_type :date do
50
- # # Configuration here will affect all date fields, in the list section, for all included models. See README for a comprehensive type list.
51
- # end
52
- # end
53
- # end
54
- #
55
- # ==> Model specific configuration
56
- # Keep in mind that *all* configuration blocks are optional.
57
- # RailsAdmin will try his best to provide the best defaults for each section, for each field.
58
- # Try to override as few things as possible, in the most generic way. Try to avoid setting labels for models and attributes, use ActiveRecord I18n API instead.
59
- # Less code is better code!
60
- # config.model MyModel do
61
- # # Cross-section field configuration
62
- # object_label_method :name # Name of the method called for pretty printing an *instance* of ModelName
63
- # label 'My model' # Name of ModelName (smartly defaults to ActiveRecord's I18n API)
64
- # label_plural 'My models' # Same, plural
65
- # weight -1 # Navigation priority. Bigger is higher.
66
- # parent OtherModel # Set parent model for navigation. MyModel will be nested below. OtherModel will be on first position of the dropdown
67
- # navigation_label # Sets dropdown entry's name in navigation. Only for parents!
68
- # # Section specific configuration:
69
- # list do
70
- # filters [:id, :name] # Array of field names which filters should be shown by default in the table header
71
- # items_per_page 100 # Override default_items_per_page
72
- # sort_by :id # Sort column (default is primary key)
73
- # sort_reverse true # Sort direction (default is true for primary key, last created first)
74
- # # Here goes the fields configuration for the list view
75
- # end
76
- # end
77
38
 
78
- # Your model's configuration, to help you get started:
39
+ ################ Model configuration ################
79
40
 
80
- # All fields marked as 'hidden' won't be shown anywhere in the rails_admin unless you mark them as visible. (visible(true))
41
+ # Each model configuration can alternatively:
42
+ # - stay here in a `config.model 'ModelName' do ... end` block
43
+ # - go in the model definition file in a `rails_admin do ... end` block
44
+
45
+ # This is your choice to make:
46
+ # - This initializer is loaded once at startup (modifications will show up when restarting the application) but all RailsAdmin configuration would stay in one place.
47
+ # - Models are reloaded at each request in development mode (when modified), which may smooth your RailsAdmin development workflow.
48
+
49
+
50
+ # Now you probably need to tour the wiki a bit: https://github.com/sferik/rails_admin/wiki
51
+ # Anyway, here is how RailsAdmin saw your application's models when you ran the initializer:
81
52
 
82
53
  <% RailsAdmin::AbstractModel.all.map do |abstract_model| -%>
83
- # config.model <%= abstract_model.model.model_name %> do
54
+
55
+
56
+ ### <%= abstract_model.model.model_name %> ###
57
+
58
+ # config.model '<%= abstract_model.model.model_name %>' do
59
+
60
+ # # You can copy this to a 'rails_admin do ... end' block inside your <%= abstract_model.model.model_name.underscore %>.rb model definition
61
+
84
62
  # # Found associations:
63
+
85
64
  <%= abstract_model.config.export.fields.select{|f| f.association?}.map do |field|
86
65
  %{ # configure #{field.name.inspect}, #{field.type.inspect}#{" # Hidden" unless field.visible?} }
87
- end.join("\n") -%>
66
+ end.join("\n") %>
67
+
88
68
  # # Found columns:
69
+
89
70
  <%= abstract_model.config.export.fields.select{|f| !f.association?}.map do |field|
90
71
  %{ # configure #{field.name.inspect}, #{field.type.inspect}#{" # Hidden" unless field.visible?} }
91
- end.join("\n") -%>
92
- # # Sections:
93
- # list do; end
94
- # export do; end
95
- # show do; end
96
- # edit do; end
97
- # create do; end
98
- # update do; end
72
+ end.join("\n") %>
73
+
74
+ # # Cross-section configuration:
75
+
76
+ # # object_label_method :name # Name of the method called for pretty printing an *instance* of ModelName
77
+ # # label 'My model' # Name of ModelName (smartly defaults to ActiveRecord's I18n API)
78
+ # # label_plural 'My models' # Same, plural
79
+ # # weight 0 # Navigation priority. Bigger is higher.
80
+ # # parent OtherModel # Set parent model for navigation. MyModel will be nested below. OtherModel will be on first position of the dropdown
81
+ # # navigation_label # Sets dropdown entry's name in navigation. Only for parents!
82
+
83
+ # # Section specific configuration:
84
+
85
+ # list do
86
+ # # filters [:id, :name] # Array of field names which filters should be shown by default in the table header
87
+ # # items_per_page 100 # Override default_items_per_page
88
+ # # sort_by :id # Sort column (default is primary key)
89
+ # # sort_reverse true # Sort direction (default is true for primary key, last created first)
90
+ # end
91
+ # show do; end
92
+ # edit do; end
93
+ # export do; end
94
+ # # also see the create, update, modal and nested sections, which override edit in specific cases (resp. when creating, updating, modifying from another model in a popup modal or modifying from another model nested form)
95
+ # # you can override a cross-section field configuration in any section with the same syntax `configure :field_name do ... end`
96
+ # # using `field` instead of `configure` will exclude all other fields and force the ordering
99
97
  # end
100
98
  <%- end -%>
99
+
101
100
  end
@@ -40,14 +40,14 @@ module RailsAdmin
40
40
  end
41
41
  end
42
42
 
43
- def initialize(m)
44
- @model_name = m.to_s
45
- if m.ancestors.map(&:to_s).include?('ActiveRecord::Base') && !m.abstract_class?
43
+ def initialize(model_or_model_name)
44
+ @model_name = model_or_model_name.to_s
45
+ if model.ancestors.map(&:to_s).include?('ActiveRecord::Base') && !model.abstract_class?
46
46
  # ActiveRecord
47
47
  @adapter = :active_record
48
48
  require 'rails_admin/adapters/active_record'
49
49
  extend Adapters::ActiveRecord
50
- elsif m.ancestors.map(&:to_s).include?('Mongoid::Document')
50
+ elsif model.ancestors.map(&:to_s).include?('Mongoid::Document')
51
51
  # Mongoid
52
52
  @adapter = :mongoid
53
53
  require 'rails_admin/adapters/mongoid'
@@ -57,7 +57,7 @@ module RailsAdmin
57
57
 
58
58
  # do not store a reference to the model, does not play well with ActiveReload/Rails3.2
59
59
  def model
60
- @model_name.try :constantize
60
+ @model_name.constantize
61
61
  end
62
62
 
63
63
  def config
@@ -65,11 +65,11 @@ module RailsAdmin
65
65
  end
66
66
 
67
67
  def to_param
68
- model.to_s.split("::").map(&:underscore).join("~")
68
+ @model_name.split("::").map(&:underscore).join("~")
69
69
  end
70
70
 
71
71
  def param_key
72
- model.to_s.split("::").map(&:underscore).join("_")
72
+ @model_name.split("::").map(&:underscore).join("_")
73
73
  end
74
74
 
75
75
  def pretty_name
@@ -4,7 +4,8 @@ require 'rails_admin/adapters/active_record/abstract_object'
4
4
  module RailsAdmin
5
5
  module Adapters
6
6
  module ActiveRecord
7
- DISABLED_COLUMN_TYPES = [:tsvector, :blob, :binary, :spatial, :hstore]
7
+ DISABLED_COLUMN_TYPES = [:tsvector, :blob, :binary, :spatial, :hstore, :geometry]
8
+ DISABLED_COLUMN_MATCHERS = [/_array$/]
8
9
 
9
10
  def ar_adapter
10
11
  Rails.configuration.database_configuration[Rails.env]['adapter']
@@ -80,16 +81,17 @@ module RailsAdmin
80
81
  end
81
82
 
82
83
  def properties
83
- columns = model.columns.reject {|c| c.type.blank? || DISABLED_COLUMN_TYPES.include?(c.type.to_sym) }
84
+ columns = model.columns.reject do |c|
85
+ c.type.blank? || DISABLED_COLUMN_TYPES.include?(c.type.to_sym) || DISABLED_COLUMN_MATCHERS.any? {|matcher| matcher.match(c.type.to_s)}
86
+ end
84
87
  columns.map do |property|
85
88
  {
86
89
  :name => property.name.to_sym,
87
90
  :pretty_name => property.name.to_s.tr('_', ' ').capitalize,
88
- :type => property.type,
89
91
  :length => property.limit,
90
92
  :nullable? => property.null,
91
93
  :serial? => property.primary,
92
- }
94
+ }.merge(type_lookup(property))
93
95
  end
94
96
  end
95
97
 
@@ -97,10 +99,6 @@ module RailsAdmin
97
99
  model.table_name
98
100
  end
99
101
 
100
- def serialized_attributes
101
- model.serialized_attributes.keys
102
- end
103
-
104
102
  def encoding
105
103
  Rails.configuration.database_configuration[Rails.env]['encoding']
106
104
  end
@@ -173,6 +171,9 @@ module RailsAdmin
173
171
  when :boolean
174
172
  return ["(#{column} IS NULL OR #{column} = ?)", false] if ['false', 'f', '0'].include?(value)
175
173
  return ["(#{column} = ?)", true] if ['true', 't', '1'].include?(value)
174
+ when :decimal
175
+ return if value.blank?
176
+ ["(#{column} = ?)", value.to_f] if value.to_f.to_s == value
176
177
  when :integer, :belongs_to_association
177
178
  return if value.blank?
178
179
  ["(#{column} = ?)", value.to_i] if value.to_i.to_s == value
@@ -217,6 +218,14 @@ module RailsAdmin
217
218
  end
218
219
  end
219
220
 
221
+ def type_lookup(property)
222
+ if model.serialized_attributes[property.name.to_s]
223
+ {:type => :serialized}
224
+ else
225
+ {:type => property.type}
226
+ end
227
+ end
228
+
220
229
  def association_model_lookup(association)
221
230
  if association.options[:polymorphic]
222
231
  RailsAdmin::AbstractModel.polymorphic_parents(:active_record, association.name) || []