rails_admin 1.2.0 → 1.3.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 (29) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -2
  3. data/README.md +4 -4
  4. data/app/assets/javascripts/rails_admin/ra.filter-box.js +123 -59
  5. data/app/assets/javascripts/rails_admin/ra.filtering-multiselect.js +12 -12
  6. data/app/assets/javascripts/rails_admin/ra.filtering-select.js +5 -0
  7. data/app/assets/javascripts/rails_admin/ra.i18n.coffee +2 -0
  8. data/app/assets/javascripts/rails_admin/ra.widgets.coffee +25 -0
  9. data/app/controllers/rails_admin/application_controller.rb +1 -1
  10. data/app/views/kaminari/ra-twitter-bootstrap/without_count/_next_page.html.haml +4 -0
  11. data/app/views/kaminari/ra-twitter-bootstrap/without_count/_paginator.html.haml +4 -0
  12. data/app/views/kaminari/ra-twitter-bootstrap/without_count/_prev_page.html.haml +4 -0
  13. data/app/views/rails_admin/main/_form_simple_mde.haml +8 -0
  14. data/app/views/rails_admin/main/history.html.haml +1 -1
  15. data/app/views/rails_admin/main/index.html.haml +13 -6
  16. data/lib/rails_admin/adapters/active_record.rb +2 -7
  17. data/lib/rails_admin/config.rb +5 -0
  18. data/lib/rails_admin/config/actions/dashboard.rb +5 -1
  19. data/lib/rails_admin/config/fields/types/active_record_enum.rb +17 -3
  20. data/lib/rails_admin/config/fields/types/all.rb +1 -0
  21. data/lib/rails_admin/config/fields/types/datetime.rb +1 -1
  22. data/lib/rails_admin/config/fields/types/json.rb +5 -1
  23. data/lib/rails_admin/config/fields/types/simple_mde.rb +33 -0
  24. data/lib/rails_admin/config/sections/list.rb +10 -0
  25. data/lib/rails_admin/extensions/history/auditing_adapter.rb +2 -2
  26. data/lib/rails_admin/extensions/history/history.rb +2 -2
  27. data/lib/rails_admin/extensions/paper_trail/auditing_adapter.rb +4 -2
  28. data/lib/rails_admin/version.rb +1 -1
  29. metadata +7 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c69e517eca7e9a2fd7b5f93c966f86f9eadd57d5
4
- data.tar.gz: c2df6d3bcda5e4ccd0cadef10ddc46a4e8f6c283
3
+ metadata.gz: 33d3dadad1730dcd25eec2e13d09c6f46e8b580c
4
+ data.tar.gz: 2f14072f95732283cf691142d80c65a47335e31e
5
5
  SHA512:
6
- metadata.gz: e6fc0cb49d89c389de0afffdc0e17215d6e9d6a702ef8c263106058ed1f4a5bdd13e0d57ce9d39cc691a88de83669bfaeaaeb21c9657aaa096f2e387091b125e
7
- data.tar.gz: fafcc0bb5ada22245b595107ee6c65c2b816de55d48d969e9ca4c225e428118ba4d4b8e5af6a4a2138e4c5b52a100fb1673970e31b0e087cc73d15d5da97d030
6
+ metadata.gz: b820c08a510d01a62f8e6ba65b48ea6c2c37243b5202bb86e51f74303bd1ff370789259623d3b8aaaf41d19c6408fc0d694ed3f4f20c76ae24e034d1f4991724
7
+ data.tar.gz: 22557c8d0ab68e47e48be789f7b813a32f50af4e2f194c7710d71557b105c14af9fd6956c4aeecc6aca889ab5d404493dc1a6c8ad0cf7488542cae812ac52070
data/Gemfile CHANGED
@@ -1,14 +1,15 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'appraisal', '>= 2.0'
4
- gem 'rails', '~> 5.0.0'
4
+ gem 'rails', '~> 5.1.0'
5
5
  gem 'haml'
6
6
  gem 'devise'
7
7
 
8
8
  group :active_record do
9
+ gem 'paper_trail'
10
+
9
11
  platforms :ruby, :mswin, :mingw do
10
12
  gem 'mysql2', '~> 0.3.14'
11
- gem 'pg', '>= 0.14'
12
13
  gem 'sqlite3', '>= 1.3'
13
14
  end
14
15
  end
data/README.md CHANGED
@@ -20,9 +20,9 @@ RailsAdmin is a Rails engine that provides an easy-to-use interface for managing
20
20
 
21
21
  ### [Action required] Security issue
22
22
 
