rails_admin 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rails_admin might be problematic. Click here for more details.

Files changed (120) hide show
  1. data/Gemfile +2 -2
  2. data/README.md +13 -6
  3. data/app/assets/images/rails_admin/aristo/images/bg_fallback.png +0 -0
  4. data/app/assets/images/rails_admin/aristo/images/icon_sprite.png +0 -0
  5. data/app/assets/images/rails_admin/aristo/images/progress_bar.gif +0 -0
  6. data/app/assets/images/rails_admin/aristo/images/slider_handles.png +0 -0
  7. data/app/assets/images/rails_admin/aristo/images/ui-icons_222222_256x240.png +0 -0
  8. data/app/assets/images/rails_admin/aristo/images/ui-icons_454545_256x240.png +0 -0
  9. data/app/assets/images/rails_admin/bullet_white.png +0 -0
  10. data/app/assets/images/rails_admin/calendar.png +0 -0
  11. data/app/assets/images/rails_admin/clock.png +0 -0
  12. data/app/assets/images/rails_admin/colorpicker/colorpicker_background.png +0 -0
  13. data/app/assets/images/rails_admin/colorpicker/colorpicker_hex.png +0 -0
  14. data/app/assets/images/rails_admin/colorpicker/colorpicker_hsb_b.png +0 -0
  15. data/app/assets/images/rails_admin/colorpicker/colorpicker_hsb_h.png +0 -0
  16. data/app/assets/images/rails_admin/colorpicker/colorpicker_hsb_s.png +0 -0
  17. data/app/assets/images/rails_admin/colorpicker/colorpicker_overlay.png +0 -0
  18. data/app/assets/images/rails_admin/colorpicker/colorpicker_rgb_b.png +0 -0
  19. data/app/assets/images/rails_admin/colorpicker/colorpicker_rgb_g.png +0 -0
  20. data/app/assets/images/rails_admin/colorpicker/colorpicker_rgb_r.png +0 -0
  21. data/app/assets/images/rails_admin/colorpicker/colorpicker_select.gif +0 -0
  22. data/app/assets/images/rails_admin/colorpicker/colorpicker_submit.png +0 -0
  23. data/app/assets/images/rails_admin/colorpicker/custom_background.png +0 -0
  24. data/app/assets/images/rails_admin/colorpicker/custom_hex.png +0 -0
  25. data/app/assets/images/rails_admin/colorpicker/custom_hsb_b.png +0 -0
  26. data/app/assets/images/rails_admin/colorpicker/custom_hsb_h.png +0 -0
  27. data/app/assets/images/rails_admin/colorpicker/custom_hsb_s.png +0 -0
  28. data/app/assets/images/rails_admin/colorpicker/custom_rgb_b.png +0 -0
  29. data/app/assets/images/rails_admin/colorpicker/custom_rgb_g.png +0 -0
  30. data/app/assets/images/rails_admin/colorpicker/custom_rgb_r.png +0 -0
  31. data/app/assets/images/rails_admin/colorpicker/custom_submit.png +0 -0
  32. data/app/assets/images/rails_admin/colorpicker/select.png +0 -0
  33. data/app/assets/images/rails_admin/colorpicker/select2.png +0 -0
  34. data/app/assets/images/rails_admin/colorpicker/slider.png +0 -0
  35. data/app/assets/images/rails_admin/logo.png +0 -0
  36. data/app/assets/images/rails_admin/magnifier.png +0 -0
  37. data/app/assets/images/rails_admin/multiselect/icon_sprite.png +0 -0
  38. data/app/assets/images/rails_admin/multiselect/ui-icon-circle-triangle-n-dark.png +0 -0
  39. data/app/assets/images/rails_admin/multiselect/ui-icon-circle-triangle-n-light.png +0 -0
  40. data/app/assets/images/rails_admin/multiselect/ui-icon-circle-triangle-s-dark.png +0 -0
  41. data/app/assets/images/rails_admin/multiselect/ui-icon-circle-triangle-s-light.png +0 -0
  42. data/app/assets/stylesheets/rails_admin/aristo/images/bg_fallback.png +0 -0
  43. data/app/assets/stylesheets/rails_admin/aristo/images/icon_sprite.png +0 -0
  44. data/app/assets/stylesheets/rails_admin/aristo/images/progress_bar.gif +0 -0
  45. data/app/assets/stylesheets/rails_admin/aristo/images/slider_handles.png +0 -0
  46. data/app/assets/stylesheets/rails_admin/aristo/images/ui-icons_222222_256x240.png +0 -0
  47. data/app/assets/stylesheets/rails_admin/aristo/images/ui-icons_454545_256x240.png +0 -0
  48. data/app/assets/stylesheets/rails_admin/jquery.colorpicker.css.scss +1 -0
  49. data/app/controllers/rails_admin/main_controller.rb +1 -1
  50. data/app/helpers/rails_admin/application_helper.rb +3 -2
  51. data/app/views/rails_admin/main/index.html.haml +1 -1
  52. data/lib/generators/rails_admin/install_generator.rb +1 -1
  53. data/lib/rails_admin/abstract_model.rb +4 -0
  54. data/lib/rails_admin/adapters/active_record.rb +4 -0
  55. data/lib/rails_admin/adapters/mongoid.rb +6 -0
  56. data/lib/rails_admin/adapters/mongoid/abstract_object.rb +3 -3
  57. data/lib/rails_admin/config.rb +9 -12
  58. data/lib/rails_admin/config/actions/base.rb +4 -3
  59. data/lib/rails_admin/config/fields/association.rb +1 -1
  60. data/lib/rails_admin/config/fields/base.rb +1 -1
  61. data/lib/rails_admin/config/fields/factories/association.rb +1 -1
  62. data/lib/rails_admin/config/fields/types/belongs_to_association.rb +1 -1
  63. data/lib/rails_admin/config/fields/types/boolean.rb +2 -2
  64. data/lib/rails_admin/config/fields/types/datetime.rb +1 -1
  65. data/lib/rails_admin/config/has_fields.rb +3 -2
  66. data/lib/rails_admin/config/lazy_model.rb +21 -0
  67. data/lib/rails_admin/extensions/history/history.rb +5 -5
  68. data/lib/rails_admin/support/csv_converter.rb +2 -6
  69. data/lib/rails_admin/version.rb +1 -1
  70. data/spec/controllers/{application_controller_spec.rb → rails_admin/application_controller_spec.rb} +0 -0
  71. data/spec/controllers/{main_controller_spec.rb → rails_admin/main_controller_spec.rb} +36 -4
  72. data/spec/dummy_app/Gemfile +2 -2
  73. data/spec/dummy_app/app/active_record/comment.rb +1 -1
  74. data/spec/dummy_app/app/active_record/team.rb +1 -1
  75. data/spec/dummy_app/app/mongoid/field_test.rb +2 -1
  76. data/spec/dummy_app/app/mongoid/team.rb +1 -1
  77. data/spec/dummy_app/db/seeds.rb +4 -4
  78. data/spec/dummy_app/db/test.sqlite3 +0 -0
  79. data/spec/dummy_app/log/test.log +156160 -0
  80. data/spec/helpers/rails_admin/application_helper_spec.rb +353 -0
  81. data/spec/helpers/{form_builder_spec.rb → rails_admin/form_builder_spec.rb} +0 -0
  82. data/spec/integration/authorization/cancan_spec.rb +13 -13
  83. data/spec/integration/basic/bulk_action/rails_admin_basic_bulk_action_spec.rb +2 -2
  84. data/spec/integration/basic/bulk_destroy/rails_admin_basic_bulk_destroy_spec.rb +13 -2
  85. data/spec/integration/basic/create/rails_admin_basic_create_spec.rb +8 -9
  86. data/spec/integration/basic/create/rails_admin_namespaced_model_create_spec.rb +1 -1
  87. data/spec/integration/basic/destroy/rails_admin_basic_destroy_spec.rb +4 -4
  88. data/spec/integration/basic/edit/rails_admin_basic_edit_spec.rb +2 -2
  89. data/spec/integration/basic/export/rails_admin_basic_export_spec.rb +2 -2
  90. data/spec/integration/basic/list/rails_admin_basic_list_spec.rb +51 -21
  91. data/spec/integration/basic/update/rails_admin_basic_update_spec.rb +15 -15
  92. data/spec/integration/config/edit/rails_admin_config_edit_spec.rb +13 -14
  93. data/spec/integration/config/list/rails_admin_config_list_spec.rb +7 -6
  94. data/spec/integration/config/show/rails_admin_config_show_spec.rb +1 -1
  95. data/spec/integration/rails_admin_spec.rb +2 -0
  96. data/spec/{unit → rails_admin}/abstract_model_spec.rb +7 -0
  97. data/spec/{unit → rails_admin}/active_record_extension_spec.rb +0 -0
  98. data/spec/{unit → rails_admin}/adapters/active_record/abstract_object_spec.rb +0 -0
  99. data/spec/{unit → rails_admin}/adapters/active_record_spec.rb +0 -0
  100. data/spec/{unit → rails_admin}/adapters/mongoid/abstract_object_spec.rb +0 -0
  101. data/spec/{unit → rails_admin}/adapters/mongoid_spec.rb +7 -1
  102. data/spec/{unit → rails_admin}/config/actions/base_spec.rb +0 -0
  103. data/spec/{unit → rails_admin}/config/actions_spec.rb +0 -0
  104. data/spec/{unit → rails_admin}/config/fields/base_spec.rb +0 -0
  105. data/spec/{unit → rails_admin}/config/fields/date_spec.rb +0 -0
  106. data/spec/{unit → rails_admin}/config/fields/datetime_spec.rb +0 -0
  107. data/spec/{unit → rails_admin}/config/fields/file_upload_spec.rb +0 -0
  108. data/spec/{unit → rails_admin}/config/fields/time_spec.rb +0 -0
  109. data/spec/{unit → rails_admin}/config/fields/timestamp_spec.rb +0 -0
  110. data/spec/rails_admin/config/fields/types/datetime_spec.rb +18 -0
  111. data/spec/{unit → rails_admin}/config/fields_spec.rb +0 -0
  112. data/spec/rails_admin/config/has_fields_spec.rb +30 -0
  113. data/spec/rails_admin/config/lazy_model_spec.rb +29 -0
  114. data/spec/{unit → rails_admin}/config/model_spec.rb +0 -0
  115. data/spec/{unit → rails_admin}/config/sections_spec.rb +0 -0
  116. data/spec/{unit → rails_admin}/config_spec.rb +0 -0
  117. data/spec/{unit → rails_admin}/support/csv_converter_spec.rb +0 -0
  118. data/spec/spec_helper.rb +2 -0
  119. metadata +65 -60
  120. data/spec/helpers/application_helper_spec.rb +0 -328
