rails_admin 1.0.0.rc → 1.0.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.
- checksums.yaml +4 -4
- data/Gemfile +1 -2
- data/README.md +1 -14
- data/app/assets/javascripts/rails_admin/ra.filtering-multiselect.js +15 -10
- data/app/assets/javascripts/rails_admin/ra.filtering-select.js +205 -110
- data/app/assets/javascripts/rails_admin/ra.remote-form.js +1 -4
- data/app/controllers/rails_admin/application_controller.rb +5 -5
- data/app/controllers/rails_admin/main_controller.rb +2 -2
- data/app/helpers/rails_admin/application_helper.rb +2 -2
- data/app/helpers/rails_admin/form_builder.rb +9 -2
- data/app/helpers/rails_admin/main_helper.rb +1 -1
- data/app/views/layouts/rails_admin/application.html.haml +1 -0
- data/app/views/rails_admin/main/_delete_notice.html.haml +14 -9
- data/app/views/rails_admin/main/index.html.haml +2 -2
- data/config/initializers/active_record_extensions.rb +2 -2
- data/config/locales/rails_admin.en.yml +1 -0
- data/lib/rails_admin/abstract_model.rb +6 -7
- data/lib/rails_admin/adapters/active_record.rb +30 -11
- data/lib/rails_admin/adapters/mongoid.rb +2 -2
- data/lib/rails_admin/adapters/mongoid/association.rb +2 -2
- data/lib/rails_admin/adapters/mongoid/extension.rb +1 -1
- data/lib/rails_admin/adapters/mongoid/property.rb +1 -1
- data/lib/rails_admin/bootstrap-sass.rb +1 -3
- data/lib/rails_admin/bootstrap-sass/compass_functions.rb +1 -1
- data/lib/rails_admin/config.rb +12 -8
- data/lib/rails_admin/config/actions.rb +1 -1
- data/lib/rails_admin/config/actions/base.rb +3 -4
- data/lib/rails_admin/config/actions/bulk_delete.rb +1 -3
- data/lib/rails_admin/config/actions/index.rb +3 -5
- data/lib/rails_admin/config/configurable.rb +4 -6
- data/lib/rails_admin/config/fields/association.rb +1 -1
- data/lib/rails_admin/config/fields/base.rb +15 -26
- data/lib/rails_admin/config/fields/factories/carrierwave.rb +1 -1
- data/lib/rails_admin/config/fields/types.rb +1 -1
- data/lib/rails_admin/config/fields/types/active_record_enum.rb +17 -2
- data/lib/rails_admin/config/fields/types/file_upload.rb +1 -1
- data/lib/rails_admin/config/fields/types/has_many_association.rb +1 -1
- data/lib/rails_admin/config/fields/types/polymorphic_association.rb +1 -1
- data/lib/rails_admin/config/fields/types/string.rb +6 -5
- data/lib/rails_admin/config/fields/types/text.rb +3 -3
- data/lib/rails_admin/config/hideable.rb +1 -1
- data/lib/rails_admin/config/inspectable.rb +39 -0
- data/lib/rails_admin/config/model.rb +4 -17
- data/lib/rails_admin/config/sections/base.rb +4 -17
- data/lib/rails_admin/engine.rb +3 -2
- data/lib/rails_admin/extension.rb +4 -4
- data/lib/rails_admin/extensions/paper_trail/auditing_adapter.rb +10 -2
- data/lib/rails_admin/extensions/pundit/authorization_adapter.rb +11 -1
- data/lib/rails_admin/support/datetime.rb +1 -1
- data/lib/rails_admin/version.rb +1 -1
- metadata +7 -6
@@ -91,10 +91,7 @@
|
|
91
91
|
dialog.find('.modal-body').html(data.responseText);
|
92
92
|
widget._bindFormEvents();
|
93
93
|
} else {
|
94
|
-
|
95
|
-
// https://github.com/JangoSteve/remotipart/blob/c08d61137ee18e0e78eb3cd9ca3030479fd101f1/lib/remotipart/render_overrides.rb#L17
|
96
|
-
var responseText = data.responseText.replace(/^try{[^}]+}catch\(err\){[^}]+}/, '');
|
97
|
-
var json = $.parseJSON(responseText);
|
94
|
+
var json = $.parseJSON(data.responseText);
|
98
95
|
var option = '<option value="' + json.id + '" selected>' + json.label + '</option>';
|
99
96
|
var select = widget.element.find('select').filter(":hidden");
|
100
97
|
|
@@ -21,13 +21,13 @@ module RailsAdmin
|
|
21
21
|
|
22
22
|
def get_model
|
23
23
|
@model_name = to_model_name(params[:model_name])
|
24
|
-
|
25
|
-
|
24
|
+
raise(RailsAdmin::ModelNotFound) unless (@abstract_model = RailsAdmin::AbstractModel.new(@model_name))
|
25
|
+
raise(RailsAdmin::ModelNotFound) if (@model_config = @abstract_model.config).excluded?
|
26
26
|
@properties = @abstract_model.properties
|
27
27
|
end
|
28
28
|
|
29
29
|
def get_object
|
30
|
-
|
30
|
+
raise(RailsAdmin::ObjectNotFound) unless (@object = @abstract_model.get(params[:id]))
|
31
31
|
end
|
32
32
|
|
33
33
|
def to_model_name(param)
|
@@ -56,8 +56,8 @@ module RailsAdmin
|
|
56
56
|
instance_eval(&RailsAdmin::Config.audit_with)
|
57
57
|
end
|
58
58
|
|
59
|
-
def
|
60
|
-
|
59
|
+
def rails_admin_controller?
|
60
|
+
true
|
61
61
|
end
|
62
62
|
|
63
63
|
rescue_from RailsAdmin::ObjectNotFound do
|
@@ -93,7 +93,7 @@ module RailsAdmin
|
|
93
93
|
return unless target_params.present?
|
94
94
|
fields = visible_fields(action, model_config)
|
95
95
|
allowed_methods = fields.collect(&:allowed_methods).flatten.uniq.collect(&:to_s) << 'id' << '_destroy'
|
96
|
-
fields.each { |field|
|
96
|
+
fields.each { |field| field.parse_input(target_params) }
|
97
97
|
target_params.slice!(*allowed_methods)
|
98
98
|
target_params.permit! if target_params.respond_to?(:permit!)
|
99
99
|
fields.select(&:nested_form).each do |association|
|
@@ -110,7 +110,7 @@ module RailsAdmin
|
|
110
110
|
|
111
111
|
respond_to do |format|
|
112
112
|
format.html { render whereto, status: :not_acceptable }
|
113
|
-
format.js { render whereto, layout: false, status: :not_acceptable
|
113
|
+
format.js { render whereto, layout: false, status: :not_acceptable }
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
@@ -47,8 +47,8 @@ module RailsAdmin
|
|
47
47
|
if defined?(Devise)
|
48
48
|
scope = Devise::Mapping.find_scope!(_current_user)
|
49
49
|
main_app.send("destroy_#{scope}_session_path") rescue false
|
50
|
-
|
51
|
-
main_app.logout_path
|
50
|
+
elsif main_app.respond_to?(:logout_path)
|
51
|
+
main_app.logout_path
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
@@ -20,10 +20,17 @@ module RailsAdmin
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def fieldset_for(fieldset, nested_in)
|
23
|
-
|
23
|
+
fields = fieldset.with(
|
24
|
+
form: self,
|
25
|
+
object: @object,
|
26
|
+
view: @template,
|
27
|
+
controller: @template.controller,
|
28
|
+
).visible_fields
|
29
|
+
return if fields.empty?
|
30
|
+
|
24
31
|
@template.content_tag :fieldset do
|
25
32
|
contents = []
|
26
|
-
contents << @template.content_tag(:legend, %(<i class="icon-chevron-#{(fieldset.active? ? 'down' : 'right')}"></i> #{fieldset.label}).html_safe, style:
|
33
|
+
contents << @template.content_tag(:legend, %(<i class="icon-chevron-#{(fieldset.active? ? 'down' : 'right')}"></i> #{fieldset.label}).html_safe, style: fieldset.name == :default ? 'display:none' : '')
|
27
34
|
contents << @template.content_tag(:p, fieldset.help) if fieldset.help.present?
|
28
35
|
contents << fields.collect { |field| field_wrapper_for(field, nested_in) }.join
|
29
36
|
contents.join.html_safe
|
@@ -63,7 +63,7 @@ module RailsAdmin
|
|
63
63
|
filter_name = filter_for_field.keys.first
|
64
64
|
filter_hash = filter_for_field.values.first
|
65
65
|
unless (field = filterable_fields.find { |f| f.name == filter_name.to_sym })
|
66
|
-
|
66
|
+
raise "#{filter_name} is not currently filterable; filterable fields are #{filterable_fields.map(&:name).join(', ')}"
|
67
67
|
end
|
68
68
|
case field.type
|
69
69
|
when :enum
|
@@ -3,6 +3,7 @@
|
|
3
3
|
%head
|
4
4
|
%meta{content: "IE=edge", "http-equiv" => "X-UA-Compatible"}
|
5
5
|
%meta{content: "text/html; charset=utf-8", "http-equiv" => "Content-Type"}
|
6
|
+
%meta{content: "width=device-width, initial-scale=1", name: "viewport; charset=utf-8"}
|
6
7
|
%meta{content: "NONE,NOARCHIVE", name: "robots"}
|
7
8
|
= csrf_meta_tag
|
8
9
|
= stylesheet_link_tag "rails_admin/rails_admin.css", media: :all
|
@@ -8,12 +8,17 @@
|
|
8
8
|
- else
|
9
9
|
= wording
|
10
10
|
%ul
|
11
|
-
- @abstract_model.each_associated_children(object) do |association,
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
=
|
18
|
-
|
19
|
-
=
|
11
|
+
- @abstract_model.each_associated_children(object) do |association, children|
|
12
|
+
- humanized_association = @abstract_model.model.human_attribute_name association.name
|
13
|
+
- limit = children.count > 12 ? 10 : children.count
|
14
|
+
- children.first(limit).each do |child|
|
15
|
+
= content_tag :li, class: dom_class(child) do
|
16
|
+
- child_config = RailsAdmin.config(child)
|
17
|
+
= humanized_association.singularize
|
18
|
+
- wording = child.send(child_config.object_label_method)
|
19
|
+
- if child.id && (show_action = action(:show, child_config.abstract_model, child))
|
20
|
+
= link_to(wording, url_for(action: show_action.action_name, model_name: child_config.abstract_model.to_param, id: child.id), class: 'pjax')
|
21
|
+
- else
|
22
|
+
= wording
|
23
|
+
- if children.count > limit
|
24
|
+
%li= t('admin.misc.more', count: children.count - limit, models_name: humanized_association)
|
@@ -51,9 +51,9 @@
|
|
51
51
|
.input-group
|
52
52
|
%input.form-control.input-small{name: "query", type: "search", value: query, placeholder: t("admin.misc.filter")}
|
53
53
|
%span.input-group-btn
|
54
|
-
%button.btn.btn-primary{type:
|
54
|
+
%button.btn.btn-primary{type: 'submit', :'data-disable-with' => '<i class="icon-white icon-refresh"></i> '.html_safe + t('admin.misc.refresh')}
|
55
55
|
%i.icon-white.icon-refresh
|
56
|
-
= t(
|
56
|
+
= t('admin.misc.refresh')
|
57
57
|
%button#remove_filter.btn.btn-info{title: "Reset filters"}
|
58
58
|
%i.icon-white.icon-remove
|
59
59
|
- if export_action
|
@@ -6,11 +6,11 @@ if defined?(::ActiveRecord)
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def rails_admin_default_object_label_method
|
9
|
-
|
9
|
+
new_record? ? "new #{self.class}" : "#{self.class} ##{id}"
|
10
10
|
end
|
11
11
|
|
12
12
|
def safe_send(value)
|
13
|
-
if
|
13
|
+
if has_attribute?(value)
|
14
14
|
read_attribute(value)
|
15
15
|
else
|
16
16
|
send(value)
|
@@ -87,12 +87,11 @@ module RailsAdmin
|
|
87
87
|
case association.type
|
88
88
|
when :has_one
|
89
89
|
if child = object.send(association.name)
|
90
|
-
yield(association, child)
|
90
|
+
yield(association, [child])
|
91
91
|
end
|
92
92
|
when :has_many
|
93
|
-
object.send(association.name)
|
94
|
-
|
95
|
-
end
|
93
|
+
children = object.send(association.name)
|
94
|
+
yield(association, Array.new(children))
|
96
95
|
end
|
97
96
|
end
|
98
97
|
end
|
@@ -147,7 +146,7 @@ module RailsAdmin
|
|
147
146
|
end
|
148
147
|
|
149
148
|
def build_statement_for_type
|
150
|
-
|
149
|
+
raise('You must override build_statement_for_type in your StatementBuilder')
|
151
150
|
end
|
152
151
|
|
153
152
|
def build_statement_for_integer_decimal_or_float
|
@@ -185,11 +184,11 @@ module RailsAdmin
|
|
185
184
|
end
|
186
185
|
|
187
186
|
def unary_operators
|
188
|
-
|
187
|
+
raise('You must override unary_operators in your StatementBuilder')
|
189
188
|
end
|
190
189
|
|
191
190
|
def range_filter(_min, _max)
|
192
|
-
|
191
|
+
raise('You must override range_filter in your StatementBuilder')
|
193
192
|
end
|
194
193
|
|
195
194
|
class FilteringDuration
|
@@ -6,7 +6,7 @@ require 'rails_admin/adapters/active_record/property'
|
|
6
6
|
module RailsAdmin
|
7
7
|
module Adapters
|
8
8
|
module ActiveRecord
|
9
|
-
DISABLED_COLUMN_TYPES = [:tsvector, :blob, :binary, :spatial, :hstore, :geometry]
|
9
|
+
DISABLED_COLUMN_TYPES = [:tsvector, :blob, :binary, :spatial, :hstore, :geometry].freeze
|
10
10
|
|
11
11
|
def new(params = {})
|
12
12
|
AbstractObject.new(model.new(params))
|
@@ -56,8 +56,8 @@ module RailsAdmin
|
|
56
56
|
def properties
|
57
57
|
columns = model.columns.reject do |c|
|
58
58
|
c.type.blank? ||
|
59
|
-
|
60
|
-
|
59
|
+
DISABLED_COLUMN_TYPES.include?(c.type.to_sym) ||
|
60
|
+
c.try(:array)
|
61
61
|
end
|
62
62
|
columns.collect do |property|
|
63
63
|
Property.new(property, model)
|
@@ -99,11 +99,12 @@ module RailsAdmin
|
|
99
99
|
|
100
100
|
def add(field, value, operator)
|
101
101
|
field.searchable_columns.flatten.each do |column_infos|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
102
|
+
value =
|
103
|
+
if value.is_a?(Array)
|
104
|
+
value.map { |v| field.parse_value(v) }
|
105
|
+
else
|
106
|
+
field.parse_value(value)
|
107
|
+
end
|
107
108
|
statement, value1, value2 = StatementBuilder.new(column_infos[:column], column_infos[:type], value, operator).to_statement
|
108
109
|
@statements << statement if statement.present?
|
109
110
|
@values << value1 unless value1.nil?
|
@@ -115,7 +116,7 @@ module RailsAdmin
|
|
115
116
|
|
116
117
|
def build
|
117
118
|
scope = @scope.where(@statements.join(' OR '), *@values)
|
118
|
-
scope = scope.references(
|
119
|
+
scope = scope.references(*@tables.uniq) if @tables.any?
|
119
120
|
scope
|
120
121
|
end
|
121
122
|
end
|
@@ -154,6 +155,17 @@ module RailsAdmin
|
|
154
155
|
protected
|
155
156
|
|
156
157
|
def unary_operators
|
158
|
+
case @type
|
159
|
+
when :boolean
|
160
|
+
boolean_unary_operators
|
161
|
+
else
|
162
|
+
generic_unary_operators
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
private
|
167
|
+
|
168
|
+
def generic_unary_operators
|
157
169
|
{
|
158
170
|
'_blank' => ["(#{@column} IS NULL OR #{@column} = '')"],
|
159
171
|
'_present' => ["(#{@column} IS NOT NULL AND #{@column} != '')"],
|
@@ -164,7 +176,14 @@ module RailsAdmin
|
|
164
176
|
}
|
165
177
|
end
|
166
178
|
|
167
|
-
|
179
|
+
def boolean_unary_operators
|
180
|
+
generic_unary_operators.merge(
|
181
|
+
'_blank' => ["(#{@column} IS NULL)"],
|
182
|
+
'_empty' => ["(#{@column} IS NULL)"],
|
183
|
+
'_present' => ["(#{@column} IS NOT NULL)"],
|
184
|
+
'_not_empty' => ["(#{@column} IS NOT NULL)"],
|
185
|
+
)
|
186
|
+
end
|
168
187
|
|
169
188
|
def range_filter(min, max)
|
170
189
|
if min && max
|
@@ -211,7 +230,7 @@ module RailsAdmin
|
|
211
230
|
when 'ends_with'
|
212
231
|
"%#{@value.downcase}"
|
213
232
|
when 'is', '='
|
214
|
-
|
233
|
+
@value.downcase
|
215
234
|
else
|
216
235
|
return
|
217
236
|
end
|
@@ -8,7 +8,7 @@ require 'rails_admin/adapters/mongoid/bson'
|
|
8
8
|
module RailsAdmin
|
9
9
|
module Adapters
|
10
10
|
module Mongoid
|
11
|
-
DISABLED_COLUMN_TYPES = %w(Range Moped::BSON::Binary BSON::Binary Mongoid::Geospatial::Point)
|
11
|
+
DISABLED_COLUMN_TYPES = %w(Range Moped::BSON::Binary BSON::Binary Mongoid::Geospatial::Point).freeze
|
12
12
|
|
13
13
|
def parse_object_id(value)
|
14
14
|
Bson.parse_object_id(value)
|
@@ -190,7 +190,7 @@ module RailsAdmin
|
|
190
190
|
when String
|
191
191
|
field_name, collection_name = options[:sort].split('.').reverse
|
192
192
|
if collection_name && collection_name != table_name
|
193
|
-
|
193
|
+
raise('sorting by associated model column is not supported in Non-Relational databases')
|
194
194
|
end
|
195
195
|
when Symbol
|
196
196
|
field_name = options[:sort].to_s
|
@@ -28,7 +28,7 @@ module RailsAdmin
|
|
28
28
|
when :has_and_belongs_to_many, :references_and_referenced_in_many
|
29
29
|
:has_and_belongs_to_many
|
30
30
|
else
|
31
|
-
|
31
|
+
raise("Unknown association type: #{macro.inspect}")
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -83,7 +83,7 @@ module RailsAdmin
|
|
83
83
|
def nested_options
|
84
84
|
nested = nested_attributes_options.try { |o| o[name] }
|
85
85
|
if !nested && [:embeds_one, :embeds_many].include?(macro.to_sym) && !association.cyclic
|
86
|
-
|
86
|
+
raise <<-MSG.gsub(/^\s+/, '')
|
87
87
|
Embbeded association without accepts_nested_attributes_for can't be handled by RailsAdmin,
|
88
88
|
because embedded model doesn't have top-level access.
|
89
89
|
Please add `accepts_nested_attributes_for :#{association.name}' line to `#{model}' model.
|
@@ -14,15 +14,13 @@ module RailsAdmin
|
|
14
14
|
require 'sass-rails' if rails?
|
15
15
|
|
16
16
|
unless rails? || compass?
|
17
|
-
|
17
|
+
raise(Bootstrap::FrameworkNotFound.new('bootstrap-sass requires either Rails > 3.1 or Compass, neither of which are loaded'))
|
18
18
|
end
|
19
19
|
|
20
20
|
stylesheets = File.expand_path(File.join('..', 'vendor', 'assets', 'stylesheets'))
|
21
21
|
::Sass.load_paths << stylesheets
|
22
22
|
end
|
23
23
|
|
24
|
-
private
|
25
|
-
|
26
24
|
def self.asset_pipeline?
|
27
25
|
defined?(::Sprockets)
|
28
26
|
end
|
@@ -8,7 +8,7 @@ module Sass
|
|
8
8
|
image_url(source, Sass::Script::Bool.new(true))
|
9
9
|
else
|
10
10
|
# Revert to the old compass-agnostic path determination
|
11
|
-
asset_sans_quotes = source.value.
|
11
|
+
asset_sans_quotes = source.value.delete('"')
|
12
12
|
Sass::Script::String.new("/images/#{asset_sans_quotes}", :string)
|
13
13
|
end
|
14
14
|
end
|
data/lib/rails_admin/config.rb
CHANGED
@@ -110,11 +110,13 @@ module RailsAdmin
|
|
110
110
|
def audit_with(*args, &block)
|
111
111
|
extension = args.shift
|
112
112
|
if extension
|
113
|
+
klass = RailsAdmin::AUDITING_ADAPTERS[extension]
|
114
|
+
klass.setup if klass.respond_to? :setup
|
113
115
|
@audit = proc do
|
114
|
-
@auditing_adapter =
|
116
|
+
@auditing_adapter = klass.new(*([self] + args).compact)
|
115
117
|
end
|
116
|
-
|
117
|
-
@audit = block
|
118
|
+
elsif block
|
119
|
+
@audit = block
|
118
120
|
end
|
119
121
|
@audit || DEFAULT_AUDIT
|
120
122
|
end
|
@@ -145,11 +147,13 @@ module RailsAdmin
|
|
145
147
|
def authorize_with(*args, &block)
|
146
148
|
extension = args.shift
|
147
149
|
if extension
|
150
|
+
klass = RailsAdmin::AUTHORIZATION_ADAPTERS[extension]
|
151
|
+
klass.setup if klass.respond_to? :setup
|
148
152
|
@authorize = proc do
|
149
|
-
@authorization_adapter =
|
153
|
+
@authorization_adapter = klass.new(*([self] + args).compact)
|
150
154
|
end
|
151
|
-
|
152
|
-
@authorize = block
|
155
|
+
elsif block
|
156
|
+
@authorize = block
|
153
157
|
end
|
154
158
|
@authorize || DEFAULT_AUTHORIZE
|
155
159
|
end
|
@@ -193,7 +197,7 @@ module RailsAdmin
|
|
193
197
|
if %w(default like starts_with ends_with is =).include? operator
|
194
198
|
@default_search_operator = operator
|
195
199
|
else
|
196
|
-
|
200
|
+
raise(ArgumentError.new("Search operator '#{operator}' not supported"))
|
197
201
|
end
|
198
202
|
end
|
199
203
|
|
@@ -283,7 +287,7 @@ module RailsAdmin
|
|
283
287
|
@show_gravatar = true
|
284
288
|
@navigation_static_links = {}
|
285
289
|
@navigation_static_label = nil
|
286
|
-
@parent_controller = '::
|
290
|
+
@parent_controller = '::ActionController::Base'
|
287
291
|
RailsAdmin::Config::Actions.reset
|
288
292
|
end
|
289
293
|
|
@@ -96,7 +96,7 @@ module RailsAdmin
|
|
96
96
|
action.instance_eval(&block) if block
|
97
97
|
@@actions ||= []
|
98
98
|
if action.custom_key.in?(@@actions.collect(&:custom_key))
|
99
|
-
|
99
|
+
raise "Action #{action.custom_key} already exists. Please change its custom key."
|
100
100
|
else
|
101
101
|
@@actions << action
|
102
102
|
end
|
@@ -115,12 +115,11 @@ module RailsAdmin
|
|
115
115
|
|
116
116
|
# Breadcrumb parent
|
117
117
|
register_instance_option :breadcrumb_parent do
|
118
|
-
|
119
|
-
when root?
|
118
|
+
if root?
|
120
119
|
[:dashboard]
|
121
|
-
|
120
|
+
elsif collection?
|
122
121
|
[:index, bindings[:abstract_model]]
|
123
|
-
|
122
|
+
elsif member?
|
124
123
|
[:show, bindings[:abstract_model], bindings[:object]]
|
125
124
|
end
|
126
125
|
end
|