23
- **RailsAdmin 1.0.0 and 1.1.0 have been reported to have CSRF vulnerability with default setup.** We strongly recommend that you upgrade RailsAdmin to 1.1.1 or later as soon as possible, if you are on these versions. See [b13e879e](https://github.com/sferik/rails_admin/commit/b13e879eb93b661204e9fb5e55f7afa4f397537a) for the detail.
23
+ **RailsAdmin prior to 1.3.0 have been reported to have XSS vulnerability.** We strongly recommend that you upgrade RailsAdmin to 1.3.0 or later as soon as possible, if you are on those versions. See [#2985](https://github.com/sferik/rails_admin/issues/2985) for the detail.
24
24
 
25
- This problem was reported by SourceClear, Inc.
25
+ Also, 1.0.0 and 1.1.0 is known to have [CSRF vulnerability](https://github.com/sferik/rails_admin/commit/b13e879eb93b661204e9fb5e55f7afa4f397537a), too.
26
26
 
27
27
 
28
28
  ## Features
@@ -42,7 +42,7 @@ This problem was reported by SourceClear, Inc.
42
42
 
43
43
  ## Installation
44
44
 
45
- 1. On your gemfile: `gem 'rails_admin', '~> 1.2'`
45
+ 1. On your gemfile: `gem 'rails_admin', '~> 1.3'`
46
46
  2. Run `bundle install`
47
47
  3. Run `rails g rails_admin:install`
48
48
  4. Provide a namespace for the routes when asked
@@ -50,7 +50,7 @@ This problem was reported by SourceClear, Inc.
50
50
 
51
51
  ## Configuration
52
52
  ### Global
53
- In `config/initializers/rails_admin`:
53
+ In `config/initializers/rails_admin.rb`:
54
54
 
55
55
  [Details](https://github.com/sferik/rails_admin/wiki/Base-configuration)
56
56
 
@@ -19,90 +19,154 @@
19
19
 
20
20
  switch(field_type) {
21
21
  case 'boolean':
22
- var control = '<select class="input-sm form-control" name="' + value_name + '">' +
23
- '<option value="_discard">...</option>' +
24
- '<option value="true"' + (field_value == "true" ? 'selected="selected"' : '') + '>' + RailsAdmin.I18n.t("true") + '</option>' +
25
- '<option value="false"' + (field_value == "false" ? 'selected="selected"' : '') + '>' + RailsAdmin.I18n.t("false") + '</option>' +
26
- '<option disabled="disabled">---------</option>' +
27
- '<option ' + (field_value == "_present" ? 'selected="selected"' : '') + ' value="_present">' + RailsAdmin.I18n.t("is_present") + '</option>' +
28
- '<option ' + (field_value == "_blank" ? 'selected="selected"' : '') + ' value="_blank" >' + RailsAdmin.I18n.t("is_blank") + '</option>' +
29
- '</select>';
22
+ control = $('<select class="input-sm form-control"></select>')
23
+ .prop('name', value_name)
24
+ .append('<option value="_discard">...</option>')
25
+ .append($('<option value="true"></option>').prop('selected', field_value == "true").text(RailsAdmin.I18n.t("true")))
26
+ .append($('<option value="false"></option>').prop('selected', field_value == "false").text(RailsAdmin.I18n.t("false")))
27
+ .append('<option disabled="disabled">---------</option>')
28
+ .append($('<option value="_present"></option>').prop('selected', field_value == "_present").text(RailsAdmin.I18n.t("is_present")))
29
+ .append($('<option value="_blank"></option>').prop('selected', field_value == "_blank").text(RailsAdmin.I18n.t("is_blank")));
30
30
  break;
31
31
  case 'date':
32
32
  additional_control =
33
- '<input size="20" class="date additional-fieldset default input-sm form-control" style="display:' + ((!field_operator || field_operator == "default") ? 'inline-block' : 'none') + ';" type="text" name="' + value_name + '[]" value="' + (field_value[0] || '') + '" /> ' +
34
- '<input size="20" placeholder="-∞" class="date additional-fieldset between input-sm form-control" style="display:' + ((field_operator == "between") ? 'inline-block' : 'none') + ';" type="text" name="' + value_name + '[]" value="' + (field_value[1] || '') + '" /> ' +
35
- '<input size="20" placeholder="∞" class="date additional-fieldset between input-sm form-control" style="display:' + ((field_operator == "between") ? 'inline-block' : 'none') + ';" type="text" name="' + value_name + '[]" value="' + (field_value[2] || '') + '" />';
33
+ $('<input size="20" class="date additional-fieldset default input-sm form-control" type="text" />')
34
+ .css('display', (!field_operator || field_operator == "default") ? 'inline-block' : 'none')
35
+ .prop('name', value_name + '[]')
36
+ .prop('value', field_value[0] || '')
37
+ .add(
38
+ $('<input size="20" placeholder="-∞" class="date additional-fieldset between input-sm form-control" type="text" />')
39
+ .css('display', (field_operator == "between") ? 'inline-block' : 'none')
40
+ .prop('name', value_name + '[]')
41
+ .prop('value', field_value[1] || '')
42
+ )
43
+ .add(
44
+ $('<input size="20" placeholder="∞" class="date additional-fieldset between input-sm form-control" type="text" />')
45
+ .css('display', (field_operator == "between") ? 'inline-block' : 'none')
46
+ .prop('name', value_name + '[]')
47
+ .prop('value', field_value[2] || '')
48
+ );
36
49
  case 'datetime':
37
50
  case 'timestamp':
38
- control = control || '<select class="switch-additionnal-fieldsets input-sm form-control" name="' + operator_name + '">' +
39
- '<option ' + (field_operator == "default" ? 'selected="selected"' : '') + ' data-additional-fieldset="default" value="default">' + RailsAdmin.I18n.t("date") + '</option>' +
40
- '<option ' + (field_operator == "between" ? 'selected="selected"' : '') + ' data-additional-fieldset="between" value="between">' + RailsAdmin.I18n.t("between_and_") + '</option>' +
41
- '<option ' + (field_operator == "today" ? 'selected="selected"' : '') + ' value="today">' + RailsAdmin.I18n.t("today") + '</option>' +
42
- '<option ' + (field_operator == "yesterday" ? 'selected="selected"' : '') + ' value="yesterday">' + RailsAdmin.I18n.t("yesterday") + '</option>' +
43
- '<option ' + (field_operator == "this_week" ? 'selected="selected"' : '') + ' value="this_week">' + RailsAdmin.I18n.t("this_week") + '</option>' +
44
- '<option ' + (field_operator == "last_week" ? 'selected="selected"' : '') + ' value="last_week">' + RailsAdmin.I18n.t("last_week") + '</option>' +
45
- '<option disabled="disabled">---------</option>' +
46
- '<option ' + (field_operator == "_not_null" ? 'selected="selected"' : '') + ' value="_not_null">' + RailsAdmin.I18n.t("is_present") + '</option>' +
47
- '<option ' + (field_operator == "_null" ? 'selected="selected"' : '') + ' value="_null" >' + RailsAdmin.I18n.t("is_blank") + '</option>' +
48
- '</select>'
51
+ control = control || $('<select class="switch-additionnal-fieldsets input-sm form-control"></select>')
52
+ .prop('name', operator_name)
53
+ .append($('<option data-additional-fieldset="default" value="default"></option>').prop('selected', field_operator == "default").text(RailsAdmin.I18n.t("date")))
54
+ .append($('<option data-additional-fieldset="between" value="between"></option>').prop('selected', field_operator == "between").text(RailsAdmin.I18n.t("between_and_")))
55
+ .append($('<option value="today"></option>').prop('selected', field_operator == "today").text(RailsAdmin.I18n.t("today")))
56
+ .append($('<option value="yesterday"></option>').prop('selected', field_operator == "yesterday").text(RailsAdmin.I18n.t("yesterday")))
57
+ .append($('<option value="this_week"></option>').prop('selected', field_operator == "this_week").text(RailsAdmin.I18n.t("this_week")))
58
+ .append($('<option value="last_week"></option>').prop('selected', field_operator == "last_week").text(RailsAdmin.I18n.t("last_week")))
59
+ .append('<option disabled="disabled">---------</option>')
60
+ .append($('<option value="_not_null"></option>').prop('selected', field_operator == "_not_null").text(RailsAdmin.I18n.t("is_present")))
61
+ .append($('<option value="_null"></option>').prop('selected', field_operator == "_null").text(RailsAdmin.I18n.t("is_blank")));
49
62
  additional_control = additional_control ||
50
- '<input size="25" class="datetime additional-fieldset default input-sm form-control" style="display:' + ((!field_operator || field_operator == "default") ? 'inline-block' : 'none') + ';" type="text" name="' + value_name + '[]" value="' + (field_value[0] || '') + '" /> ' +
51
- '<input size="25" placeholder="-∞" class="datetime additional-fieldset between input-sm form-control" style="display:' + ((field_operator == "between") ? 'inline-block' : 'none') + ';" type="text" name="' + value_name + '[]" value="' + (field_value[1] || '') + '" /> ' +
52
- '<input size="25" placeholder="∞" class="datetime additional-fieldset between input-sm form-control" style="display:' + ((field_operator == "between") ? 'inline-block' : 'none') + ';" type="text" name="' + value_name + '[]" value="' + (field_value[2] || '') + '" />';
63
+ $('<input size="25" class="datetime additional-fieldset default input-sm form-control" type="text" />')
64
+ .css('display', (!field_operator || field_operator == "default") ? 'inline-block' : 'none')
65
+ .prop('name', value_name + '[]')
66
+ .prop('value', field_value[0] || '')
67
+ .add(
68
+ $('<input size="25" placeholder="-∞" class="datetime additional-fieldset between input-sm form-control" type="text" />')
69
+ .css('display', (field_operator == "between") ? 'inline-block' : 'none')
70
+ .prop('name', value_name + '[]')
71
+ .prop('value', field_value[1] || '')
72
+ )
73
+ .add(
74
+ $('<input size="25" placeholder="∞" class="datetime additional-fieldset between input-sm form-control" type="text" />')
75
+ .css('display', (field_operator == "between") ? 'inline-block' : 'none')
76
+ .prop('name', value_name + '[]')
77
+ .prop('value', field_value[2] || '')
78
+ );
53
79
  break;
54
80
  case 'enum':
55
81
  var multiple_values = ((field_value instanceof Array) ? true : false)
56
- control = '<select style="display:' + (multiple_values ? 'none' : 'inline-block') + '" ' + (multiple_values ? '' : 'name="' + value_name + '"') + ' data-name="' + value_name + '" class="select-single input-sm form-control">' +
57
- '<option value="_discard">...</option>' +
58
- '<option ' + (field_value == "_present" ? 'selected="selected"' : '') + ' value="_present">' + RailsAdmin.I18n.t("is_present") + '</option>' +
59
- '<option ' + (field_value == "_blank" ? 'selected="selected"' : '') + ' value="_blank">' + RailsAdmin.I18n.t("is_blank") + '</option>' +
60
- '<option disabled="disabled">---------</option>' +
61
- select_options +
62
- '</select>' +
63
- '<select multiple="multiple" style="display:' + (multiple_values ? 'inline-block' : 'none') + '" ' + (multiple_values ? 'name="' + value_name + '[]"' : '') + ' data-name="' + value_name + '[]" class="select-multiple input-sm form-control">' +
64
- select_options +
65
- '</select> ' +
66
- '<a href="#" class="switch-select"><i class="icon-' + (multiple_values ? 'minus' : 'plus') + '"></i></a>';
82
+ control = $('<select class="select-single input-sm form-control"></select>')
83
+ .css('display', multiple_values ? 'none' : 'inline-block')
84
+ .prop('name', multiple_values ? undefined : value_name)
85
+ .data('name', value_name)
86
+ .append('<option value="_discard">...</option>')
87
+ .append($('<option value="_present"></option>').prop('selected', field_value == "_present").text(RailsAdmin.I18n.t("is_present")))
88
+ .append($('<option value="_blank"></option>').prop('selected', field_value == "_blank").text(RailsAdmin.I18n.t("is_blank")))
89
+ .append('<option disabled="disabled">---------</option>')
90
+ .append(select_options)
91
+ .add(
92
+ $('<select multiple="multiple" class="select-multiple input-sm form-control"></select>')
93
+ .css('display', multiple_values ? 'inline-block' : 'none')
94
+ .prop('name', multiple_values ? value_name + '[]' : undefined)
95
+ .data('name', value_name + '[]')
96
+ .append(select_options)
97
+ )
98
+ .add(
99
+ $('<a href="#" class="switch-select"></a>')
100
+ .append($('<i></i>').addClass('icon-' + (multiple_values ? 'minus' : 'plus')))
101
+ );
67
102
  break;
68
103
  case 'string':
69
104
  case 'text':
70
105
  case 'belongs_to_association':
71
- control = '<select class="switch-additionnal-fieldsets input-sm form-control" value="' + field_operator + '" name="' + operator_name + '">' +
72
- '<option data-additional-fieldset="additional-fieldset"' + (field_operator == "like" ? 'selected="selected"' : '') + ' value="like">' + RailsAdmin.I18n.t("contains") + '</option>' +
73
- '<option data-additional-fieldset="additional-fieldset"' + (field_operator == "is" ? 'selected="selected"' : '') + ' value="is">' + RailsAdmin.I18n.t("is_exactly") + '</option>' +
74
- '<option data-additional-fieldset="additional-fieldset"' + (field_operator == "starts_with" ? 'selected="selected"' : '') + ' value="starts_with">' + RailsAdmin.I18n.t("starts_with") + '</option>' +
75
- '<option data-additional-fieldset="additional-fieldset"' + (field_operator == "ends_with" ? 'selected="selected"' : '') + ' value="ends_with">' + RailsAdmin.I18n.t("ends_with") + '</option>' +
76
- '<option disabled="disabled">---------</option>' +
77
- '<option ' + (field_operator == "_not_null" ? 'selected="selected"' : '') + ' value="_not_null">' + RailsAdmin.I18n.t("is_present") + '</option>' +
78
- '<option ' + (field_operator == "_null" ? 'selected="selected"' : '') + ' value="_null">' + RailsAdmin.I18n.t("is_blank") + '</option>' +
79
- '</select>'
80
- additional_control = '<input class="additional-fieldset input-sm form-control" style="display:' + (field_operator == "_blank" || field_operator == "_present" ? 'none' : 'inline-block') + ';" type="text" name="' + value_name + '" value="' + field_value + '" /> ';
106
+ control = $('<select class="switch-additionnal-fieldsets input-sm form-control"></select>')
107
+ .prop('value', field_operator)
108
+ .prop('name', operator_name)
109
+ .append('<option value="_discard">...</option>')
110
+ .append($('<option data-additional-fieldset="additional-fieldset" value="like"></option>').prop('selected', field_operator == "like").text(RailsAdmin.I18n.t("contains")))
111
+ .append($('<option data-additional-fieldset="additional-fieldset" value="is"></option>').prop('selected', field_operator == "is").text(RailsAdmin.I18n.t("is_exactly")))
112
+ .append($('<option data-additional-fieldset="additional-fieldset" value="starts_with"></option>').prop('selected', field_operator == "starts_with").text(RailsAdmin.I18n.t("starts_with")))
113
+ .append($('<option data-additional-fieldset="additional-fieldset" value="ends_with"></option>').prop('selected', field_operator == "ends_with").text(RailsAdmin.I18n.t("ends_with")))
114
+ .append('<option disabled="disabled">---------</option>')
115
+ .append($('<option value="_present"></option>').prop('selected', field_operator == "_present").text(RailsAdmin.I18n.t("is_present")))
116
+ .append($('<option value="_blank"></option>').prop('selected', field_operator == "_blank").text(RailsAdmin.I18n.t("is_blank")));
117
+ additional_control = $('<input class="additional-fieldset input-sm form-control" type="text" />')
118
+ .css('display', field_operator == "_present" || field_operator == "_blank" ? 'none' : 'inline-block')
119
+ .prop('name', value_name)
120
+ .prop('value', field_value);
81
121
  break;
82
122
  case 'integer':
83
123
  case 'decimal':
84
124
  case 'float':
85
- control = '<select class="switch-additionnal-fieldsets input-sm form-control" name="' + operator_name + '">' +
86
- '<option ' + (field_operator == "default" ? 'selected="selected"' : '') + ' data-additional-fieldset="default" value="default">' + RailsAdmin.I18n.t("number") + '</option>' +
87
- '<option ' + (field_operator == "between" ? 'selected="selected"' : '') + ' data-additional-fieldset="between" value="between">' + RailsAdmin.I18n.t("between_and_") + '</option>' +
88
- '<option disabled="disabled">---------</option>' +
89
- '<option ' + (field_operator == "_not_null" ? 'selected="selected"' : '') + ' value="_not_null">' + RailsAdmin.I18n.t("is_present") +'</option>' +
90
- '<option ' + (field_operator == "_null" ? 'selected="selected"' : '') + ' value="_null" >' + RailsAdmin.I18n.t("is_blank") + '</option>' +
91
- '</select>'
125
+ control = $('<select class="switch-additionnal-fieldsets input-sm form-control"></select>')
126
+ .prop('name', operator_name)
127
+ .append($('<option data-additional-fieldset="default" value="default"></option>').prop('selected', field_operator == "default").text(RailsAdmin.I18n.t("number")))
128
+ .append($('<option data-additional-fieldset="between" value="between"></option>').prop('selected', field_operator == "between").text(RailsAdmin.I18n.t("between_and_")))
129
+ .append('<option disabled="disabled">---------</option>')
130
+ .append($('<option value="_not_null"></option>').prop('selected', field_operator == "_not_null").text(RailsAdmin.I18n.t("is_present")))
131
+ .append($('<option value="_null"></option>').prop('selected', field_operator == "_null").text(RailsAdmin.I18n.t("is_blank")));
92
132
  additional_control =
93
- '<input class="additional-fieldset default input-sm form-control" style="display:' + ((!field_operator || field_operator == "default") ? 'inline-block' : 'none') + ';" type="' + field_type + '" name="' + value_name + '[]" value="' + (field_value[0] || '') + '" /> ' +
94
- '<input placeholder="-∞" class="additional-fieldset between input-sm form-control" style="display:' + ((field_operator == "between") ? 'inline-block' : 'none') + ';" type="' + field_type + '" name="' + value_name + '[]" value="' + (field_value[1] || '') + '" /> ' +
95
- '<input placeholder="∞" class="additional-fieldset between input-sm form-control" style="display:' + ((field_operator == "between") ? 'inline-block' : 'none') + ';" type="' + field_type + '" name="' + value_name + '[]" value="' + (field_value[2] || '') + '" />';
133
+ $('<input class="additional-fieldset default input-sm form-control" type="text" />')
134
+ .css('display', (!field_operator || field_operator == "default") ? 'inline-block' : 'none')
135
+ .prop('type', field_type)
136
+ .prop('name', value_name + '[]')
137
+ .prop('value', field_value[0] || '')
138
+ .add(
139
+ $('<input placeholder="-∞" class="additional-fieldset between input-sm form-control" />')
140
+ .css('display', (field_operator == "between") ? 'inline-block' : 'none')
141
+ .prop('type', field_type)
142
+ .prop('name', value_name + '[]')
143
+ .prop('value', field_value[1] || '')
144
+ )
145
+ .add(
146
+ $('<input placeholder="∞" class="additional-fieldset between input-sm form-control" />')
147
+ .css('display', (field_operator == "between") ? 'inline-block' : 'none')
148
+ .prop('type', field_type)
149
+ .prop('name', value_name + '[]')
150
+ .prop('value', field_value[2] || '')
151
+ );
96
152
  break;
97
153
  default:
98
- control = '<input type="text" class="input-sm form-control" name="' + value_name + '" value="' + field_value + '"/> ';
154
+ control = $('<input type="text" class="input-sm form-control" />')
155
+ .prop('name', value_name)
156
+ .prop('value', field_value);
99
157
  break;
100
158
  }
101
159
 
102
160
  var $content = $('<p>')
103
161
  .addClass('filter form-search')
104
- .append('<span class="label label-info form-label"><a href="#delete" class="delete"><i class="fa fa-trash-o fa-fw icon-white"></i>' + field_label + '</a></span>')
105
- .append('&nbsp;' + control + '&nbsp;' + (additional_control || ''));
162
+ .append(
163
+ $('<span class="label label-info form-label"></span>')
164
+ .append($('<a href="#delete" class="delete"></a>').append('<i class="fa fa-trash-o fa-fw icon-white"></i>').append(document.createTextNode(field_label)))
165
+ )
166
+ .append('&nbsp;')
167
+ .append(control)
168
+ .append('&nbsp;')
169
+ .append(additional_control);
106
170
 
107
171
  $('#filters_box').append($content);
108
172
 
@@ -186,12 +186,13 @@
186
186
  }
187
187
  if (filtered.length > 0) {
188
188
  widget.collection[0].innerHTML = '';
189
- var filteredContainer = [];
190
189
  for (i = 0; i < filtered.length; i++) {
191
- var newOptions = '<option value="'+matches[filtered[i]].id+'" title="'+matches[filtered[i]].label+'">'+matches[filtered[i]].label+'</option>';
192
- filteredContainer.push(newOptions);
190
+ var newOptions = $('<option></option>')
191
+ .prop('value', matches[filtered[i]].id)
192
+ .prop('title', matches[filtered[i]].label)
193
+ .text(matches[filtered[i]].label);
194
+ $(widget.collection[0]).append(newOptions);
193
195
  }
194
- widget.collection[0].innerHTML = filteredContainer.join("");
195
196
  } else {
196
197
  widget.collection[0].innerHTML = widget.noObjectsPlaceholder;
197
198
  }
@@ -212,12 +213,11 @@
212
213
  var widget = this;
213
214
 
214
215
  this.element.find("option").each(function(i, option) {
216
+ widget._cache['o_' + option.value] = {id: option.value, value: $(option).text()};
215
217
  if (option.selected) {
216
- widget._cache['o_' + option.value] = {id: option.value, value: option.innerHTML};
217
- $(option).clone().appendTo(widget.selection).attr("selected", false).attr("title", $(option).text());
218
+ $(option).clone().appendTo(widget.selection).prop("selected", false).prop("title", $(option).text());
218
219
  } else {
219
- widget._cache['o_' + option.value] = {id: option.value, value: option.innerHTML};
220
- $(option).clone().appendTo(widget.collection).attr("selected", false).attr("title", $(option).text());
220
+ $(option).clone().appendTo(widget.collection).prop("selected", false).prop("title", $(option).text());
221
221
  }
222
222
  });
223
223
  },
@@ -227,7 +227,7 @@
227
227
  options.each(function(i, option) {
228
228
  widget.element.find('option[value="' + option.value + '"]').removeAttr("selected");
229
229
  });
230
- $(options).appendTo(this.collection).attr('selected', false);
230
+ $(options).appendTo(this.collection).prop('selected', false);
231
231
  },
232
232
 
233
233
  _query: function(query, success) {
@@ -282,12 +282,12 @@
282
282
  options.each(function(i, option) {
283
283
  var el = widget.element.find('option[value="' + option.value + '"]');
284
284
  if (el.length) {
285
- el.attr("selected", "selected");
285
+ el.prop("selected", true);
286
286
  } else {
287
- widget.element.append($('<option></option>').attr('value', option.value).attr('selected', "selected"));
287
+ widget.element.append($('<option></option>').prop('value', option.value).prop('selected', true));
288
288
  }
289
289
  });
290
- $(options).appendTo(this.selection).attr('selected', false);
290
+ $(options).appendTo(this.selection).prop('selected', false);
291
291
  },
292
292
 
293
293
  _move: function(direction, options) {
@@ -189,6 +189,11 @@
189
189
  input.attr('placeholder', this.element.attr('placeholder'));
190
190
  }
191
191
 
192
+ if (this.element.attr('required')) {
193
+ input.attr('required', this.element.attr('required'));
194
+ this.element.attr('required', false);
195
+ }
196
+
192
197
  return input;
193
198
  },
