active_scaffold 3.5.5 → 3.6.0.pre
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.
- checksums.yaml +4 -4
- data/CHANGELOG +18 -2
- data/README.md +17 -7
- data/app/assets/javascripts/jquery/active_scaffold.js +28 -2
- data/app/views/active_scaffold_overrides/_base_form.html.erb +2 -2
- data/app/views/active_scaffold_overrides/_form.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_form_association_footer.html.erb +3 -2
- data/app/views/active_scaffold_overrides/_form_association_record.html.erb +6 -6
- data/app/views/active_scaffold_overrides/_horizontal_subform.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_horizontal_subform_header.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_list.html.erb +2 -1
- data/app/views/active_scaffold_overrides/_list_messages.html.erb +1 -0
- data/app/views/active_scaffold_overrides/_messages.html.erb +1 -0
- data/app/views/active_scaffold_overrides/_render_field.js.erb +2 -1
- data/app/views/active_scaffold_overrides/_show_association_horizontal.html.erb +2 -1
- data/app/views/active_scaffold_overrides/_show_columns.html.erb +2 -2
- data/app/views/active_scaffold_overrides/_show_horizontal_record.html.erb +4 -4
- data/app/views/active_scaffold_overrides/_update_calculations.js.erb +1 -1
- data/app/views/active_scaffold_overrides/_update_column.js.erb +2 -2
- data/app/views/active_scaffold_overrides/action_confirmation.html.erb +2 -2
- data/app/views/active_scaffold_overrides/delete.html.erb +2 -2
- data/app/views/active_scaffold_overrides/on_action_update.js.erb +16 -6
- data/app/views/active_scaffold_overrides/on_update.js.erb +1 -1
- data/app/views/active_scaffold_overrides/row.js.erb +1 -1
- data/app/views/active_scaffold_overrides/update_column.js.erb +1 -1
- data/lib/active_scaffold.rb +11 -13
- data/lib/active_scaffold/actions/core.rb +25 -35
- data/lib/active_scaffold/actions/create.rb +1 -1
- data/lib/active_scaffold/actions/delete.rb +2 -2
- data/lib/active_scaffold/actions/field_search.rb +2 -2
- data/lib/active_scaffold/actions/list.rb +8 -7
- data/lib/active_scaffold/actions/nested.rb +9 -9
- data/lib/active_scaffold/actions/search.rb +1 -1
- data/lib/active_scaffold/actions/show.rb +1 -1
- data/lib/active_scaffold/actions/subform.rb +3 -1
- data/lib/active_scaffold/actions/update.rb +5 -4
- data/lib/active_scaffold/active_record_permissions.rb +2 -11
- data/lib/active_scaffold/attribute_params.rb +16 -23
- data/lib/active_scaffold/bridges.rb +8 -8
- data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +1 -1
- data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +1 -1
- data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +3 -18
- data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +1 -1
- data/lib/active_scaffold/bridges/chosen/helpers.rb +7 -6
- data/lib/active_scaffold/bridges/date_picker/ext.rb +0 -13
- data/lib/active_scaffold/bridges/date_picker/helper.rb +3 -3
- data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +1 -1
- data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +3 -3
- data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +8 -7
- data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +2 -4
- data/lib/active_scaffold/bridges/paper_trail.rb +1 -1
- data/lib/active_scaffold/bridges/paperclip/list_ui.rb +1 -1
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +1 -1
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb +2 -2
- data/lib/active_scaffold/bridges/record_select/helpers.rb +9 -9
- data/lib/active_scaffold/bridges/shared/date_bridge.rb +3 -3
- data/lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb +1 -1
- data/lib/active_scaffold/config/base.rb +89 -21
- data/lib/active_scaffold/config/core.rb +127 -18
- data/lib/active_scaffold/config/delete.rb +2 -0
- data/lib/active_scaffold/config/field_search.rb +7 -1
- data/lib/active_scaffold/config/form.rb +10 -1
- data/lib/active_scaffold/config/list.rb +27 -11
- data/lib/active_scaffold/config/mark.rb +3 -1
- data/lib/active_scaffold/config/nested.rb +16 -17
- data/lib/active_scaffold/config/search.rb +9 -0
- data/lib/active_scaffold/config/show.rb +4 -0
- data/lib/active_scaffold/config/update.rb +4 -0
- data/lib/active_scaffold/configurable.rb +11 -6
- data/lib/active_scaffold/constraints.rb +1 -1
- data/lib/active_scaffold/core.rb +46 -16
- data/lib/active_scaffold/data_structures/action_columns.rb +50 -59
- data/lib/active_scaffold/data_structures/action_link.rb +20 -8
- data/lib/active_scaffold/data_structures/action_links.rb +6 -2
- data/lib/active_scaffold/data_structures/association/abstract.rb +9 -5
- data/lib/active_scaffold/data_structures/association/active_record.rb +1 -1
- data/lib/active_scaffold/data_structures/column.rb +51 -33
- data/lib/active_scaffold/data_structures/nested_info.rb +1 -1
- data/lib/active_scaffold/data_structures/set.rb +8 -0
- data/lib/active_scaffold/data_structures/sorting.rb +5 -2
- data/lib/active_scaffold/delayed_setup.rb +2 -1
- data/lib/active_scaffold/extensions/action_controller_rendering.rb +2 -1
- data/lib/active_scaffold/extensions/action_view_rendering.rb +1 -1
- data/lib/active_scaffold/extensions/cow_proxy.rb +43 -0
- data/lib/active_scaffold/extensions/ice_nine.rb +36 -0
- data/lib/active_scaffold/extensions/left_outer_joins.rb +8 -33
- data/lib/active_scaffold/extensions/routing_mapper.rb +4 -43
- data/lib/active_scaffold/extensions/unsaved_record.rb +2 -4
- data/lib/active_scaffold/finder.rb +26 -30
- data/lib/active_scaffold/helpers/action_link_helpers.rb +16 -16
- data/lib/active_scaffold/helpers/association_helpers.rb +5 -5
- data/lib/active_scaffold/helpers/controller_helpers.rb +11 -1
- data/lib/active_scaffold/helpers/form_column_helpers.rb +25 -24
- data/lib/active_scaffold/helpers/id_helpers.rb +2 -2
- data/lib/active_scaffold/helpers/list_column_helpers.rb +8 -6
- data/lib/active_scaffold/helpers/search_column_helpers.rb +4 -4
- data/lib/active_scaffold/helpers/view_helpers.rb +7 -13
- data/lib/active_scaffold/marked_model.rb +2 -2
- data/lib/active_scaffold/orm_checks.rb +1 -5
- data/lib/active_scaffold/paginator.rb +6 -4
- data/lib/active_scaffold/registry.rb +22 -0
- data/lib/active_scaffold/responds_to_parent.rb +2 -6
- data/lib/active_scaffold/tableless.rb +63 -59
- data/lib/active_scaffold/version.rb +2 -2
- data/lib/generators/active_scaffold/controller_generator.rb +2 -2
- data/lib/generators/active_scaffold/install_generator.rb +1 -1
- data/lib/generators/active_scaffold/resource_generator.rb +2 -2
- data/test/bridges/date_picker_test.rb +1 -2
- data/test/bridges/paperclip_test.rb +5 -5
- data/test/class_with_finder.rb +2 -2
- data/test/company.rb +2 -2
- data/test/config/create_test.rb +4 -2
- data/test/config/nested_test.rb +1 -1
- data/test/config/show_test.rb +1 -1
- data/test/config/update_test.rb +7 -6
- data/test/data_structures/action_links_test.rb +1 -1
- data/test/data_structures/sorting_test.rb +7 -0
- data/test/misc/active_record_permissions_test.rb +1 -9
- data/test/misc/attribute_params_test.rb +8 -8
- data/test/misc/calculation_test.rb +1 -1
- data/test/misc/constraints_test.rb +2 -2
- data/test/misc/convert_numbers_format_test.rb +3 -3
- data/test/misc/lang_test.rb +1 -1
- data/test/misc/parse_datetime_test.rb +3 -4
- data/test/misc/tableless_test.rb +6 -0
- data/test/mock_app/Rakefile +1 -1
- data/test/mock_app/config/application.rb +1 -1
- data/test/mock_app/config/boot.rb +1 -1
- data/test/mock_app/config/environment.rb +2 -2
- data/test/test_helper.rb +8 -1
- metadata +38 -13
@@ -32,11 +32,11 @@ module ActiveScaffold
|
|
32
32
|
klass = association_klass_scoped(association, klass, record)
|
33
33
|
relation = klass.where(conditions)
|
34
34
|
column = column_for_association(association, record)
|
35
|
-
if column
|
35
|
+
if column&.includes
|
36
36
|
include_assoc = column.includes.find { |assoc| assoc.is_a?(Hash) && assoc.include?(association.name) }
|
37
37
|
relation = relation.includes(include_assoc[association.name]) if include_assoc
|
38
38
|
end
|
39
|
-
if column
|
39
|
+
if column&.sort && column.sort&.dig(:sql)
|
40
40
|
relation = relation.order(column.sort[:sql])
|
41
41
|
end
|
42
42
|
relation = yield(relation) if block_given?
|
@@ -49,12 +49,12 @@ module ActiveScaffold
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def association_klass_scoped(association, klass, record)
|
52
|
-
if nested? && nested.through_association? && nested.child_association
|
52
|
+
if nested? && nested.through_association? && nested.child_association&.through_reflection == association
|
53
53
|
# only ActiveRecord associations
|
54
54
|
if nested.association.through_reflection.collection?
|
55
55
|
nested_parent_record.send(nested.association.through_reflection.name)
|
56
56
|
else
|
57
|
-
klass.where(association.association_primary_key => nested_parent_record.send(nested.association.through_reflection.name)
|
57
|
+
klass.where(association.association_primary_key => nested_parent_record.send(nested.association.through_reflection.name)&.id)
|
58
58
|
end
|
59
59
|
else
|
60
60
|
klass
|
@@ -65,7 +65,7 @@ module ActiveScaffold
|
|
65
65
|
def sorted_association_options_find(association, conditions = nil, record = nil)
|
66
66
|
options = association_options_find(association, conditions, nil, record)
|
67
67
|
column = column_for_association(association, record)
|
68
|
-
unless column
|
68
|
+
unless column&.sort && column.sort&.dig(:sql)
|
69
69
|
method = column.options[:label_method] if column
|
70
70
|
options = options.sort_by(&(method || :to_label).to_sym)
|
71
71
|
end
|
@@ -8,13 +8,23 @@ module ActiveScaffold
|
|
8
8
|
:main_path_to_return, :render_parent_options,
|
9
9
|
:render_parent_action, :nested_singular_association?,
|
10
10
|
:main_form_controller, :build_associated,
|
11
|
-
:generate_temporary_id, :generated_id
|
11
|
+
:generate_temporary_id, :generated_id,
|
12
|
+
:active_scaffold_config_for
|
12
13
|
end
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
16
17
|
include ActiveScaffold::Helpers::IdHelpers
|
17
18
|
|
19
|
+
def active_scaffold_config_for(klass)
|
20
|
+
config = self.class.active_scaffold_config_for(klass)
|
21
|
+
if ActiveScaffold.threadsafe
|
22
|
+
config.user || config.new_user_settings({}, {})
|
23
|
+
else
|
24
|
+
config
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
18
28
|
def generate_temporary_id(record = nil, generated_id = nil)
|
19
29
|
(generated_id || (Time.now.to_f * 1000).to_i.to_s).tap do |id|
|
20
30
|
(@temporary_ids ||= {})[record.class.name] = id if record
|
@@ -66,9 +66,7 @@ module ActiveScaffold
|
|
66
66
|
col_class = col_class.join(' ')
|
67
67
|
end
|
68
68
|
if readonly && !record.new_record? || !record.authorized_for?(:crud_type => crud_type, :column => column.name)
|
69
|
-
|
70
|
-
options[:class] = "#{options[:class]} #{col_class}" if col_class
|
71
|
-
content_tag :span, get_column_value(record, column), options
|
69
|
+
form_attribute(column, record, scope, true, col_class)
|
72
70
|
else
|
73
71
|
renders_as = column_renders_as(column)
|
74
72
|
html = render_column(column, record, renders_as, scope, false, col_class)
|
@@ -86,7 +84,7 @@ module ActiveScaffold
|
|
86
84
|
|
87
85
|
# the standard active scaffold options used for textual inputs
|
88
86
|
def active_scaffold_input_text_options(options = {})
|
89
|
-
options[:autocomplete]
|
87
|
+
options[:autocomplete] ||= 'off'
|
90
88
|
options[:class] = "#{options[:class]} text-input".strip
|
91
89
|
options
|
92
90
|
end
|
@@ -97,7 +95,7 @@ module ActiveScaffold
|
|
97
95
|
record = options[:object]
|
98
96
|
|
99
97
|
# Add some HTML5 attributes for in-browser validation and better user experience
|
100
|
-
if column.required? && (!@disable_required_for_new || scope.nil? || record
|
98
|
+
if column.required? && (!@disable_required_for_new || scope.nil? || record&.persisted?)
|
101
99
|
options[:required] = true
|
102
100
|
end
|
103
101
|
options[:placeholder] = column.placeholder if column.placeholder.present?
|
@@ -114,18 +112,20 @@ module ActiveScaffold
|
|
114
112
|
|
115
113
|
def current_form_columns(record, scope, subform_controller = nil)
|
116
114
|
if scope
|
117
|
-
subform_controller.active_scaffold_config.subform.columns.
|
115
|
+
subform_controller.active_scaffold_config.subform.columns.visible_columns_names
|
118
116
|
elsif %i[new create edit update render_field].include? action_name.to_sym
|
119
117
|
# disable update_columns for inplace_edit (GET render_field)
|
120
118
|
return if action_name == 'render_field' && request.get?
|
121
|
-
active_scaffold_config.send(record.new_record? ? :create : :update).columns.
|
119
|
+
active_scaffold_config.send(record.new_record? ? :create : :update).columns.visible_columns_names
|
122
120
|
end
|
123
121
|
end
|
124
122
|
|
125
123
|
def update_columns_options(column, scope, options, force = false)
|
126
124
|
record = options[:object]
|
127
125
|
subform_controller = controller.class.active_scaffold_controller_for(record.class) if scope
|
128
|
-
|
126
|
+
if @main_columns && (scope.nil? || subform_controller == controller.class)
|
127
|
+
form_columns = @main_columns.visible_columns_names
|
128
|
+
end
|
129
129
|
form_columns ||= current_form_columns(record, scope, subform_controller)
|
130
130
|
if force || (form_columns && column.update_columns && (column.update_columns & form_columns).present?)
|
131
131
|
url_params = params_for(:action => 'render_field', :column => column.name, :id => record.to_param)
|
@@ -134,7 +134,7 @@ module ActiveScaffold
|
|
134
134
|
url_params = url_params.except(:parent_scaffold, :association, nested.param_name)
|
135
135
|
end
|
136
136
|
if scope
|
137
|
-
url_params[:parent_controller] ||= url_params[:controller].gsub(
|
137
|
+
url_params[:parent_controller] ||= url_params[:controller].gsub(%r{/^//}, '')
|
138
138
|
url_params[:controller] = subform_controller.controller_path
|
139
139
|
url_params[:scope] = scope
|
140
140
|
url_params[:parent_id] = params[:parent_id] || params[:id]
|
@@ -189,7 +189,7 @@ module ActiveScaffold
|
|
189
189
|
end
|
190
190
|
|
191
191
|
def label_for(column, options)
|
192
|
-
options[:id] unless column.form_ui == :select && column.association
|
192
|
+
options[:id] unless column.form_ui == :select && column.association&.collection?
|
193
193
|
end
|
194
194
|
|
195
195
|
def subform_label(column, hidden)
|
@@ -205,7 +205,7 @@ module ActiveScaffold
|
|
205
205
|
|
206
206
|
def form_hidden_field(column, record, scope)
|
207
207
|
options = active_scaffold_input_options(column, scope)
|
208
|
-
if column.association
|
208
|
+
if column.association&.collection?
|
209
209
|
associated = record.send(column.name)
|
210
210
|
if associated.blank?
|
211
211
|
hidden_field_tag options[:name], '', options
|
@@ -217,7 +217,7 @@ module ActiveScaffold
|
|
217
217
|
safe_join fields, ''
|
218
218
|
end
|
219
219
|
elsif column.association
|
220
|
-
hidden_field_tag options[:name], record.send(column.name)
|
220
|
+
hidden_field_tag options[:name], record.send(column.name)&.id, options
|
221
221
|
else
|
222
222
|
hidden_field :record, column.name, options.merge(object: record)
|
223
223
|
end
|
@@ -245,7 +245,7 @@ module ActiveScaffold
|
|
245
245
|
end
|
246
246
|
|
247
247
|
def column_show_add_existing(column, record = nil)
|
248
|
-
column.allow_add_existing && options_for_association_count(column.association, record)
|
248
|
+
column.allow_add_existing && options_for_association_count(column.association, record).positive?
|
249
249
|
end
|
250
250
|
|
251
251
|
def column_show_add_new(column, associated, record)
|
@@ -263,7 +263,7 @@ module ActiveScaffold
|
|
263
263
|
def active_scaffold_grouped_options(column, select_options, optgroup)
|
264
264
|
group_column = active_scaffold_config_for(column.association.klass).columns[optgroup]
|
265
265
|
group_label = group_column.options[:label_method] if group_column
|
266
|
-
group_label ||= group_column
|
266
|
+
group_label ||= group_column&.association ? :to_label : :to_s
|
267
267
|
select_options.group_by(&optgroup.to_sym).collect do |group, options|
|
268
268
|
[group.send(group_label), options.collect { |r| [r.send(column.options[:label_method] || :to_label), r.id] }]
|
269
269
|
end
|
@@ -289,7 +289,7 @@ module ActiveScaffold
|
|
289
289
|
select_options.unshift(associated) unless associated.nil? || select_options.include?(associated)
|
290
290
|
|
291
291
|
method = column.name
|
292
|
-
options.merge! :selected => associated
|
292
|
+
options.merge! :selected => associated&.id, :include_blank => as_(:_select_), :object => record
|
293
293
|
|
294
294
|
html_options.merge!(column.options[:html_options] || {})
|
295
295
|
options.merge!(column.options)
|
@@ -345,7 +345,7 @@ module ActiveScaffold
|
|
345
345
|
link_options['data-update_send_form'] = html_options['data-update_send_form']
|
346
346
|
link_options['data-update_send_form_selector'] = html_options['data-update_send_form_selector']
|
347
347
|
else
|
348
|
-
scope = html_options[:name].scan(/^record((\[[^\]]*\])*)\[#{column.name}\]/)
|
348
|
+
scope = html_options[:name].scan(/^record((\[[^\]]*\])*)\[#{column.name}\]/).dig(0, 0) if html_options[:name]
|
349
349
|
link_options = update_columns_options(column, scope.presence, link_options, true)
|
350
350
|
end
|
351
351
|
link_options[:class] = 'refresh-link'
|
@@ -418,9 +418,9 @@ module ActiveScaffold
|
|
418
418
|
end
|
419
419
|
|
420
420
|
def active_scaffold_input_select(column, html_options)
|
421
|
-
if column.association
|
421
|
+
if column.association&.singular?
|
422
422
|
active_scaffold_input_singular_association(column, html_options)
|
423
|
-
elsif column.association
|
423
|
+
elsif column.association&.collection?
|
424
424
|
active_scaffold_input_plural_association(column, html_options)
|
425
425
|
else
|
426
426
|
active_scaffold_input_enum(column, html_options)
|
@@ -430,7 +430,8 @@ module ActiveScaffold
|
|
430
430
|
def active_scaffold_radio_option(option, selected, column, radio_options)
|
431
431
|
if column.association
|
432
432
|
label_method = column.options[:label_method] || :to_label
|
433
|
-
text
|
433
|
+
text = option.send(label_method)
|
434
|
+
value = option.id
|
434
435
|
checked = {:checked => selected == value}
|
435
436
|
else
|
436
437
|
text, value = active_scaffold_translated_option(column, *option)
|
@@ -452,7 +453,7 @@ module ActiveScaffold
|
|
452
453
|
active_scaffold_enum_options(column, record)
|
453
454
|
end
|
454
455
|
|
455
|
-
selected = record.send(column.association.name)
|
456
|
+
selected = record.send(column.association.name)&.id if column.association
|
456
457
|
radios = options.map do |option|
|
457
458
|
active_scaffold_radio_option(option, selected, column, html_options)
|
458
459
|
end
|
@@ -464,7 +465,7 @@ module ActiveScaffold
|
|
464
465
|
end
|
465
466
|
|
466
467
|
def active_scaffold_input_password(column, options)
|
467
|
-
active_scaffold_text_input :password_field, column, options
|
468
|
+
active_scaffold_text_input :password_field, column, options.reverse_merge(autocomplete: 'new-password')
|
468
469
|
end
|
469
470
|
|
470
471
|
def active_scaffold_input_textarea(column, options)
|
@@ -519,7 +520,7 @@ module ActiveScaffold
|
|
519
520
|
# A color picker
|
520
521
|
def active_scaffold_input_color(column, options)
|
521
522
|
options = active_scaffold_input_text_options(options)
|
522
|
-
if column.column
|
523
|
+
if column.column&.null
|
523
524
|
no_color = options[:object].send(column.name).nil?
|
524
525
|
method = no_color ? :hidden_field : :color_field
|
525
526
|
html = content_tag(:label, check_box_tag('disable', '1', no_color, id: nil, name: nil, class: 'no-color') << " #{as_ column.options[:no_color] || :no_color}")
|
@@ -622,7 +623,7 @@ module ActiveScaffold
|
|
622
623
|
end
|
623
624
|
|
624
625
|
def column_scope(column, scope = nil, record = nil)
|
625
|
-
if column.association
|
626
|
+
if column.association&.collection?
|
626
627
|
"#{scope}[#{column.name}][#{record.id || generate_temporary_id(record)}]"
|
627
628
|
else
|
628
629
|
"#{scope}[#{column.name}]"
|
@@ -689,7 +690,7 @@ module ActiveScaffold
|
|
689
690
|
only_odd_valid = validators.any? { |v| v.options[:odd] }
|
690
691
|
only_even_valid = validators.any? { |v| v.options[:even] } unless only_odd_valid
|
691
692
|
if !only_integer
|
692
|
-
numerical_constraints[:step] ||= "0.#{'0' * (column.column.scale - 1)}1" if column.column
|
693
|
+
numerical_constraints[:step] ||= "0.#{'0' * (column.column.scale - 1)}1" if column.column&.scale.to_i.positive?
|
693
694
|
elsif options[:min] && options[:min].respond_to?(:even?) && (only_odd_valid || only_even_valid)
|
694
695
|
numerical_constraints[:step] = 2
|
695
696
|
numerical_constraints[:min] += 1 if only_odd_valid && options[:min].even?
|
@@ -14,8 +14,8 @@ module ActiveScaffold
|
|
14
14
|
nested_parent_record.id
|
15
15
|
end
|
16
16
|
|
17
|
-
def nested_id(controller =
|
18
|
-
"#{nested.parent_scaffold.controller_path}-#{nested_parent_id}-#{controller}" if nested?
|
17
|
+
def nested_id(controller = nil)
|
18
|
+
"#{nested.parent_scaffold.controller_path}-#{nested_parent_id}-#{controller || params[:parent_controller] || params[:controller]}" if nested?
|
19
19
|
end
|
20
20
|
|
21
21
|
def active_scaffold_id
|
@@ -11,7 +11,7 @@ module ActiveScaffold
|
|
11
11
|
value = nil
|
12
12
|
end
|
13
13
|
value = ' '.html_safe if value.nil? || value.blank? # fix for IE 6
|
14
|
-
|
14
|
+
value
|
15
15
|
rescue StandardError => e
|
16
16
|
logger.error "#{e.class.name}: #{e.message} -- on the ActiveScaffold column = :#{column.name} in #{controller.class}, record: #{record.inspect}"
|
17
17
|
raise e
|
@@ -249,7 +249,7 @@ module ActiveScaffold
|
|
249
249
|
# we are not using eager loading, cache firsts records in order not to query the database for whole association in a future
|
250
250
|
if column.associated_limit.nil?
|
251
251
|
logger.warn "ActiveScaffold: Enable eager loading for #{column.name} association to reduce SQL queries"
|
252
|
-
elsif column.associated_limit
|
252
|
+
elsif column.associated_limit.positive?
|
253
253
|
# load at least one record more, is needed to display '...'
|
254
254
|
association.target = association.reader.limit(column.associated_limit + 1).select(column.select_associated_columns || "#{association.klass.quoted_table_name}.*").to_a
|
255
255
|
elsif @cache_associations
|
@@ -295,8 +295,10 @@ module ActiveScaffold
|
|
295
295
|
|
296
296
|
def inplace_edit_control(column)
|
297
297
|
return unless inplace_edit?(active_scaffold_config.model, column) && inplace_edit_cloning?(column)
|
298
|
-
|
299
|
-
|
298
|
+
unless ActiveScaffold.threadsafe
|
299
|
+
column = column.dup
|
300
|
+
column.options = column.options.dup
|
301
|
+
end
|
300
302
|
column.form_ui = :select if column.association && column.form_ui.nil?
|
301
303
|
options = active_scaffold_input_options(column).merge(:object => column.active_record_class.new)
|
302
304
|
options[:class] = "#{options[:class]} inplace_field"
|
@@ -316,7 +318,7 @@ module ActiveScaffold
|
|
316
318
|
data[:ie_loading_text] = column.options[:loading_text] || as_(:loading)
|
317
319
|
data[:ie_save_text] = column.options[:save_text] || as_(:update)
|
318
320
|
data[:ie_saving_text] = column.options[:saving_text] || as_(:saving)
|
319
|
-
data[:ie_rows] = column.options[:rows] || 5 if column.column
|
321
|
+
data[:ie_rows] = column.options[:rows] || 5 if column.column&.type == :text
|
320
322
|
data[:ie_cols] = column.options[:cols] if column.options[:cols]
|
321
323
|
data[:ie_size] = column.options[:size] if column.options[:size]
|
322
324
|
data[:ie_use_html] = column.options[:use_html] if column.options[:use_html]
|
@@ -327,7 +329,7 @@ module ActiveScaffold
|
|
327
329
|
data[:ie_mode] = :clone
|
328
330
|
elsif column.inplace_edit == :ajax
|
329
331
|
url = url_for(params_for(:controller => params_for[:controller], :action => 'render_field', :id => '__id__', :update_column => column.name))
|
330
|
-
plural = column.association
|
332
|
+
plural = column.association&.collection? && !override_form_field?(column) && %i[select record_select].include?(column.form_ui)
|
331
333
|
data[:ie_render_url] = url
|
332
334
|
data[:ie_mode] = :ajax
|
333
335
|
data[:ie_plural] = plural
|
@@ -195,9 +195,9 @@ module ActiveScaffold
|
|
195
195
|
def include_null_comparators?(column)
|
196
196
|
return column.options[:null_comparators] if column.options.key? :null_comparators
|
197
197
|
if column.association
|
198
|
-
!column.association.belongs_to? || active_scaffold_config.columns[column.association.foreign_key].column
|
198
|
+
!column.association.belongs_to? || active_scaffold_config.columns[column.association.foreign_key].column&.null
|
199
199
|
else
|
200
|
-
column.column
|
200
|
+
column.column&.null
|
201
201
|
end
|
202
202
|
end
|
203
203
|
|
@@ -225,7 +225,7 @@ module ActiveScaffold
|
|
225
225
|
content_tag(
|
226
226
|
:span,
|
227
227
|
safe_join([' - ', send(input_method, "#{options[:name]}[to]", to_value, to_options)]),
|
228
|
-
:id => "#{options[:id]}_between", :class => 'as_search_range_between', :style => (opt_value == 'BETWEEN')
|
228
|
+
:id => "#{options[:id]}_between", :class => 'as_search_range_between', :style => ('display: none' unless opt_value == 'BETWEEN')
|
229
229
|
)
|
230
230
|
end
|
231
231
|
content_tag :span, html, :class => 'search_range'
|
@@ -292,7 +292,7 @@ module ActiveScaffold
|
|
292
292
|
def visibles_and_hiddens(search_config)
|
293
293
|
visibles = []
|
294
294
|
hiddens = []
|
295
|
-
search_config.columns.
|
295
|
+
search_config.columns.each_column do |column|
|
296
296
|
next unless column.search_sql
|
297
297
|
if search_config.optional_columns.include?(column.name) && !searched_by?(column)
|
298
298
|
hiddens << column
|
@@ -17,15 +17,6 @@ module ActiveScaffold
|
|
17
17
|
## Delegates
|
18
18
|
##
|
19
19
|
|
20
|
-
# access to the configuration variable
|
21
|
-
def active_scaffold_config
|
22
|
-
controller.class.active_scaffold_config
|
23
|
-
end
|
24
|
-
|
25
|
-
def active_scaffold_config_for(*args)
|
26
|
-
controller.class.active_scaffold_config_for(*args)
|
27
|
-
end
|
28
|
-
|
29
20
|
def active_scaffold_controller_for(*args)
|
30
21
|
controller.class.active_scaffold_controller_for(*args)
|
31
22
|
end
|
@@ -44,7 +35,10 @@ module ActiveScaffold
|
|
44
35
|
# This is the template finder logic, keep it updated with however we find stuff in rails
|
45
36
|
# currently this very similar to the logic in ActionBase::Base.render for options file
|
46
37
|
def template_exists?(template_name, partial = false)
|
47
|
-
|
38
|
+
if @_view_paths
|
39
|
+
restore_view_paths = lookup_context.view_paths
|
40
|
+
lookup_context.view_paths = @_view_paths
|
41
|
+
end
|
48
42
|
lookup_context.exists?(template_name, '', partial).tap do
|
49
43
|
lookup_context.view_paths = restore_view_paths if @_view_paths
|
50
44
|
end
|
@@ -173,7 +167,7 @@ module ActiveScaffold
|
|
173
167
|
|
174
168
|
def history_state
|
175
169
|
if active_scaffold_config.store_user_settings
|
176
|
-
state = {page: @page
|
170
|
+
state = {page: @page&.number}
|
177
171
|
state[:search] = search_params if respond_to?(:search_params) && search_params.present?
|
178
172
|
if active_scaffold_config.list.user.user_sorting?
|
179
173
|
column, state[:sort_direction] = active_scaffold_config.list.user.sorting.first
|
@@ -189,12 +183,12 @@ module ActiveScaffold
|
|
189
183
|
|
190
184
|
def display_message(message)
|
191
185
|
message = safe_join message, tag(:br) if message.is_a?(Array)
|
192
|
-
if (highlights = active_scaffold_config.highlight_messages)
|
186
|
+
if (highlights = active_scaffold_config.user.highlight_messages)
|
193
187
|
message = highlights.inject(message) do |msg, (phrases, highlighter)|
|
194
188
|
highlight(msg, phrases, highlighter || {})
|
195
189
|
end
|
196
190
|
end
|
197
|
-
if (format = active_scaffold_config.timestamped_messages)
|
191
|
+
if (format = active_scaffold_config.user.timestamped_messages)
|
198
192
|
format = :short if format == true
|
199
193
|
messages = [content_tag(:div, l(Time.current, :format => format), :class => 'timestamp')]
|
200
194
|
messages << content_tag(:div, message, :class => 'message-content')
|
@@ -24,11 +24,11 @@ module ActiveScaffold
|
|
24
24
|
|
25
25
|
module ClassMethods
|
26
26
|
def marked_records
|
27
|
-
|
27
|
+
ActiveScaffold::Registry.marked_records ||= {}
|
28
28
|
end
|
29
29
|
|
30
30
|
def marked_records=(marked)
|
31
|
-
|
31
|
+
ActiveScaffold::Registry.marked_records = marked
|
32
32
|
end
|
33
33
|
|
34
34
|
def marked_record_ids
|
@@ -69,11 +69,7 @@ module ActiveScaffold
|
|
69
69
|
|
70
70
|
def type_for_attribute(klass, column_name)
|
71
71
|
if active_record? klass
|
72
|
-
|
73
|
-
klass.type_for_attribute column_name.to_s
|
74
|
-
else # Rails.version < 4.2
|
75
|
-
klass.column_types[column_name.to_s]
|
76
|
-
end
|
72
|
+
klass.type_for_attribute column_name.to_s
|
77
73
|
elsif mongoid? klass
|
78
74
|
klass.fields[column_name.to_s].type
|
79
75
|
end
|
@@ -19,7 +19,8 @@ class Paginator
|
|
19
19
|
# (and the number of items to show per page, for
|
20
20
|
# convenience, if the arity is 2)
|
21
21
|
def initialize(count, per_page, &select)
|
22
|
-
@count
|
22
|
+
@count = count
|
23
|
+
@per_page = per_page
|
23
24
|
unless select
|
24
25
|
raise MissingSelectError, 'Must provide block to select data for each page'
|
25
26
|
end
|
@@ -28,7 +29,7 @@ class Paginator
|
|
28
29
|
|
29
30
|
# Total number of pages
|
30
31
|
def number_of_pages
|
31
|
-
(@count / @per_page).to_i + (@count % @per_page
|
32
|
+
(@count / @per_page).to_i + ((@count % @per_page).positive? ? 1 : 0)
|
32
33
|
end
|
33
34
|
|
34
35
|
# First page object
|
@@ -57,7 +58,7 @@ class Paginator
|
|
57
58
|
|
58
59
|
# Retrieve page object by number
|
59
60
|
def page(number)
|
60
|
-
number =
|
61
|
+
number = [1, number.to_i].max
|
61
62
|
Page.new(self, number) do
|
62
63
|
offset = (number - 1) * @per_page
|
63
64
|
args = [offset]
|
@@ -80,7 +81,8 @@ class Paginator
|
|
80
81
|
attr_reader :number, :pager
|
81
82
|
|
82
83
|
def initialize(pager, number, &select) #:nodoc:
|
83
|
-
@pager
|
84
|
+
@pager = pager
|
85
|
+
@number = number
|
84
86
|
@offset = (number - 1) * pager.per_page
|
85
87
|
@select = select
|
86
88
|
end
|