data/Gemfile CHANGED
@@ -9,7 +9,7 @@ group :active_record do
9
9
  platforms :ruby, :mswin, :mingw do
10
10
  case ENV['CI_DB_ADAPTER']
11
11
  when 'mysql'
12
- gem 'mysql', '~> 2.9'
12
+ gem 'mysql', '2.8.1'
13
13
  when 'postgresql'
14
14
  gem 'pg', '~> 0.13'
15
15
  else
@@ -21,7 +21,7 @@ end
21
21
  group :mongoid do
22
22
  gem 'mongoid', '~> 3.0'
23
23
  gem 'mongoid-paperclip', '~> 0.0.8', :require => 'mongoid_paperclip'
24
- gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid', :git => 'git://github.com/jnicklas/carrierwave-mongoid.git', :branch => 'mongoid-3.0'
24
+ gem 'carrierwave-mongoid', '~> 0.3', :require => 'carrierwave/mongoid'
25
25
  end
26
26
 
27
27
  group :debug do
data/README.md CHANGED
@@ -28,18 +28,25 @@ Hoeven][plukevdh], and [Rein Henrichs][reinh].
28
28
 
29
29
  ## Announcements
30
30
 
31
- * for those with `rake db:migrate` errors, update to master and check that you see the line: "[RailsAdmin] RailsAdmin initialization disabled by default." when you launch the task. If not (or if migrations still don't work), open a ticket with an application on Github that can reproduce the issue.
32
-
33
- * `config.models do ... end` is deprecated (note the 's' to models, `config.model(MyModel) do .. end` is fine), for performance reasons (forces early loading of all application's models). Duplicate to each model instead, before next release. If you really need the old behavior:
31
+ RailsAdmin model configuration is now lazy loaded.
34
32
 
35
33
  ```ruby
36
- config.models.each do |m|
37
- config.model m do
38
- # <<<< here goes your code
34
+ config.model 'Team' do
35
+ ...
36
+ end
37
+
38
+ # or
39
+ class Team
40
+ rails_admin do
41
+ ...
39
42
  end
40
43
  end
41
44
  ```
42
45
 
46
+ won't load the Team model.
47
+
48
+ Incidentally, you are only allowed one configuration block per model.
49
+
43
50
  ## Features
44
51
 
45
52
  * Display database tables
@@ -100,6 +100,7 @@
100
100
  padding: 0 !important;
101
101
  height: 11px !important;
102
102
  width: auto !important;
103
+ line-height: normal !important;
103
104
  }
104
105
  .colorpicker_hex {
105
106
  position: absolute;
@@ -130,7 +130,7 @@ module RailsAdmin
130
130
  def get_collection(model_config, scope, pagination)
131
131
  associations = model_config.list.fields.select {|f| f.type == :belongs_to_association && !f.polymorphic? }.map {|f| f.association[:name] }
132
132
  options = {}
133
- options = options.merge(:page => (params[:page] || 1).to_i, :per => (params[:per] || model_config.list.items_per_page)) if pagination
133
+ options = options.merge(:page => (params[Kaminari.config.param_name] || 1).to_i, :per => (params[:per] || model_config.list.items_per_page)) if pagination
134
134
  options = options.merge(:include => associations) unless associations.blank?
135
135
  options = options.merge(get_sort_hash(model_config))
136
136
  options = options.merge(:query => params[:query]) if params[:query].present?
@@ -5,8 +5,9 @@ module RailsAdmin
5
5
 
6
6
  include RailsAdmin::I18nSupport
7
7
 
8
- def authorized?(*args)
9
- @authorization_adapter.nil? || @authorization_adapter.authorized?(*args)
8
+ def authorized?(action, abstract_model = nil, object = nil)
9
+ object = nil if object.try :new_record?
10
+ @authorization_adapter.nil? || @authorization_adapter.authorized?(action, abstract_model, object)
10
11
  end
11
12
 
12
13
  def current_action?(action, abstract_model = @abstract_model, object = @object)
@@ -21,7 +21,7 @@
21
21
  @index = 0
22
22
  @ordered_filters = (params[:f] || @model_config.list.filters).inject({}) { |memo, filter|
23
23
  field_name = filter.is_a?(Array) ? filter.first : filter
24
- (filter.is_a?(Array) ? filter.last : { (@index += 1) => { "value" => '' } }) .each do |index, filter_hash|
24
+ (filter.is_a?(Array) ? filter.last : { (@index += 1) => { "v" => '' } }) .each do |index, filter_hash|
25
25
  unless filter_hash['disabled']
26
26
  memo[index] = { field_name => filter_hash }
27
27
  else
@@ -20,7 +20,7 @@ module RailsAdmin
20
20
  routes = File.open(Rails.root.join("config/routes.rb")).try :read
21
21
  initializer = (File.open(Rails.root.join("config/initializers/rails_admin.rb")) rescue nil).try :read
22
22
 
23
- display "Hello, RailsAdmin installer will help you sets things up!", :blue
23
+ display "Hello, RailsAdmin installer will help you set things up!", :blue
24
24
  display "I need to work with Devise, let's look at a few things first:"
25
25
  display "Checking for a current installation of devise..."
26
26
  unless defined?(Devise)
@@ -61,6 +61,10 @@ module RailsAdmin
61
61
  @model_name.constantize
62
62
  end
63
63
 
64
+ def to_s
65
+ model.to_s
66
+ end
67
+
64
68
  def config
65
69
  Config.model self
66
70
  end
@@ -107,6 +107,10 @@ module RailsAdmin
107
107
  false
108
108
  end
109
109
 
110
+ def adapter_supports_joins?
111
+ true
112
+ end
113
+
110
114
  private
111
115
 
112
116
  def query_conditions(query, fields = config.list.fields.select(&:queryable?))
@@ -109,6 +109,10 @@ module RailsAdmin
109
109
  ObjectId.from_string(str)
110
110
  end
111
111
 
112
+ def adapter_supports_joins?
113
+ false
114
+ end
115
+
112
116
  private
113
117
 
114
118
  def query_conditions(query, fields = config.list.fields.select(&:queryable?))
@@ -263,6 +267,7 @@ module RailsAdmin
263
267
  "Moped::BSON::ObjectId" => { :type => :bson_object_id, :serial? => (name == primary_key) },
264
268
  "Date" => { :type => :date },
265
269
  "DateTime" => { :type => :datetime },
270
+ "ActiveSupport::TimeWithZone" => { :type => :datetime },
266
271
  "Float" => { :type => :float },
267
272
  "Hash" => { :type => :serialized },
268
273
  "Money" => { :type => :serialized },
@@ -408,6 +413,7 @@ module RailsAdmin
408
413
 
409
414
  def sort_by(options, scope)
410
415
  return scope unless options[:sort]
416
+
411
417
  field_name, collection_name = options[:sort].to_s.split('.').reverse
412
418
  if collection_name && collection_name != table_name
413
419
  # sorting by associated model column is not supported, so just ignore
@@ -13,11 +13,11 @@ module RailsAdmin
13
13
  end
14
14
 
15
15
  def #{name.to_s.singularize}_ids=(item_ids)
16
- items = Array.wrap(item_ids).map{|item_id| #{name}.klass.find(item_id) rescue nil }.compact
16
+ __items__ = Array.wrap(item_ids).map{|item_id| #{name}.klass.find(item_id) rescue nil }.compact
17
17
  if persisted?
18
- #{name}.substitute items
18
+ #{name}.substitute __items__
19
19
  else
20
- items.each do |item|
20
+ __items__.each do |item|
21
21
  item.update_attribute('#{association.foreign_key}', id)
22
22
  end
23
23
  end
@@ -1,4 +1,4 @@
1
- require 'rails_admin/config/model'
1
+ require 'rails_admin/config/lazy_model'
2
2
  require 'rails_admin/config/sections/list'
3
3
  require 'active_support/core_ext/class/attribute_accessors'
4
4
 
@@ -244,9 +244,12 @@ module RailsAdmin
244
244
  entity.class.name.to_sym
245
245
  end
246
246
  end
247
- config = @registry[key] ||= RailsAdmin::Config::Model.new(entity)
248
- config.instance_eval(&block) if block
249
- config
247
+
248
+ if block
249
+ @registry[key] = RailsAdmin::Config::LazyModel.new(entity, &block)
250
+ else
251
+ @registry[key] ||= RailsAdmin::Config::LazyModel.new(entity)
252
+ end
250
253
  end
251
254
 
252
255
  def default_hidden_fields=(fields)
@@ -266,15 +269,9 @@ module RailsAdmin
266
269
 
267
270
  # Returns all model configurations
268
271
  #
269
- # If a block is given it is evaluated in the context of configuration
270
- # instances.
271
- #
272
272
  # @see RailsAdmin::Config.registry
273
- def models(&block)
274
- if block
275
- ActiveSupport::Deprecation.warn("'config.models do ... end' is deprecated for performance reasons and will be removed in next major release, please duplicate to every concerned model instead.")
276
- end
277
- RailsAdmin::AbstractModel.all.map{|m| model(m, &block)}
273
+ def models
274
+ RailsAdmin::AbstractModel.all.map{|m| model(m)}
278
275
  end
279
276
 
280
277
  # Reset all configurations to defaults.
@@ -30,10 +30,11 @@ module RailsAdmin
30
30
 
31
31
  register_instance_option :authorized? do
32
32
  (
33
- bindings[:controller].nil? or bindings[:controller].authorized?(self.authorization_key, bindings[:abstract_model], bindings[:object])) and (
33
+ bindings[:controller].nil? or bindings[:controller].authorized?(self.authorization_key, bindings[:abstract_model], bindings[:object])
34
+ ) and (
34
35
  bindings[:abstract_model].nil? or (
35
- (only.nil? or [only].flatten.map(&:to_s).include?(bindings[:abstract_model].model.to_s)) and
36
- ![except].flatten.map(&:to_s).include?(bindings[:abstract_model].model.to_s) and
36
+ (only.nil? or [only].flatten.map(&:to_s).include?(bindings[:abstract_model].to_s)) and
37
+ ![except].flatten.map(&:to_s).include?(bindings[:abstract_model].to_s) and
37
38
  bindings[:abstract_model].config.with(bindings).visible?
38
39
  ))
39
40
  end
@@ -90,7 +90,7 @@ module RailsAdmin
90
90
 
91
91
  # Reader for the association's value unformatted
92
92
  def value
93
- bindings[:object].send(association[:name])
93
+ bindings[:object].safe_send(association[:name])
94
94
  end
95
95
 
96
96
  # has many?
@@ -279,7 +279,7 @@ module RailsAdmin
279
279
  register_instance_option :allowed_methods do
280
280
  [method_name]
281
281
  end
282
-
282
+
283
283
  def parse_input(params)
284
284
  # overriden
285
285
  end
@@ -16,7 +16,7 @@ RailsAdmin::Config::Fields.register_factory do |parent, properties, fields|
16
16
  end.map{|k| association[k] }.compact
17
17
 
18
18
  parent.abstract_model.properties.select{|p| possible_field_names.include? p[:name] }.each do |column|
19
- unless child_field = fields.find{|f| f.name.to_s == column[:name].to_s }
19
+ unless child_field = fields.find{|f| f.name.to_s == column[:name].to_s }
20
20
  child_field = RailsAdmin::Config::Fields.default_factory.call(parent, column, fields)
21
21
  end
22
22
  child_columns << child_field
@@ -12,7 +12,7 @@ module RailsAdmin
12
12
  end
13
13
 
14
14
  register_instance_option :sortable do
15
- @sortable ||= associated_model_config.abstract_model.properties.map{ |p| p[:name] }.include?(associated_model_config.object_label_method) ? associated_model_config.object_label_method : {self.abstract_model.table_name => self.method_name}
15
+ @sortable ||= abstract_model.adapter_supports_joins? && associated_model_config.abstract_model.properties.map{ |p| p[:name] }.include?(associated_model_config.object_label_method) ? associated_model_config.object_label_method : {self.abstract_model.table_name => self.method_name}
16
16
  end
17
17
 
18
18
  register_instance_option :searchable do
@@ -16,9 +16,9 @@ module RailsAdmin
16
16
  case value
17
17
  when nil
18
18
  %{<span class="badge">-</span>}
19
- when false
19
+ when false
20
20
  %{<span class="badge badge-important">&#x2718;</span>}
21
- when true
21
+ when true
22
22
  %{<span class="badge badge-success">&#x2713;</span>}
23
23
  end.html_safe
24
24
  end
@@ -52,7 +52,7 @@ module RailsAdmin
52
52
  end
53
53
 
54
54
  def formatted_date_value
55
- value = bindings[:object].new_record? && self.value.nil? && !self.default_value.nil? ? self.default_value : nil
55
+ value = bindings[:object].new_record? && self.value.nil? && !self.default_value.nil? ? self.default_value : self.value
56
56
  value.nil? ? "" : I18n.l(value, :format => localized_date_format).strip
57
57
  end
58
58
 
@@ -8,8 +8,9 @@ module RailsAdmin
8
8
 
9
9
  # some fields are hidden by default (belongs_to keys, has_many associations in list views.)
10
10
  # unhide them if config specifically defines them
11
- field.show if field.try(:hidden?)
12
-
11
+ if field
12
+ field.show unless field.instance_variable_get("@#{field.name}_registered").is_a?(Proc)
13
+ end
13
14
  # Specify field as virtual if type is not specifically set and field was not
14
15
  # found in default stack
15
16
  if field.nil? && type.nil?
@@ -0,0 +1,21 @@
1
+ require 'rails_admin/config/model'
2
+
3
+ module RailsAdmin
4
+ module Config
5
+ class LazyModel
6
+ def initialize(entity, &block)
7
+ @entity = entity
8
+ @deferred_block = block
9
+ end
10
+
11
+ def method_missing(method, *args, &block)
12
+ if !@model
13
+ @model = RailsAdmin::Config::Model.new(@entity)
14
+ @model.instance_eval(&@deferred_block) if @deferred_block
15
+ end
16
+
17
+ @model.send(method, *args, &block)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -15,20 +15,20 @@ class RailsAdmin::History < ActiveRecord::Base
15
15
  create(
16
16
  :message => [message].flatten.join(', '),
17
17
  :item => object.id,
18
- :table => abstract_model.model.to_s,
18
+ :table => abstract_model.to_s,
19
19
  :username => user.try(:email)
20
20
  )
21
21
  end
22
22
 
23
- def self.history_for_model(model, query, sort, sort_reverse, all, page, per_page = (RailsAdmin::Config.default_items_per_page || 20))
24
- history = where(:table => model.pretty_name)
23
+ def self.history_for_model(abstract_model, query, sort, sort_reverse, all, page, per_page = (RailsAdmin::Config.default_items_per_page || 20))
24
+ history = where(:table => abstract_model.to_s)
25
25
  history = history.where("message LIKE ? OR username LIKE ?", "%#{query}%", "%#{query}%") if query
26
26
  history = history.order(sort_reverse == "true" ? "#{sort} DESC" : sort) if sort
27
27
  all ? history : history.send(Kaminari.config.page_method_name, page.presence || "1").per(per_page)
28
28
  end
29
29
 
30
- def self.history_for_object(model, object, query, sort, sort_reverse, all, page, per_page = (RailsAdmin::Config.default_items_per_page || 20))
31
- history = where(:table => model.pretty_name, :item => object.id)
30
+ def self.history_for_object(abstract_model, object, query, sort, sort_reverse, all, page, per_page = (RailsAdmin::Config.default_items_per_page || 20))
31
+ history = where(:table => abstract_model.to_s, :item => object.id)
32
32
  history = history.where("message LIKE ? OR username LIKE ?", "%#{query}%", "%#{query}%") if query
33
33
  history = history.order(sort_reverse == "true" ? "#{sort} DESC" : sort) if sort
34
34
  all ? history : history.send(Kaminari.config.page_method_name, page.presence || "1").per(per_page)
@@ -5,6 +5,7 @@ module RailsAdmin
5
5
 
6
6
  CSVClass = RUBY_VERSION < '1.9' ? ::FasterCSV : ::CSV
7
7
  NON_ASCII_ENCODINGS = /(UTF\-16)|(UTF\-32)|(ISO\-2022\-JP)|(Big5\-HKSCS)|(UTF\-7)/
8
+ UTF8_ENCODINGS = [nil, '', 'utf8', 'utf-8', 'unicode', 'UTF8', 'UTF-8', 'UNICODE']
8
9
 
9
10
  class CSVConverter
10
11
 
@@ -42,11 +43,7 @@ module RailsAdmin
42
43
  return '' if @objects.blank?
43
44
 
44
45
  # encoding shenanigans first
45
- @encoding_from = if [nil, '', 'utf8', 'utf-8', 'UTF8', 'UTF-8'].include?(encoding = @abstract_model.encoding)
46
- 'UTF-8'
47
- else
48
- encoding
49
- end
46
+ @encoding_from = UTF8_ENCODINGS.include?(@abstract_model.encoding) ? 'UTF-8' : @abstract_model.encoding
50
47
 
51
48
  unless options[:encoding_to].blank?
52
49
  @encoding_to = options[:encoding_to]
@@ -106,4 +103,3 @@ module RailsAdmin
106
103
  end
107
104
  end
108
105
  end
109
-