194
199
 
@@ -2,6 +2,8 @@
2
2
  @RailsAdmin.I18n = class Locale
3
3
  @init: (@locale, @translations)->
4
4
  moment.locale(@locale)
5
+ if typeof(@translations) == "string"
6
+ @translations = JSON.parse(@translations)
5
7
 
6
8
  @t:(key) ->
7
9
  humanize = key.charAt(0).toUpperCase() + key.replace(/_/g, " ").slice(1)
@@ -171,6 +171,31 @@ $(document).on 'rails_admin.dom_ready', (e, content) ->
171
171
  html = html.add(option)
172
172
  object_select.html(html)
173
173
 
174
+
175
+ # simplemde
176
+
177
+ goSimpleMDEs = ->
178
+ content.find('[data-richtext=simplemde]').not('.simplemded').each (index, domEle) ->
179
+ options = $(this).data('options')
180
+ instance_config = options.instance_config
181
+ new window.SimpleMDE($.extend(true, {
182
+ element: document.getElementById(this.id),
183
+ autosave: {
184
+ uniqueId: this.id
185
+ }
186
+ }, instance_config))
187
+ $(this).addClass('simplemded')
188
+
189
+ $editors = content.find('[data-richtext=simplemde]').not('.simplemded')
190
+ if $editors.length
191
+ if not window.SimpleMDE
192
+ options = $editors.first().data('options')
193
+ $('head').append('<link href="' + options['css_location'] + '" rel="stylesheet" media="all" type="text\/css">')
194
+ $.getScript options['js_location'], (script, textStatus, jqXHR) ->
195
+ goSimpleMDEs()
196
+ else
197
+ goSimpleMDEs()
198
+
174
199
  # ckeditor
