rails_admin 0.1.2 → 0.2.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.
- data/Gemfile +18 -20
- data/README.md +8 -1
- data/app/assets/javascripts/rails_admin/ra.widgets.coffee +5 -4
- data/app/assets/stylesheets/rails_admin/base/theming.css.scss +4 -4
- data/app/controllers/rails_admin/main_controller.rb +11 -2
- data/app/helpers/rails_admin/application_helper.rb +1 -1
- data/app/helpers/rails_admin/form_builder.rb +3 -3
- data/app/views/rails_admin/main/_form_filtering_multiselect.html.haml +4 -4
- data/app/views/rails_admin/main/_form_filtering_select.html.haml +2 -2
- data/app/views/rails_admin/main/_form_nested_one.html.haml +1 -1
- data/app/views/rails_admin/main/_form_text.html.haml +2 -1
- data/app/views/rails_admin/main/export.html.haml +2 -2
- data/app/views/rails_admin/main/index.html.haml +5 -5
- data/app/views/rails_admin/main/show.html.haml +1 -1
- data/lib/generators/rails_admin/templates/initializer.erb +5 -5
- data/lib/rails_admin/abstract_model.rb +1 -0
- data/lib/rails_admin/config.rb +1 -1
- data/lib/rails_admin/config/actions/base.rb +1 -1
- data/lib/rails_admin/config/actions/edit.rb +5 -4
- data/lib/rails_admin/config/actions/new.rb +5 -4
- data/lib/rails_admin/config/fields/association.rb +10 -10
- data/lib/rails_admin/config/fields/base.rb +10 -4
- data/lib/rails_admin/config/fields/types/belongs_to_association.rb +2 -2
- data/lib/rails_admin/config/fields/types/boolean.rb +4 -4
- data/lib/rails_admin/config/fields/types/bson_object_id.rb +4 -4
- data/lib/rails_admin/config/fields/types/carrierwave.rb +3 -3
- data/lib/rails_admin/config/fields/types/datetime.rb +5 -5
- data/lib/rails_admin/config/fields/types/enum.rb +5 -5
- data/lib/rails_admin/config/fields/types/file_upload.rb +10 -6
- data/lib/rails_admin/config/fields/types/has_many_association.rb +1 -1
- data/lib/rails_admin/config/fields/types/has_one_association.rb +3 -3
- data/lib/rails_admin/config/fields/types/integer.rb +1 -1
- data/lib/rails_admin/config/fields/types/paperclip.rb +2 -2
- data/lib/rails_admin/config/fields/types/polymorphic_association.rb +8 -4
- data/lib/rails_admin/config/fields/types/serialized.rb +2 -2
- data/lib/rails_admin/config/fields/types/string.rb +3 -3
- data/lib/rails_admin/config/fields/types/text.rb +22 -15
- data/lib/rails_admin/config/fields/types/time.rb +1 -1
- data/lib/rails_admin/config/hideable.rb +1 -1
- data/lib/rails_admin/config/model.rb +4 -0
- data/lib/rails_admin/config/sections/modal.rb +1 -1
- data/lib/rails_admin/engine.rb +1 -1
- data/lib/rails_admin/extensions/paper_trail/auditing_adapter.rb +2 -1
- data/lib/rails_admin/support/csv_converter.rb +1 -1
- data/lib/rails_admin/version.rb +2 -2
- data/lib/rails_admin/version.rbc +582 -0
- data/lib/tasks/rails_admin.rake +2 -2
- data/spec/controllers/main_controller_spec.rb +113 -45
- data/spec/dummy_app/Gemfile +11 -25
- data/spec/dummy_app/Gemfile.lock +214 -0
- data/spec/dummy_app/app/active_record/comment.rb +1 -1
- data/spec/dummy_app/app/active_record/field_test.rb +0 -1
- data/spec/dummy_app/config/initializers/strong_parameters.rb +2 -0
- data/spec/dummy_app/db/test.sqlite3 +0 -0
- data/spec/dummy_app/log/test.log +97612 -0
- data/spec/helpers/application_helper_spec.rb +24 -24
- data/spec/helpers/form_builder_spec.rb +4 -4
- data/spec/integration/authorization/cancan_spec.rb +3 -3
- data/spec/integration/basic/bulk_action/rails_admin_basic_bulk_action_spec.rb +2 -2
- data/spec/integration/basic/bulk_destroy/rails_admin_basic_bulk_destroy_spec.rb +2 -2
- data/spec/integration/basic/create/rails_admin_basic_create_spec.rb +9 -9
- data/spec/integration/basic/create/rails_admin_namespaced_model_create_spec.rb +1 -1
- data/spec/integration/basic/delete/rails_admin_basic_delete_spec.rb +4 -4
- data/spec/integration/basic/destroy/rails_admin_basic_destroy_spec.rb +9 -9
- data/spec/integration/basic/edit/rails_admin_basic_edit_spec.rb +10 -10
- data/spec/integration/basic/export/rails_admin_basic_export_spec.rb +5 -5
- data/spec/integration/basic/list/rails_admin_basic_list_spec.rb +32 -25
- data/spec/integration/basic/new/rails_admin_basic_new_spec.rb +8 -8
- data/spec/integration/basic/new/rails_admin_namespaced_model_new_spec.rb +3 -3
- data/spec/integration/basic/show/rails_admin_basic_show_spec.rb +6 -6
- data/spec/integration/basic/update/rails_admin_basic_update_spec.rb +13 -13
- data/spec/integration/config/edit/rails_admin_config_edit_spec.rb +97 -76
- data/spec/integration/config/list/rails_admin_config_list_spec.rb +32 -32
- data/spec/integration/config/show/rails_admin_config_show_spec.rb +23 -23
- data/spec/integration/history/rails_admin_history_spec.rb +6 -6
- data/spec/integration/rails_admin_spec.rb +17 -17
- data/spec/integration/relation_spec.rb +7 -7
- data/spec/unit/abstract_model_spec.rb +11 -5
- data/spec/unit/active_record_extension_spec.rb +2 -2
- data/spec/unit/adapters/active_record/abstract_object_spec.rb +8 -8
- data/spec/unit/adapters/active_record_spec.rb +6 -6
- data/spec/unit/adapters/mongoid/abstract_object_spec.rb +1 -1
- data/spec/unit/adapters/mongoid_spec.rb +12 -12
- data/spec/unit/config/actions/base_spec.rb +2 -2
- data/spec/unit/config/actions_spec.rb +16 -16
- data/spec/unit/config/fields/base_spec.rb +61 -49
- data/spec/unit/config/fields/date_spec.rb +4 -4
- data/spec/unit/config/fields/datetime_spec.rb +4 -4
- data/spec/unit/config/fields/file_upload_spec.rb +21 -0
- data/spec/unit/config/fields/time_spec.rb +3 -3
- data/spec/unit/config/fields/timestamp_spec.rb +1 -1
- data/spec/unit/config/model_spec.rb +10 -10
- data/spec/unit/config/sections_spec.rb +4 -4
- data/spec/unit/config_spec.rb +9 -9
- metadata +17 -218
data/Gemfile
CHANGED
|
@@ -1,21 +1,9 @@
|
|
|
1
1
|
source 'https://rubygems.org'
|
|
2
2
|
|
|
3
|
-
# Bundle gems for the local environment. Make sure to
|
|
4
|
-
# put test-only gems in this group so their generators
|
|
5
|
-
# and rake tasks are available in development mode:
|
|
6
3
|
group :active_record do
|
|
7
4
|
platforms :jruby do
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
gem 'activerecord-jdbcmysql-adapter', '~> 1.2'
|
|
11
|
-
gem 'jdbc-mysql', '~> 5.1'
|
|
12
|
-
when 'postgresql'
|
|
13
|
-
gem 'activerecord-jdbcpostgresql-adapter', '~> 1.2'
|
|
14
|
-
gem 'jdbc-postgres', '~> 9.0'
|
|
15
|
-
else
|
|
16
|
-
gem 'activerecord-jdbcsqlite3-adapter', '~> 1.2'
|
|
17
|
-
gem 'jdbc-sqlite3', '~> 3.6'
|
|
18
|
-
end
|
|
5
|
+
gem 'activerecord-jdbcsqlite3-adapter', '~> 1.2'
|
|
6
|
+
gem 'jdbc-sqlite3', '~> 3.6'
|
|
19
7
|
end
|
|
20
8
|
|
|
21
9
|
platforms :ruby, :mswin, :mingw do
|
|
@@ -28,7 +16,6 @@ group :active_record do
|
|
|
28
16
|
gem 'sqlite3', '~> 1.3'
|
|
29
17
|
end
|
|
30
18
|
end
|
|
31
|
-
gem 'carrierwave'
|
|
32
19
|
end
|
|
33
20
|
|
|
34
21
|
group :mongoid do
|
|
@@ -39,15 +26,26 @@ end
|
|
|
39
26
|
|
|
40
27
|
group :debug do
|
|
41
28
|
platform :mri_19 do
|
|
42
|
-
gem 'debugger'
|
|
43
|
-
gem 'simplecov', :require => false
|
|
29
|
+
gem 'debugger', '~> 1.2'
|
|
30
|
+
gem 'simplecov', '~> 0.6', :require => false
|
|
44
31
|
end
|
|
45
32
|
end
|
|
46
33
|
|
|
47
34
|
group :development, :test do
|
|
48
|
-
gem '
|
|
49
|
-
gem '
|
|
50
|
-
gem '
|
|
35
|
+
gem 'strong_parameters', '~> 0.1.5'
|
|
36
|
+
gem 'cancan', '~> 1.6'
|
|
37
|
+
gem 'capybara', '~> 1.1'
|
|
38
|
+
gem 'carrierwave', '~> 0.6'
|
|
39
|
+
gem 'database_cleaner', '~> 0.8'
|
|
40
|
+
gem 'devise', '~> 2.1'
|
|
41
|
+
gem 'dragonfly', '~> 0.9'
|
|
42
|
+
gem 'factory_girl', '~> 4.1'
|
|
43
|
+
gem 'generator_spec', '~> 0.8'
|
|
44
|
+
gem 'launchy', '~> 2.1'
|
|
45
|
+
gem 'mini_magick', '~> 3.4'
|
|
46
|
+
gem 'paperclip', '~> 3.3'
|
|
47
|
+
gem 'rspec-rails', '~> 2.11'
|
|
48
|
+
gem 'timecop', '~> 0.5'
|
|
51
49
|
end
|
|
52
50
|
|
|
53
51
|
gemspec
|
data/README.md
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
# RailsAdmin
|
|
1
|
+
# RailsAdmin
|
|
2
|
+
[][travis]
|
|
3
|
+
[][gemnasium]
|
|
4
|
+
[][codeclimate]
|
|
5
|
+
[][pledgie]
|
|
6
|
+
[][flattr]
|
|
7
|
+
|
|
2
8
|
RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data.
|
|
3
9
|
|
|
4
10
|
[travis]: http://travis-ci.org/sferik/rails_admin
|
|
5
11
|
[gemnasium]: https://gemnasium.com/sferik/rails_admin
|
|
6
12
|
[codeclimate]: https://codeclimate.com/github/sferik/rails_admin
|
|
7
13
|
[pledgie]: http://www.pledgie.com/campaigns/15917
|
|
14
|
+
[flattr]: http://flattr.com/thing/799416/sferikrailsadmin-on-GitHub
|
|
8
15
|
|
|
9
16
|
It started as a port of [MerbAdmin][merb-admin] to Rails 3 and was implemented
|
|
10
17
|
as a [Ruby Summer of Code project][rubysoc] by [Bogdan Gaza][hurrycane] with
|
|
@@ -191,19 +191,20 @@ $(document).live 'rails_admin.dom_ready', ->
|
|
|
191
191
|
|
|
192
192
|
# bootstrap_wysihtml5
|
|
193
193
|
|
|
194
|
-
goBootstrapWysihtml5s = (array) =>
|
|
194
|
+
goBootstrapWysihtml5s = (array, config_options) =>
|
|
195
195
|
array.each ->
|
|
196
196
|
$(@).addClass('bootstrap-wysihtml5ed')
|
|
197
197
|
$(@).closest('.controls').addClass('well')
|
|
198
|
-
$(@).wysihtml5()
|
|
198
|
+
$(@).wysihtml5(config_options)
|
|
199
199
|
|
|
200
200
|
array = $('form [data-richtext=bootstrap-wysihtml5]').not('.bootstrap-wysihtml5ed')
|
|
201
201
|
if array.length
|
|
202
202
|
@array = array
|
|
203
203
|
if not window.wysihtml5
|
|
204
204
|
options = $(array[0]).data('options')
|
|
205
|
+
config_options = $.parseJSON(options['config_options'])
|
|
205
206
|
$('head').append('<link href="' + options['csspath'] + '" rel="stylesheet" media="all" type="text\/css">')
|
|
206
207
|
$.getScript options['jspath'], (script, textStatus, jqXHR) =>
|
|
207
|
-
goBootstrapWysihtml5s(@array)
|
|
208
|
+
goBootstrapWysihtml5s(@array, config_options)
|
|
208
209
|
else
|
|
209
|
-
goBootstrapWysihtml5s(@array)
|
|
210
|
+
goBootstrapWysihtml5s(@array, config_options)
|
|
@@ -102,7 +102,7 @@ body.rails_admin {
|
|
|
102
102
|
margin-left:-10px;
|
|
103
103
|
.control-group > label {
|
|
104
104
|
padding-left:10px;
|
|
105
|
-
width:
|
|
105
|
+
width:135px;
|
|
106
106
|
}
|
|
107
107
|
legend {
|
|
108
108
|
float:left;
|
|
@@ -119,7 +119,7 @@ body.rails_admin {
|
|
|
119
119
|
margin-left:-20px;
|
|
120
120
|
.control-group > label {
|
|
121
121
|
padding-left:20px;
|
|
122
|
-
width:
|
|
122
|
+
width:125px;
|
|
123
123
|
}
|
|
124
124
|
legend {
|
|
125
125
|
margin-left:20px;
|
|
@@ -135,7 +135,7 @@ body.rails_admin {
|
|
|
135
135
|
margin-left:-30px;
|
|
136
136
|
.control-group > label {
|
|
137
137
|
padding-left:30px;
|
|
138
|
-
width:
|
|
138
|
+
width:115px;
|
|
139
139
|
}
|
|
140
140
|
legend {
|
|
141
141
|
margin-left:30px;
|
|
@@ -151,7 +151,7 @@ body.rails_admin {
|
|
|
151
151
|
margin-left:-40px;
|
|
152
152
|
.control-group > label {
|
|
153
153
|
padding-left:40px;
|
|
154
|
-
width:
|
|
154
|
+
width:105px;
|
|
155
155
|
}
|
|
156
156
|
legend {
|
|
157
157
|
margin-left:40px;
|
|
@@ -87,11 +87,20 @@ module RailsAdmin
|
|
|
87
87
|
end
|
|
88
88
|
end
|
|
89
89
|
|
|
90
|
+
def satisfy_strong_params!
|
|
91
|
+
if @abstract_model.model.ancestors.map(&:to_s).include?('ActiveModel::ForbiddenAttributesProtection')
|
|
92
|
+
params[@abstract_model.param_key].try :permit!
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
90
96
|
def sanitize_params_for!(action, model_config = @model_config, _params = params[@abstract_model.param_key])
|
|
91
97
|
return unless _params.present?
|
|
92
|
-
fields = model_config.send(action).
|
|
98
|
+
fields = model_config.send(action).with(:controller => self, :view => self.view_context, :object => @object).visible_fields
|
|
99
|
+
allowed_methods = fields.map{|f|
|
|
100
|
+
f.allowed_methods
|
|
101
|
+
}.flatten.uniq.map(&:to_s) << "id" << "_destroy"
|
|
93
102
|
fields.select{ |f| f.respond_to?(:parse_input) }.each {|f| f.parse_input(_params) }
|
|
94
|
-
|
|
103
|
+
_params.slice!(*allowed_methods)
|
|
95
104
|
fields.select(&:nested_form).each do |association|
|
|
96
105
|
children_params = association.multiple? ? _params[association.method_name].try(:values) : [_params[association.method_name]].compact
|
|
97
106
|
(children_params || []).each do |children_param|
|
|
@@ -70,7 +70,7 @@ module RailsAdmin
|
|
|
70
70
|
nodes.map do |node|
|
|
71
71
|
model_param = node.abstract_model.to_param
|
|
72
72
|
url = url_for(:action => :index, :controller => 'rails_admin/main', :model_name => model_param)
|
|
73
|
-
level_class = "nav-level-#{level}" if level > 0
|
|
73
|
+
level_class = " nav-level-#{level}" if level > 0
|
|
74
74
|
|
|
75
75
|
li = content_tag :li, "data-model"=>model_param do
|
|
76
76
|
link_to node.label_plural, url, :class => "pjax#{level_class}"
|
|
@@ -18,7 +18,7 @@ module RailsAdmin
|
|
|
18
18
|
action = options[:action]
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
groups = options[:model_config].send(action).with(:form => self, :object => @object, :view => @template).visible_groups
|
|
21
|
+
groups = options[:model_config].send(action).with(:form => self, :object => @object, :view => @template, :controller => @template.controller).visible_groups
|
|
22
22
|
|
|
23
23
|
object_infos +
|
|
24
24
|
groups.map do |fieldset|
|
|
@@ -29,7 +29,7 @@ module RailsAdmin
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def fieldset_for fieldset, nested_in
|
|
32
|
-
if (fields = fieldset.with(:form => self, :object => @object, :view => @template).visible_fields).length > 0
|
|
32
|
+
if (fields = fieldset.with(:form => self, :object => @object, :view => @template, :controller => @template.controller).visible_fields).length > 0
|
|
33
33
|
@template.content_tag :fieldset do
|
|
34
34
|
contents = []
|
|
35
35
|
contents << @template.content_tag(:legend, %{<i class="icon-chevron-#{(fieldset.active? ? 'down' : 'right')}"></i> #{fieldset.label}}.html_safe, :style => "#{fieldset.name == :default ? 'display:none' : ''}")
|
|
@@ -102,7 +102,7 @@ module RailsAdmin
|
|
|
102
102
|
def dom_name field
|
|
103
103
|
(@dom_name ||= {})[field.name] ||= %{#{@object_name}#{options[:index] && "[#{options[:index]}]"}[#{field.method_name}]#{field.is_a?(Config::Fields::Association) && field.multiple? ? '[]' : ''}}
|
|
104
104
|
end
|
|
105
|
-
|
|
105
|
+
|
|
106
106
|
protected
|
|
107
107
|
def without_field_error_proc_added_div
|
|
108
108
|
default_field_error_proc = ::ActionView::Base.field_error_proc
|
|
@@ -11,16 +11,16 @@
|
|
|
11
11
|
selected_ids = selected.map{|s| s.send(field.associated_primary_key)}
|
|
12
12
|
|
|
13
13
|
current_action = params[:action].in?(['create', 'new']) ? 'create' : 'update'
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
xhr = !field.associated_collection_cache_all
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
collection = if xhr
|
|
18
18
|
selected.map { |o| [o.send(field.associated_object_label_method), o.send(field.associated_primary_key)] }
|
|
19
19
|
else
|
|
20
20
|
i = 0
|
|
21
21
|
controller.list_entries(config, :index, field.associated_collection_scope, false).map { |o| [o.send(field.associated_object_label_method), o.send(field.associated_primary_key)] }.sort_by {|a| [selected_ids.index(a[1]) || selected_ids.size, i+=1] }
|
|
22
22
|
end
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
js_data = {
|
|
25
25
|
:xhr => xhr,
|
|
26
26
|
:'edit-url' => (authorized?(:edit, config.abstract_model) ? edit_path(:model_name => config.abstract_model.to_param, :id => '__ID__') : ''),
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
:down => t("admin.misc.down")
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
%input{:name => form.dom_name(field), :type => "hidden", :value => ""}
|
|
41
41
|
|
|
42
42
|
- selected_ids = (hdv = field.html_default_value).nil? ? selected_ids : hdv
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
edit_url = authorized?(:edit, config.abstract_model) ? edit_path(:model_name => config.abstract_model.to_param, :modal => true, :id => '__ID__') : ''
|
|
18
18
|
|
|
19
19
|
xhr = !field.associated_collection_cache_all
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
collection = xhr ? [[selected_name, selected_id]] : controller.list_entries(config, :index, field.associated_collection_scope, false).map { |o| [o.send(field.associated_object_label_method), o.send(field.associated_primary_key)] }
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
js_data = {
|
|
24
24
|
:xhr => xhr,
|
|
25
25
|
:remote_source => index_path(config.abstract_model.to_param, :source_object_id => form.object.id, :source_abstract_model => source_abstract_model.to_param, :associated_collection => field.name, :current_action => current_action, :compact => true)
|
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
- form.object.send("build_#{field.name}") unless form.object.send(field.name)
|
|
8
8
|
.tab-content
|
|
9
9
|
= form.fields_for field.name do |nested_form|
|
|
10
|
-
= nested_form.generate({:action => :nested, :model_config => field.associated_model_config, :nested_in => field.name })
|
|
10
|
+
= nested_form.generate({:action => :nested, :model_config => field.associated_model_config, :nested_in => field.name })
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
richtext = 'bootstrap-wysihtml5'
|
|
21
21
|
js_data = {
|
|
22
22
|
:csspath => field.bootstrap_wysihtml5_css_location,
|
|
23
|
-
:jspath => field.bootstrap_wysihtml5_js_location
|
|
23
|
+
:jspath => field.bootstrap_wysihtml5_js_location,
|
|
24
|
+
:config_options => field.bootstrap_wysihtml5_config_options.to_json
|
|
24
25
|
}
|
|
25
26
|
else
|
|
26
27
|
richtext = false
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
- params = request.params.except(:action, :controller, :utf8, :page, :per_page, :format, :authenticity_token)
|
|
2
|
-
- visible_fields = @model_config.export.with(:view => self, :object => @abstract_model.model.new).visible_fields
|
|
2
|
+
- visible_fields = @model_config.export.with(:view => self, :object => @abstract_model.model.new, :controller => self.controller).visible_fields
|
|
3
3
|
|
|
4
4
|
= form_tag export_path(params.merge(:all => true)), :method => 'post', :class => 'form-horizontal denser' do
|
|
5
5
|
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
= field.label
|
|
28
28
|
|
|
29
29
|
- visible_fields.select{ |f| f.association? && !f.association[:polymorphic] }.each do |field|
|
|
30
|
-
- fields = field.associated_model_config.export.with(:view => self, :object => (associated_model = field.associated_model_config.abstract_model.model).new).visible_fields.select{ |f| !f.association? }
|
|
30
|
+
- fields = field.associated_model_config.export.with(:controller => self.controller, :view => self, :object => (associated_model = field.associated_model_config.abstract_model.model).new).visible_fields.select{ |f| !f.association? }
|
|
31
31
|
.control-group
|
|
32
32
|
%label.control-label{:rel => 'tooltip', :'data-original-title' => t('admin.export.click_to_reverse_selection'), :onclick => 'jQuery(this).siblings(".controls").find("input").click()'}= t('admin.export.fields_from_associated', :name => field.label.downcase)
|
|
33
33
|
.controls
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
export_action = RailsAdmin::Config::Actions.find(:export, { :controller => self.controller, :abstract_model => @abstract_model })
|
|
12
12
|
export_action = export_action && authorized?(export_action.authorization_key, @abstract_model) ? export_action : nil
|
|
13
13
|
|
|
14
|
-
properties = @model_config.list.with(:view => self, :object => @abstract_model.model.new).visible_fields
|
|
14
|
+
properties = @model_config.list.with(:controller => self.controller, :view => self, :object => @abstract_model.model.new).visible_fields
|
|
15
15
|
# columns paginate
|
|
16
16
|
@filterable_fields = @model_config.list.fields.select(&:filterable?)
|
|
17
17
|
sets = get_column_sets(properties)
|
|
@@ -80,9 +80,9 @@
|
|
|
80
80
|
monthNamesShort: #{raw RailsAdmin::Config::Fields::Types::Datetime.abbr_month_names.to_json}
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
-
|
|
83
|
+
|
|
84
84
|
= @ordered_filter_string
|
|
85
|
-
|
|
85
|
+
|
|
86
86
|
});
|
|
87
87
|
%style
|
|
88
88
|
- properties.select{ |p| p.column_width.present? }.each do |property|
|
|
@@ -135,6 +135,6 @@
|
|
|
135
135
|
- total_count = @objects.total_count.to_i
|
|
136
136
|
= paginate(@objects, :theme => 'twitter-bootstrap', :remote => true)
|
|
137
137
|
= link_to(t("admin.misc.show_all"), index_path(params.merge(:all => true)), :class => "show-all btn clearfix pjax") unless total_count > 100 || total_count <= @objects.to_a.size
|
|
138
|
-
.clearfix.total-count= "#{total_count} #{@model_config.
|
|
138
|
+
.clearfix.total-count= "#{total_count} #{@model_config.pluralize(total_count).downcase}"
|
|
139
139
|
- else
|
|
140
|
-
.clearfix.total-count= "#{@objects.size} #{@model_config.
|
|
140
|
+
.clearfix.total-count= "#{@objects.size} #{@model_config.pluralize(@objects.size).downcase}"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
- @model_config.show.with(:object => @object, :view => self).visible_groups.each do |fieldset|
|
|
2
|
-
- unless (fields = fieldset.with(:object => @object, :view => self).visible_fields).empty?
|
|
2
|
+
- unless (fields = fieldset.with(:object => @object, :view => self, :controller => self.controller).visible_fields).empty?
|
|
3
3
|
- if !(values = fields.map{ |f| v = f.value; (!v.nil? && v != '' && v != []) ? v : nil }).compact.empty? || !RailsAdmin::config.compact_show_view
|
|
4
4
|
.fieldset
|
|
5
5
|
%h4
|
|
@@ -41,7 +41,7 @@ RailsAdmin.config do |config|
|
|
|
41
41
|
# Each model configuration can alternatively:
|
|
42
42
|
# - stay here in a `config.model 'ModelName' do ... end` block
|
|
43
43
|
# - go in the model definition file in a `rails_admin do ... end` block
|
|
44
|
-
|
|
44
|
+
|
|
45
45
|
# This is your choice to make:
|
|
46
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
47
|
# - Models are reloaded at each request in development mode (when modified), which may smooth your RailsAdmin development workflow.
|
|
@@ -58,7 +58,7 @@ RailsAdmin.config do |config|
|
|
|
58
58
|
# config.model '<%= abstract_model.model.model_name %>' do
|
|
59
59
|
|
|
60
60
|
# # You can copy this to a 'rails_admin do ... end' block inside your <%= abstract_model.model.model_name.underscore %>.rb model definition
|
|
61
|
-
|
|
61
|
+
|
|
62
62
|
# # Found associations:
|
|
63
63
|
|
|
64
64
|
<%= abstract_model.config.export.fields.select{|f| f.association?}.map do |field|
|
|
@@ -72,16 +72,16 @@ end.join("\n") %>
|
|
|
72
72
|
end.join("\n") %>
|
|
73
73
|
|
|
74
74
|
# # Cross-section configuration:
|
|
75
|
-
|
|
75
|
+
|
|
76
76
|
# # object_label_method :name # Name of the method called for pretty printing an *instance* of ModelName
|
|
77
77
|
# # label 'My model' # Name of ModelName (smartly defaults to ActiveRecord's I18n API)
|
|
78
78
|
# # label_plural 'My models' # Same, plural
|
|
79
79
|
# # weight 0 # Navigation priority. Bigger is higher.
|
|
80
80
|
# # parent OtherModel # Set parent model for navigation. MyModel will be nested below. OtherModel will be on first position of the dropdown
|
|
81
81
|
# # navigation_label # Sets dropdown entry's name in navigation. Only for parents!
|
|
82
|
-
|
|
82
|
+
|
|
83
83
|
# # Section specific configuration:
|
|
84
|
-
|
|
84
|
+
|
|
85
85
|
# list do
|
|
86
86
|
# # filters [:id, :name] # Array of field names which filters should be shown by default in the table header
|
|
87
87
|
# # items_per_page 100 # Override default_items_per_page
|
|
@@ -18,6 +18,7 @@ module RailsAdmin
|
|
|
18
18
|
m = m.is_a?(Class) ? m : m.constantize
|
|
19
19
|
(am = old_new(m)).model && am.adapter ? am : nil
|
|
20
20
|
rescue LoadError, NameError
|
|
21
|
+
puts "[RailsAdmin] Could not load model #{m}, assuming model is non existing. (#{$!})" unless Rails.env.test?
|
|
21
22
|
nil
|
|
22
23
|
end
|
|
23
24
|
|
data/lib/rails_admin/config.rb
CHANGED
|
@@ -69,7 +69,7 @@ module RailsAdmin
|
|
|
69
69
|
# accepts a hash of static links to be shown below the main navigation
|
|
70
70
|
attr_accessor :navigation_static_links
|
|
71
71
|
attr_accessor :navigation_static_label
|
|
72
|
-
|
|
72
|
+
|
|
73
73
|
# yell about fields that are not marked as accessible
|
|
74
74
|
attr_accessor :yell_for_non_accessible_fields
|
|
75
75
|
|
|
@@ -28,9 +28,10 @@ module RailsAdmin
|
|
|
28
28
|
@modified_assoc = []
|
|
29
29
|
|
|
30
30
|
@old_object = @object.dup
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
|
|
32
|
+
satisfy_strong_params!
|
|
33
|
+
sanitize_params_for!(request.xhr? ? :modal : :update)
|
|
34
|
+
|
|
34
35
|
@object.set_attributes(params[@abstract_model.param_key], _attr_accessible_role)
|
|
35
36
|
@authorization_adapter && @authorization_adapter.attributes_for(:update, @abstract_model).each do |name, value|
|
|
36
37
|
@object.send("#{name}=", value)
|
|
@@ -40,7 +41,7 @@ module RailsAdmin
|
|
|
40
41
|
@auditing_adapter && @auditing_adapter.update_object(@abstract_model, @object, @cached_assocations_hash, associations_hash, @modified_assoc, @old_object, _current_user)
|
|
41
42
|
respond_to do |format|
|
|
42
43
|
format.html { redirect_to_on_success }
|
|
43
|
-
format.js { render :json => { :id => @object.id, :label => @model_config.with(:object => @object).object_label } }
|
|
44
|
+
format.js { render :json => { :id => @object.id.to_s, :label => @model_config.with(:object => @object).object_label } }
|
|
44
45
|
end
|
|
45
46
|
else
|
|
46
47
|
handle_save_error :edit
|
|
@@ -34,18 +34,19 @@ module RailsAdmin
|
|
|
34
34
|
|
|
35
35
|
@modified_assoc = []
|
|
36
36
|
@object = @abstract_model.new
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
satisfy_strong_params!
|
|
38
|
+
sanitize_params_for!(request.xhr? ? :modal : :create)
|
|
39
|
+
|
|
39
40
|
@object.set_attributes(params[@abstract_model.param_key], _attr_accessible_role)
|
|
40
41
|
@authorization_adapter && @authorization_adapter.attributes_for(:create, @abstract_model).each do |name, value|
|
|
41
42
|
@object.send("#{name}=", value)
|
|
42
43
|
end
|
|
43
|
-
|
|
44
|
+
|
|
44
45
|
if @object.save
|
|
45
46
|
@auditing_adapter && @auditing_adapter.create_object("Created #{@model_config.with(:object => @object).object_label}", @object, @abstract_model, _current_user)
|
|
46
47
|
respond_to do |format|
|
|
47
48
|
format.html { redirect_to_on_success }
|
|
48
|
-
format.js { render :json => { :id => @object.id, :label => @model_config.with(:object => @object).object_label } }
|
|
49
|
+
format.js { render :json => { :id => @object.id.to_s, :label => @model_config.with(:object => @object).object_label } }
|
|
49
50
|
end
|
|
50
51
|
else
|
|
51
52
|
handle_save_error
|
|
@@ -15,7 +15,7 @@ module RailsAdmin
|
|
|
15
15
|
@properties
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
register_instance_option
|
|
18
|
+
register_instance_option :pretty_value do
|
|
19
19
|
v = bindings[:view]
|
|
20
20
|
[value].flatten.select(&:present?).map do |associated|
|
|
21
21
|
amc = polymorphic? ? RailsAdmin.config(associated) : associated_model_config # perf optimization for non-polymorphic associations
|
|
@@ -29,12 +29,12 @@ module RailsAdmin
|
|
|
29
29
|
# Accessor whether association is visible or not. By default
|
|
30
30
|
# association checks whether the child model is excluded in
|
|
31
31
|
# configuration or not.
|
|
32
|
-
register_instance_option
|
|
32
|
+
register_instance_option :visible? do
|
|
33
33
|
@visible ||= !self.associated_model_config.excluded?
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
# use the association name as a key, not the association key anymore!
|
|
37
|
-
register_instance_option
|
|
37
|
+
register_instance_option :label do
|
|
38
38
|
(@label ||= {})[::I18n.locale] ||= abstract_model.model.human_attribute_name association[:name]
|
|
39
39
|
end
|
|
40
40
|
|
|
@@ -46,12 +46,12 @@ module RailsAdmin
|
|
|
46
46
|
scope.limit(associated_collection_scope_limit)
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
# inverse relationship
|
|
51
51
|
register_instance_option :inverse_of do
|
|
52
52
|
association[:inverse_of]
|
|
53
53
|
end
|
|
54
|
-
|
|
54
|
+
|
|
55
55
|
# preload entire associated collection (per associated_collection_scope) on load
|
|
56
56
|
# Be sure to set limit in associated_collection_scope if set is large
|
|
57
57
|
register_instance_option :associated_collection_cache_all do
|
|
@@ -67,17 +67,17 @@ module RailsAdmin
|
|
|
67
67
|
def associated_object_label_method
|
|
68
68
|
@associated_object_label_method ||= associated_model_config.object_label_method
|
|
69
69
|
end
|
|
70
|
-
|
|
70
|
+
|
|
71
71
|
# Reader for associated primary key
|
|
72
72
|
def associated_primary_key
|
|
73
73
|
@associated_primary_key ||= association[:primary_key_proc].call
|
|
74
74
|
end
|
|
75
|
-
|
|
75
|
+
|
|
76
76
|
# Reader for the association's key
|
|
77
77
|
def foreign_key
|
|
78
78
|
association[:foreign_key]
|
|
79
79
|
end
|
|
80
|
-
|
|
80
|
+
|
|
81
81
|
# Reader whether this is a polymorphic association
|
|
82
82
|
def polymorphic?
|
|
83
83
|
association[:polymorphic]
|
|
@@ -92,12 +92,12 @@ module RailsAdmin
|
|
|
92
92
|
def value
|
|
93
93
|
bindings[:object].send(association[:name])
|
|
94
94
|
end
|
|
95
|
-
|
|
95
|
+
|
|
96
96
|
# has many?
|
|
97
97
|
def multiple?
|
|
98
98
|
true
|
|
99
99
|
end
|
|
100
|
-
|
|
100
|
+
|
|
101
101
|
def virtual?
|
|
102
102
|
true
|
|
103
103
|
end
|