175
200
 
176
201
  goCkeditors = ->
@@ -11,7 +11,7 @@ module RailsAdmin
11
11
  end
12
12
 
13
13
  class ApplicationController < Config.parent_controller.constantize
14
- protect_from_forgery with: :exception
14
+ protect_from_forgery(Config.forgery_protection_settings)
15
15
 
16
16
  before_action :_authenticate!
17
17
  before_action :_authorize!
@@ -0,0 +1,4 @@
1
+ - if current_page.last?
2
+ %li.next.disabled= link_to raw(t 'admin.pagination.next'), '#'
3
+ - else
4
+ %li.next= link_to raw(t 'admin.pagination.next'), url, class: (remote ? 'pjax' : '')
@@ -0,0 +1,4 @@
1
+ = paginator.render do
2
+ %ul.pagination
3
+ = prev_page_tag if !current_page.first?
4
+ = next_page_tag
@@ -0,0 +1,4 @@
1
+ - if current_page.first?
2
+ %li.prev.disabled= link_to raw(t 'admin.pagination.previous'), '#'
3
+ - else
4
+ %li.prev= link_to raw(t 'admin.pagination.previous'), url, class: (remote ? 'pjax' : '')
@@ -0,0 +1,8 @@
1
+ :ruby
2
+ js_data = {
3
+ js_location: field.js_location,
4
+ css_location: field.css_location,
5
+ instance_config: field.instance_config
6
+ }
7
+
8
+ = form.text_area field.method_name, field.html_attributes.reverse_merge(data: { richtext: 'simplemde', options: js_data.to_json }).reverse_merge({ value: field.form_value })
@@ -10,7 +10,7 @@
10
10
  .input-group
11
11
  %input.form-control.input-small{name: "query", type: "search", value: query, placeholder: "#{t("admin.misc.filter")}", class: 'input-small'}
12
12
  %span.input-group-btn
13
- %button.btn.btn-primary{type: "submit", :'data-disable-with' => "<i class='icon-white icon-refresh'></i> ".html_safe + t("admin.misc.refresh")}
13
+ %button.btn.btn-primary{type: 'submit', :'data-disable-with' => '<i class="icon-white icon-refresh"></i> '.html_safe + t('admin.misc.refresh')}
14
14
  %i.icon-white.icon-refresh
15
15
  = t("admin.misc.refresh")
16
16
  %table#history.table.table-striped.table-condensed
@@ -10,6 +10,7 @@
10
10
  export_action = nil unless export_action && authorized?(export_action.authorization_key, @abstract_model)
11
11
  description = RailsAdmin.config(@abstract_model.model_name).description
12
12
  properties = @model_config.list.with(controller: self.controller, view: self, object: @abstract_model.model.new).visible_fields
13
+ checkboxes = @model_config.list.checkboxes?
13
14
  # columns paginate
14
15
  sets = get_column_sets(properties)
15
16
  properties = sets[params[:set].to_i] || []
@@ -17,7 +18,8 @@
17
18
  other_right = sets[params[:set].to_i + 1].present?
18
19
 
19
20
  - content_for :contextual_tabs do
20
- = bulk_menu
21
+ - if checkboxes
22
+ = bulk_menu
21
23
  - if filterable_fields.present?
22
24
  %li.dropdown{style: 'float:right'}
23
25
  %a.dropdown-toggle{href: '#', :'data-toggle' => "dropdown"}
@@ -75,8 +77,9 @@
75
77
  %table.table.table-condensed.table-striped
76
78
  %thead
77
79
  %tr
78
- %th.shrink
79
- %input.toggle{type: "checkbox"}
80
+ - if checkboxes
81
+ %th.shrink
82
+ %input.toggle{type: "checkbox"}
80
83
  - if other_left
81
84
  %th.other.left.shrink= "..."
82
85
  - properties.each do |property|
@@ -91,8 +94,8 @@
91
94
  %tbody
92
95
  - @objects.each do |object|
93
96
  %tr{class: "#{@abstract_model.param_key}_row #{@model_config.list.with(object: object).row_css_class}"}
94
- %td
95
- = check_box_tag "bulk_ids[]", object.id, false
97
+ - if checkboxes
98
+ %td= check_box_tag "bulk_ids[]", object.id, false
96
99
  - if @other_left_link ||= other_left && index_path(params.except('set').merge(params[:set].to_i != 1 ? {set: (params[:set].to_i - 1)} : {}))
97
100
  %td.other.left= link_to "...", @other_left_link, class: 'pjax'
98
101
  - properties.map{ |property| property.bind(:object, object) }.each do |property|
@@ -103,7 +106,11 @@
103
106
  %td.last.links
104
107
  %ul.inline.list-inline= menu_for :member, @abstract_model, object, true
105
108
 
106
- - if @objects.respond_to?(:total_count)
109
+ - if @model_config.list.limited_pagination
110
+ .row
111
+ .col-md-6= paginate(@objects, theme: 'ra-twitter-bootstrap/without_count', total_pages: Float::INFINITY, remote: true)
112
+
113
+ - elsif @objects.respond_to?(:total_count)
107
114
  - total_count = @objects.total_count.to_i
108
115
  .row
109
116
  .col-md-6= paginate(@objects, theme: 'ra-twitter-bootstrap', remote: true)
@@ -101,12 +101,6 @@ module RailsAdmin
101
101
 
102
102
  def add(field, value, operator)
103
103
  field.searchable_columns.flatten.each do |column_infos|
104
- value =
105
- if value.is_a?(Array)
106
- value.map { |v| field.parse_value(v) }
107
- else
108
- field.parse_value(value)
109
- end
110
104
  statement, value1, value2 = StatementBuilder.new(column_infos[:column], column_infos[:type], value, operator).to_statement
111
105
  @statements << statement if statement.present?
112
106
  @values << value1 unless value1.nil?
@@ -126,7 +120,8 @@ module RailsAdmin
126
120
  def query_scope(scope, query, fields = config.list.fields.select(&:queryable?))
127
121
  wb = WhereBuilder.new(scope)
128
122
  fields.each do |field|
129
- wb.add(field, field.parse_value(query), field.search_operator)
123
+ value = parse_field_value(field, query)
124
+ wb.add(field, value, field.search_operator)
130
125
  end
131
126
  # OR all query statements
132
127
  wb.build
@@ -62,6 +62,10 @@ module RailsAdmin
62
62
  # set parent controller
63
63
  attr_accessor :parent_controller
64
64
 
65
+ # set settings for `protect_from_forgery` method
66
+ # By default, it raises exception upon invalid CSRF tokens
67
+ attr_accessor :forgery_protection_settings
68
+
65
69
  # Stores model configuration objects in a hash identified by model's class
66
70
  # name.
67
71
  #
@@ -288,6 +292,7 @@ module RailsAdmin
288
292
  @navigation_static_links = {}
289
293
  @navigation_static_label = nil
290
294
  @parent_controller = '::ActionController::Base'
295
+ @forgery_protection_settings = {with: :exception}
291
296
  RailsAdmin::Config::Actions.reset
292
297
  end
293
298
 
@@ -12,9 +12,13 @@ module RailsAdmin
12
12
  nil
13
13
  end
14
14
 
15
+ register_instance_option :auditing_versions_limit do
16
+ 100
17
+ end
18
+
15
19
  register_instance_option :controller do
16
20
  proc do
17
- @history = @auditing_adapter && @auditing_adapter.latest || []
21
+ @history = @auditing_adapter && @auditing_adapter.latest(@action.auditing_versions_limit) || []
18
22
  if @action.statistics?
19
23
  @abstract_models = RailsAdmin::Config.visible_models(controller: self).collect(&:abstract_model)
20
24
 
@@ -30,14 +30,20 @@ module RailsAdmin
30
30
  def parse_value(value)
31
31
  return unless value.present?
32
32
  if ::Rails.version >= '5'
33
- abstract_model.model.attribute_types[name.to_s].deserialize(value)
33
+ abstract_model.model.attribute_types[name.to_s].serialize(value)
34
34
  else
35
- enum.invert[type_cast_value(value)]
35
+ # Depending on the colum type and AR version, we might get a
36
+ # string or an integer, so we need to handle both cases.
37
+ enum.fetch(value) do
38
+ type_cast_value(value)
39
+ end
36
40
  end
37
41
  end
38
42
 
39
43
  def parse_input(params)
40
- params[name] = parse_value(params[name]) if params[name]
44
+ value = params[name]
45
+ return unless value
46
+ params[name] = parse_input_value(value)
41
47
  end
42
48
 
43
49
  def form_value
@@ -46,6 +52,14 @@ module RailsAdmin
46
52
 
47
53
  private
48
54
 
55
+ def parse_input_value(value)
56
+ if ::Rails.version >= '5'
57
+ abstract_model.model.attribute_types[name.to_s].deserialize(value)
58
+ else
59
+ enum.invert[type_cast_value(value)]
60
+ end
61
+ end
62
+
49
63
  def type_cast_value(value)
50
64
  if ::Rails.version >= '4.2'
51
65
  abstract_model.model.column_types[name.to_s].type_cast_from_user(value)
@@ -25,6 +25,7 @@ require 'rails_admin/config/fields/types/serialized'
25
25
  require 'rails_admin/config/fields/types/time'
26
26
  require 'rails_admin/config/fields/types/timestamp'
27
27
  require 'rails_admin/config/fields/types/color'
28
+ require 'rails_admin/config/fields/types/simple_mde'
28
29
  require 'rails_admin/config/fields/types/ck_editor'
29
30
  require 'rails_admin/config/fields/types/code_mirror'
30
31
  require 'rails_admin/config/fields/types/wysihtml5'
@@ -9,7 +9,7 @@ module RailsAdmin
9
9
  RailsAdmin::Config::Fields::Types.register(self)
10
10
 
11
11
  def parser
12
- @parser ||= RailsAdmin::Support::Datetime.new(strftime_format)
12
+ RailsAdmin::Support::Datetime.new(strftime_format)
13
13
  end
14
14
 
15
15
  def parse_value(value)
@@ -10,7 +10,11 @@ module RailsAdmin
10
10
  RailsAdmin::Config::Fields::Types.register(:jsonb, self)
11
11
 
12
12
  register_instance_option :formatted_value do
13
- value.present? ? JSON.pretty_generate(value) : nil
13
+ value ? JSON.pretty_generate(value) : nil
14
+ end
15
+
16
+ register_instance_option :pretty_value do
17
+ bindings[:view].content_tag(:pre) { formatted_value }.html_safe
14
18
  end
15
19
 
16
20
  def parse_value(value)
@@ -0,0 +1,33 @@
1
+ require 'rails_admin/config/fields/base'
2
+
3
+ module RailsAdmin
4
+ module Config
5
+ module Fields
6
+ module Types
7
+ class SimpleMDE < RailsAdmin::Config::Fields::Types::Text
8
+ # Register field type for the type loader
9
+ RailsAdmin::Config::Fields::Types.register(self)
10
+
11
+ # If you want to have a different SimpleMDE config for each instance
12
+ # you can override this option with these values: https://github.com/sparksuite/simplemde-markdown-editor#configuration
13
+ register_instance_option :instance_config do
14
+ nil
15
+ end
16
+
17
+ # Use this if you want to point to a cloud instance of the base SimpleMDE
18
+ register_instance_option :js_location do
19
+ "#{Rails.application.config.assets.prefix}/simplemde.min.js"
20
+ end
21
+
22
+ register_instance_option :css_location do
23
+ "#{Rails.application.config.assets.prefix}/simplemde.min.css"
24
+ end
25
+
26
+ register_instance_option :partial do
27
+ :form_simple_mde
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -5,6 +5,10 @@ module RailsAdmin
5
5
  module Sections
6
6
  # Configuration of the list view
7
7
  class List < RailsAdmin::Config::Sections::Base
8
+ register_instance_option :checkboxes? do
9
+ true
10
+ end
11
+
8
12
  register_instance_option :filters do
9
13
  []
10
14
  end
@@ -14,6 +18,12 @@ module RailsAdmin
14
18
  RailsAdmin::Config.default_items_per_page
15
19
  end
16
20
 
21
+ # Positive value shows only prev, next links in pagination.
22
+ # This is for avoiding count(*) query.
23
+ register_instance_option :limited_pagination do
24
+ false
25
+ end
26
+
17
27
  register_instance_option :sort_by do
18
28
  parent.abstract_model.primary_key
19
29
  end
@@ -8,8 +8,8 @@ module RailsAdmin
8
8
  require 'rails_admin/extensions/history/history'
9
9
  end
10
10
 
11
- def latest
12
- ::RailsAdmin::History.latest
11
+ def latest(count = 100)
12
+ ::RailsAdmin::History.latest(count)
13
13
  end
14
14
 
15
15
  def delete_object(object, model, user)
@@ -11,8 +11,8 @@ module RailsAdmin
11
11
  default_scope { order('id DESC') }
12
12
 
13
13
  class << self
14
- def latest
15
- limit(100)
14
+ def latest(count = 100)
15
+ limit(count)
16
16
  end
17
17
 
18
18
  def create_history_item(message, object, abstract_model, user)
@@ -63,8 +63,10 @@ module RailsAdmin
63
63
  end
64
64
  end
65
65
 
66
- def latest
67
- @version_class.order('id DESC').limit(100).collect { |version| VersionProxy.new(version, @user_class) }
66
+ def latest(count = 100)
67
+ @version_class.
68
+ order(id: :desc).includes(:item).limit(count).
69
+ collect { |version| VersionProxy.new(version, @user_class) }
68
70
  end
69
71
 
70
72
  def delete_object(_object, _model, _user)
@@ -1,7 +1,7 @@
1
1
  module RailsAdmin
2
2
  class Version
3
3
  MAJOR = 1
4
- MINOR = 2
4
+ MINOR = 3
5
5
  PATCH = 0
6
6
  PRE = nil
7
7
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Michaels-Ober
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2017-05-31 00:00:00.000000000 Z
15
+ date: 2018-02-18 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: builder
@@ -421,6 +421,9 @@ files:
421
421
  - app/views/kaminari/ra-twitter-bootstrap/_page.html.haml
422
422
  - app/views/kaminari/ra-twitter-bootstrap/_paginator.html.haml
423
423
  - app/views/kaminari/ra-twitter-bootstrap/_prev_page.html.haml
424
+ - app/views/kaminari/ra-twitter-bootstrap/without_count/_next_page.html.haml
425
+ - app/views/kaminari/ra-twitter-bootstrap/without_count/_paginator.html.haml
426
+ - app/views/kaminari/ra-twitter-bootstrap/without_count/_prev_page.html.haml
424
427
  - app/views/layouts/rails_admin/_navigation.html.haml
425
428
  - app/views/layouts/rails_admin/_secondary_navigation.html.haml
426
429
  - app/views/layouts/rails_admin/_sidebar_navigation.html.haml
@@ -442,6 +445,7 @@ files:
442
445
  - app/views/rails_admin/main/_form_nested_many.html.haml
443
446
  - app/views/rails_admin/main/_form_nested_one.html.haml
444
447
  - app/views/rails_admin/main/_form_polymorphic_association.html.haml
448
+ - app/views/rails_admin/main/_form_simple_mde.haml
445
449
  - app/views/rails_admin/main/_form_text.html.haml
446
450
  - app/views/rails_admin/main/_form_wysihtml5.html.haml
447
451
  - app/views/rails_admin/main/_submit_buttons.html.haml
@@ -535,6 +539,7 @@ files:
535
539
  - lib/rails_admin/config/fields/types/polymorphic_association.rb
536
540
  - lib/rails_admin/config/fields/types/refile.rb
537
541
  - lib/rails_admin/config/fields/types/serialized.rb
542
+ - lib/rails_admin/config/fields/types/simple_mde.rb
538
543
  - lib/rails_admin/config/fields/types/string.rb
539
544
  - lib/rails_admin/config/fields/types/text.rb
540
545
  - lib/rails_admin/config/fields/types/time.rb