active_scaffold 3.7.5 → 3.7.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.rdoc +13 -0
- data/app/views/active_scaffold_overrides/action_confirmation.html.erb +1 -1
- data/lib/active_scaffold/actions/common_search.rb +3 -3
- data/lib/active_scaffold/actions/core.rb +14 -2
- data/lib/active_scaffold/actions/field_search.rb +29 -18
- data/lib/active_scaffold/actions/update.rb +7 -5
- data/lib/active_scaffold/core.rb +2 -2
- data/lib/active_scaffold/data_structures/action_link.rb +9 -2
- data/lib/active_scaffold/data_structures/action_links.rb +9 -2
- data/lib/active_scaffold/data_structures/column.rb +16 -8
- data/lib/active_scaffold/data_structures/sorting.rb +3 -3
- data/lib/active_scaffold/finder.rb +1 -1
- data/lib/active_scaffold/helpers/action_link_helpers.rb +6 -6
- data/lib/active_scaffold/helpers/association_helpers.rb +2 -2
- data/lib/active_scaffold/helpers/controller_helpers.rb +1 -0
- data/lib/active_scaffold/helpers/list_column_helpers.rb +5 -2
- data/lib/active_scaffold/helpers/view_helpers.rb +1 -1
- data/lib/active_scaffold/orm_checks.rb +2 -2
- data/lib/active_scaffold/version.rb +1 -1
- data/test/misc/finder_test.rb +5 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5777dd56be3d144f2c62d8b2fa3cf8a0e765155d3afd445b5d150ce25c203155
|
4
|
+
data.tar.gz: 2c2ef1fbe12d539b84d81d48d1a2d373f3634a864664d61ab27099c783f404c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e13283f6ae89cf8618e070ee0e6afa87a47389eaee7043a669ab771f82c6aec2dbbdf2317c57ca6872785622e601d0d1278140e53cf24ca5245a88f9353dfe97
|
7
|
+
data.tar.gz: ea569709001c16bae097715c62fe9a9717597c288b2504d2c930e55aa01b28e77b53c29583d3e0462c86f329aebae8c8a82d73c832b14332a8999ee777d42e3c
|
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
= 3.7.7
|
2
|
+
- Fix usage with mongoid, broken on 3.7.5
|
3
|
+
- Support proc or lambda in label of action links
|
4
|
+
- Set successful to false when update_column is not authorized for the column
|
5
|
+
- Use action link's label for flash message when custom action is not authorized
|
6
|
+
- Add default_value to columns, so default_value can be defined in AS config, overriding DB default
|
7
|
+
- Fix caching query from association_klass_scoped in subforms, when returns different queries for the same association on different rows
|
8
|
+
|
9
|
+
= 3.7.6
|
10
|
+
- Respect :label_method set in form_ui_options on list.
|
11
|
+
- Fix grouped search for PostgreSQL
|
12
|
+
- Fix loading current search params when search form is open and store_user_settings is disabled
|
13
|
+
|
1
14
|
= 3.7.5
|
2
15
|
- Fix always show search for nested list on multi-level through associations
|
3
16
|
- Support changing step, min and max options with column options or search_ui options for decimal and integer search_ui
|
@@ -4,7 +4,7 @@
|
|
4
4
|
<h4><%= link.confirm(h(record&.to_label)) -%></h4>
|
5
5
|
|
6
6
|
<p class="form-footer">
|
7
|
-
<%= submit_tag as_(link.label), :class => 'submit' %>
|
7
|
+
<%= submit_tag as_(link.label(record)), :class => 'submit' %>
|
8
8
|
<%= link_to as_(:cancel), main_path_to_return, :class => 'cancel' %>
|
9
9
|
</p>
|
10
10
|
|
@@ -3,9 +3,9 @@ module ActiveScaffold::Actions
|
|
3
3
|
def self.included(base)
|
4
4
|
return if base < InstanceMethods
|
5
5
|
base.send :include, InstanceMethods
|
6
|
-
base.before_action :search_authorized_filter, :
|
7
|
-
base.before_action :store_search_params_into_session, :only => [
|
8
|
-
base.before_action :do_search, :
|
6
|
+
base.before_action :search_authorized_filter, only: :show_search
|
7
|
+
base.before_action :store_search_params_into_session, :only => %i[index show_search]
|
8
|
+
base.before_action :do_search, only: [:index]
|
9
9
|
base.helper_method :search_params
|
10
10
|
end
|
11
11
|
|
@@ -294,7 +294,7 @@ module ActiveScaffold::Actions
|
|
294
294
|
end
|
295
295
|
end
|
296
296
|
|
297
|
-
def
|
297
|
+
def empty_model
|
298
298
|
relation = beginning_of_chain
|
299
299
|
if nested? && nested.plural_association? && nested.match_model?(active_scaffold_config.model)
|
300
300
|
build_options = sti_nested_build_options(relation.klass)
|
@@ -302,6 +302,18 @@ module ActiveScaffold::Actions
|
|
302
302
|
relation.respond_to?(:build) ? relation.build(build_options || {}) : relation.new
|
303
303
|
end
|
304
304
|
|
305
|
+
def new_model
|
306
|
+
empty_model.tap do |record|
|
307
|
+
assign_default_attributes record
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
def assign_default_attributes(record)
|
312
|
+
active_scaffold_config.columns.each do |column|
|
313
|
+
record.write_attribute column.name, column.default_value if column.default_value?
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
305
317
|
def sti_nested_build_options(klass)
|
306
318
|
config = active_scaffold_config_for(klass)
|
307
319
|
return unless config
|
@@ -391,7 +403,7 @@ module ActiveScaffold::Actions
|
|
391
403
|
get_row(crud_type_or_security_options)
|
392
404
|
if @record.nil?
|
393
405
|
self.successful = false
|
394
|
-
flash[:error] = as_(:no_authorization_for_action, :action => action_name)
|
406
|
+
flash[:error] = as_(:no_authorization_for_action, :action => @action_link&.label(nil) || action_name)
|
395
407
|
else
|
396
408
|
yield @record
|
397
409
|
end
|
@@ -12,7 +12,7 @@ module ActiveScaffold::Actions
|
|
12
12
|
# FieldSearch uses params[:search] and not @record because search conditions do not always pass the Model's validations.
|
13
13
|
# This facilitates for example, textual searches against associations via .search_sql
|
14
14
|
def show_search
|
15
|
-
@record =
|
15
|
+
@record = empty_model
|
16
16
|
super
|
17
17
|
end
|
18
18
|
|
@@ -56,25 +56,33 @@ module ActiveScaffold::Actions
|
|
56
56
|
|
57
57
|
def custom_finder_options
|
58
58
|
if grouped_search?
|
59
|
-
|
60
|
-
select_query = grouped_search_select
|
61
|
-
select_query << group_sql.as(search_group_column.name.to_s) if search_group_column && group_sql.respond_to?(:to_sql)
|
62
|
-
{group: group_sql, select: select_query}
|
59
|
+
grouped_search_finder_options
|
63
60
|
else
|
64
61
|
super
|
65
62
|
end
|
66
63
|
end
|
67
64
|
|
65
|
+
def grouped_search_finder_options
|
66
|
+
group_sql = calculation_for_group_by(search_group_column&.field || search_group_name, search_group_function) if search_group_function
|
67
|
+
group_by = group_sql&.to_sql || quoted_select_columns(search_group_column&.select_columns || [search_group_name])
|
68
|
+
select_query = grouped_search_select + (group_sql ? [group_sql.as(search_group_column.name.to_s)] : group_by)
|
69
|
+
{group: group_by, select: select_query, reorder: grouped_sorting(group_by)}
|
70
|
+
end
|
71
|
+
|
68
72
|
def grouped_search_select
|
69
|
-
|
70
|
-
|
71
|
-
select_query << active_scaffold_config.columns[active_scaffold_config.model.inheritance_column].field
|
72
|
-
end
|
73
|
-
grouped_columns_calculations.each do |name, part|
|
74
|
-
select_query << (part.respond_to?(:as) ? part : Arel::Nodes::SqlLiteral.new(part)).as(name.to_s)
|
73
|
+
grouped_columns_calculations.map do |name, part|
|
74
|
+
(part.respond_to?(:as) ? part : Arel::Nodes::SqlLiteral.new(part)).as(name.to_s)
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
+
def grouped_sorting(group_sql)
|
79
|
+
return unless search_group_column && active_scaffold_config.list.user.sorting
|
80
|
+
group_sort = search_group_function ? group_sql : search_group_column.sort[:sql] if search_group_column.sortable?
|
81
|
+
grouped_columns = grouped_columns_calculations.merge(search_group_column.name => group_sort)
|
82
|
+
sorting = active_scaffold_config.list.user.sorting.clause(grouped_columns)
|
83
|
+
active_scaffold_config.active_record? ? sorting&.map(&Arel.method(:sql)) : sorting
|
84
|
+
end
|
85
|
+
|
78
86
|
def grouped_columns_calculations
|
79
87
|
@grouped_columns_calculations ||= list_columns[1..-1].each_with_object({}) do |c, h|
|
80
88
|
h[c.name] = calculation_for_group_search(c)
|
@@ -85,21 +93,24 @@ module ActiveScaffold::Actions
|
|
85
93
|
sql_function column.calculate.to_s, column.active_record_class.arel_table[column.name]
|
86
94
|
end
|
87
95
|
|
88
|
-
def calculation_for_group_by(group_sql)
|
89
|
-
return group_sql unless search_group_function
|
96
|
+
def calculation_for_group_by(group_sql, group_function)
|
90
97
|
group_sql = Arel::Nodes::SqlLiteral.new(group_sql)
|
91
|
-
case
|
98
|
+
case group_function
|
92
99
|
when 'year', 'month', 'quarter'
|
93
|
-
|
100
|
+
extract_sql_fn(group_function, group_sql)
|
94
101
|
when 'year_month'
|
95
|
-
|
102
|
+
sql_operator(sql_operator(extract_sql_fn('year', group_sql), '*', 100), '+', extract_sql_fn('month', group_sql))
|
96
103
|
when 'year_quarter'
|
97
|
-
sql_operator(sql_operator(
|
104
|
+
sql_operator(sql_operator(extract_sql_fn('year', group_sql), '*', 10), '+', extract_sql_fn('quarter', group_sql))
|
98
105
|
else
|
99
|
-
raise "#{
|
106
|
+
raise "#{group_function} unsupported, override calculation_for_group_by in #{self.class.name}"
|
100
107
|
end
|
101
108
|
end
|
102
109
|
|
110
|
+
def extract_sql_fn(part, column)
|
111
|
+
sql_function('extract', sql_operator(Arel::Nodes::SqlLiteral.new(part), 'FROM', column))
|
112
|
+
end
|
113
|
+
|
103
114
|
def sql_function(function, *args)
|
104
115
|
args.map! { |arg| quoted_arel_value(arg) }
|
105
116
|
Arel::Nodes::NamedFunction.new(function, args)
|
@@ -150,9 +150,8 @@ module ActiveScaffold::Actions
|
|
150
150
|
params.delete(:original_html)
|
151
151
|
params.delete(:original_value)
|
152
152
|
@column = active_scaffold_config.columns[column]
|
153
|
-
value_record = record_for_update_column
|
154
|
-
return unless value_record
|
155
153
|
|
154
|
+
value_record = record_for_update_column
|
156
155
|
value = value_for_update_column(value, @column, value_record)
|
157
156
|
value_record.send("#{@column.name}=", value)
|
158
157
|
before_update_save(@record)
|
@@ -168,16 +167,19 @@ module ActiveScaffold::Actions
|
|
168
167
|
end
|
169
168
|
end
|
170
169
|
after_update_save(@record)
|
170
|
+
rescue ActiveScaffold::ActionNotAllowed
|
171
|
+
self.successful = false
|
171
172
|
end
|
172
173
|
|
173
174
|
def record_for_update_column
|
174
175
|
@record = find_if_allowed(params[:id], :read)
|
175
|
-
|
176
|
+
raise ActiveScaffold::ActionNotAllowed unless @record.authorized_for?(:crud_type => :update, :column => @column.name)
|
176
177
|
|
177
178
|
if @column.delegated_association
|
178
179
|
value_record = @record.send(@column.delegated_association.name)
|
179
180
|
value_record ||= @record.association(@column.delegated_association.name).build
|
180
|
-
|
181
|
+
raise ActiveScaffold::ActionNotAllowed unless value_record.authorized_for?(:crud_type => :update, :column => @column.name)
|
182
|
+
value_record
|
181
183
|
else
|
182
184
|
@record
|
183
185
|
end
|
@@ -185,7 +187,7 @@ module ActiveScaffold::Actions
|
|
185
187
|
|
186
188
|
def value_for_update_column(param_value, column, record)
|
187
189
|
unless param_value
|
188
|
-
param_value =
|
190
|
+
param_value = column.default_for_empty_value
|
189
191
|
param_value = false if param_value == true
|
190
192
|
end
|
191
193
|
value = column_value_from_param_value(record, column, param_value)
|
data/lib/active_scaffold/core.rb
CHANGED
@@ -267,12 +267,12 @@ module ActiveScaffold
|
|
267
267
|
end
|
268
268
|
|
269
269
|
def self.mongoid_column_type_cast(value, column)
|
270
|
-
return Time.zone.at(value.to_i) if
|
270
|
+
return Time.zone.at(value.to_i) if [Time, DateTime].include?(column.type) && value =~ /\A\d+\z/
|
271
271
|
column.type.evolve value
|
272
272
|
end
|
273
273
|
|
274
274
|
def self.active_record_column_type_cast(value, column_or_type)
|
275
|
-
return Time.zone.at(value.to_i) if
|
275
|
+
return Time.zone.at(value.to_i) if %i[time datetime].include?(column_or_type.type) && value =~ /\A\d+\z/
|
276
276
|
cast_type = column_or_type.is_a?(ActiveRecord::ConnectionAdapters::Column) ? ActiveRecord::Type.lookup(column_or_type.type) : column_or_type
|
277
277
|
cast_type ? cast_type.cast(value) : value
|
278
278
|
end
|
@@ -77,8 +77,15 @@ module ActiveScaffold::DataStructures
|
|
77
77
|
|
78
78
|
# what string to use to represent this action
|
79
79
|
attr_writer :label
|
80
|
-
def label
|
81
|
-
|
80
|
+
def label(record = nil)
|
81
|
+
case @label
|
82
|
+
when Symbol
|
83
|
+
ActiveScaffold::Registry.cache(:translations, @label) { as_(@label) }
|
84
|
+
when Proc
|
85
|
+
@label.call(record)
|
86
|
+
else
|
87
|
+
@label
|
88
|
+
end
|
82
89
|
end
|
83
90
|
|
84
91
|
# image to use {:name => 'arrow.png', :size => '16x16'}
|
@@ -139,8 +139,15 @@ module ActiveScaffold::DataStructures
|
|
139
139
|
end
|
140
140
|
|
141
141
|
attr_writer :label
|
142
|
-
def label
|
143
|
-
|
142
|
+
def label(record)
|
143
|
+
case @label
|
144
|
+
when Symbol
|
145
|
+
ActiveScaffold::Registry.cache(:translations, @label) { as_(@label) }
|
146
|
+
when Proc
|
147
|
+
@label.call(record)
|
148
|
+
else
|
149
|
+
@label
|
150
|
+
end
|
144
151
|
end
|
145
152
|
|
146
153
|
def method_missing(name, *args, &block)
|
@@ -37,6 +37,19 @@ module ActiveScaffold::DataStructures
|
|
37
37
|
@params ||= NO_PARAMS.dup
|
38
38
|
end
|
39
39
|
|
40
|
+
def default_value
|
41
|
+
@default_value || @db_default_value
|
42
|
+
end
|
43
|
+
|
44
|
+
def default_value=(value)
|
45
|
+
raise ArgumentError, "Can't set default value for non-DB columns (virtual columns or associations)" unless column
|
46
|
+
@default_value = value
|
47
|
+
end
|
48
|
+
|
49
|
+
def default_value?
|
50
|
+
defined? @default_value
|
51
|
+
end
|
52
|
+
|
40
53
|
# the display-name of the column. this will be used, for instance, as the column title in the table and as the field name in the form.
|
41
54
|
# if left alone it will utilize human_attribute_name which includes localization
|
42
55
|
attr_writer :label
|
@@ -377,6 +390,7 @@ module ActiveScaffold::DataStructures
|
|
377
390
|
if @column.nil? && active_record? && active_record_class._default_attributes.key?(name.to_s)
|
378
391
|
@column = active_record_class._default_attributes[name.to_s]
|
379
392
|
end
|
393
|
+
@db_default_value = ActiveScaffold::OrmChecks.default_value active_record_class, name if @column
|
380
394
|
@delegated_association = delegated_association
|
381
395
|
@cache_key = [@active_record_class.name, name].compact.map(&:to_s).join('#')
|
382
396
|
setup_association_info
|
@@ -455,10 +469,8 @@ module ActiveScaffold::DataStructures
|
|
455
469
|
return nil unless column
|
456
470
|
if column.is_a?(ActiveModel::Attribute)
|
457
471
|
column.value
|
458
|
-
|
459
|
-
|
460
|
-
elsif mongoid?
|
461
|
-
column.default_val
|
472
|
+
else
|
473
|
+
default_value
|
462
474
|
end
|
463
475
|
end
|
464
476
|
|
@@ -487,10 +499,6 @@ module ActiveScaffold::DataStructures
|
|
487
499
|
ActiveScaffold::OrmChecks.column_type active_record_class, name
|
488
500
|
end
|
489
501
|
|
490
|
-
def default_value
|
491
|
-
ActiveScaffold::OrmChecks.column_type active_record_class, name
|
492
|
-
end
|
493
|
-
|
494
502
|
def attributes=(opts)
|
495
503
|
opts.each do |setting, value|
|
496
504
|
send "#{setting}=", value
|
@@ -121,14 +121,14 @@ module ActiveScaffold::DataStructures
|
|
121
121
|
end
|
122
122
|
|
123
123
|
# builds an order-by clause
|
124
|
-
def clause(
|
124
|
+
def clause(grouped_columns = nil)
|
125
125
|
return nil if sorts_by_method? || default_sorting?
|
126
126
|
|
127
127
|
# unless the sorting is by method, create the sql string
|
128
128
|
order = []
|
129
129
|
each do |sort_column, sort_direction|
|
130
130
|
next if constraint_columns.include? sort_column.name
|
131
|
-
sql =
|
131
|
+
sql = grouped_columns ? grouped_columns[sort_column.name] : sort_column.sort[:sql]
|
132
132
|
next if sql.blank?
|
133
133
|
sql = sql.to_sql if sql.respond_to?(:to_sql)
|
134
134
|
|
@@ -138,7 +138,7 @@ module ActiveScaffold::DataStructures
|
|
138
138
|
order << parts
|
139
139
|
end
|
140
140
|
|
141
|
-
order << @primary_key_order_clause if @sorting_by_primary_key
|
141
|
+
order << @primary_key_order_clause if @sorting_by_primary_key && grouped_columns.nil?
|
142
142
|
order.flatten!(1)
|
143
143
|
order unless order.empty?
|
144
144
|
end
|
@@ -577,7 +577,7 @@ module ActiveScaffold
|
|
577
577
|
def finder_options(options = {})
|
578
578
|
search_conditions = all_conditions
|
579
579
|
|
580
|
-
sorting = options[:sorting]&.clause
|
580
|
+
sorting = options[:sorting]&.clause
|
581
581
|
sorting = sorting.map(&Arel.method(:sql)) if sorting && active_scaffold_config.active_record?
|
582
582
|
# create a general-use options array that's compatible with Rails finders
|
583
583
|
finder_options = {
|
@@ -68,7 +68,7 @@ module ActiveScaffold
|
|
68
68
|
group_tag = :li
|
69
69
|
end
|
70
70
|
content = content_tag(group_tag, :class => html_classes.presence, :onclick => ('' if hover_via_click?)) do
|
71
|
-
content_tag(:div, as_(link.label), :class => link.name.to_s.downcase) << content_tag(:ul, content)
|
71
|
+
content_tag(:div, as_(link.label(record)), :class => link.name.to_s.downcase) << content_tag(:ul, content)
|
72
72
|
end
|
73
73
|
else
|
74
74
|
content = render_action_link(link, record, options)
|
@@ -86,7 +86,7 @@ module ActiveScaffold
|
|
86
86
|
end
|
87
87
|
if link.action.nil? || (link.type == :member && options.key?(:authorized) && !options[:authorized])
|
88
88
|
html_class = "disabled #{link.action}#{" #{link.html_options[:class]}" if link.html_options[:class].present?}"
|
89
|
-
html_options = {:link => action_link_text(link, options), :class => html_class, :title => options[:not_authorized_reason]}
|
89
|
+
html_options = {:link => action_link_text(link, record, options), :class => html_class, :title => options[:not_authorized_reason]}
|
90
90
|
action_link_html(link, nil, html_options, record)
|
91
91
|
else
|
92
92
|
url = action_link_url(link, record)
|
@@ -298,8 +298,8 @@ module ActiveScaffold
|
|
298
298
|
url_options
|
299
299
|
end
|
300
300
|
|
301
|
-
def action_link_text(link, options)
|
302
|
-
text = image_tag(link.image[:name], :size => link.image[:size], :alt => options[:link] || link.label, :title => options[:link] || link.label) if link.image
|
301
|
+
def action_link_text(link, record, options)
|
302
|
+
text = image_tag(link.image[:name], :size => link.image[:size], :alt => options[:link] || link.label(record), :title => options[:link] || link.label(record)) if link.image
|
303
303
|
text || options[:link]
|
304
304
|
end
|
305
305
|
|
@@ -329,7 +329,7 @@ module ActiveScaffold
|
|
329
329
|
def action_link_html_options(link, record, options)
|
330
330
|
link_id = get_action_link_id(link, record)
|
331
331
|
html_options = link.html_options.merge(:class => [link.html_options[:class], link.action.to_s].compact.join(' '))
|
332
|
-
html_options[:link] = action_link_text(link, options)
|
332
|
+
html_options[:link] = action_link_text(link, record, options)
|
333
333
|
|
334
334
|
# Needs to be in html_options to as the adding _method to the url is no longer supported by Rails
|
335
335
|
html_options[:method] = link.method if link.method != :get
|
@@ -388,7 +388,7 @@ module ActiveScaffold
|
|
388
388
|
|
389
389
|
def action_link_html(link, url, html_options, record)
|
390
390
|
label = html_options.delete(:link)
|
391
|
-
label ||= link.label
|
391
|
+
label ||= link.label(record)
|
392
392
|
if url.nil?
|
393
393
|
content_tag(:a, label, html_options)
|
394
394
|
else
|
@@ -6,7 +6,7 @@ module ActiveScaffold
|
|
6
6
|
def cache_association_options(association, conditions, klass, cache = true)
|
7
7
|
if active_scaffold_config.cache_association_options && cache
|
8
8
|
@_associations_cache ||= Hash.new { |h, k| h[k] = {} }
|
9
|
-
key = [association.name, association.inverse_klass.name, klass.name].join('/')
|
9
|
+
key = [association.name, association.inverse_klass.name, klass.respond_to?(:cache_key) ? klass.cache_key : klass.name].join('/')
|
10
10
|
@_associations_cache[key][conditions] ||= yield
|
11
11
|
else
|
12
12
|
yield
|
@@ -31,8 +31,8 @@ module ActiveScaffold
|
|
31
31
|
end
|
32
32
|
|
33
33
|
conditions ||= send(association_helper_method(association, :options_for_association_conditions), association, record)
|
34
|
+
klass = send(association_helper_method(association, :association_klass_scoped), association, klass, record)
|
34
35
|
cache_association_options(association, conditions, klass, cache) do
|
35
|
-
klass = send(association_helper_method(association, :association_klass_scoped), association, klass, record)
|
36
36
|
relation = klass.where(conditions)
|
37
37
|
column = column_for_association(association, record)
|
38
38
|
if column&.includes
|
@@ -181,6 +181,7 @@ module ActiveScaffold
|
|
181
181
|
parent_record.send("build_#{association.name}")
|
182
182
|
else
|
183
183
|
association.klass.new.tap do |record|
|
184
|
+
assign_default_attributes record
|
184
185
|
save_record_to_association(record, association.reverse_association, parent_record) # set inverse
|
185
186
|
end
|
186
187
|
end
|
@@ -226,7 +226,10 @@ module ActiveScaffold
|
|
226
226
|
I18n.t(options[:group_format] || search_group_function, scope: 'date.formats', num: value)
|
227
227
|
when 'month'
|
228
228
|
I18n.l(Date.new(Time.zone.today.year, value, 1), format: options[:group_format] || search_group_function.to_sym)
|
229
|
-
|
229
|
+
when 'year'
|
230
|
+
value.to_i
|
231
|
+
else
|
232
|
+
value
|
230
233
|
end
|
231
234
|
end
|
232
235
|
|
@@ -263,7 +266,7 @@ module ActiveScaffold
|
|
263
266
|
end
|
264
267
|
|
265
268
|
def format_association_value(value, column, size)
|
266
|
-
method = column.options[:label_method] || :to_label
|
269
|
+
method = (column.list_ui_options || column.options)[:label_method] || :to_label
|
267
270
|
value =
|
268
271
|
if column.association.collection?
|
269
272
|
format_collection_association_value(value, column, method, size)
|
@@ -157,7 +157,7 @@ module ActiveScaffold
|
|
157
157
|
cache_keys ||= [method, model.name]
|
158
158
|
ActiveScaffold::Registry.cache(*cache_keys) do
|
159
159
|
model_names = [model.name]
|
160
|
-
model_names << model.base_class.name if model.base_class != model
|
160
|
+
model_names << model.base_class.name if model.respond_to?(:base_class) && model.base_class != model
|
161
161
|
method_with_class = model_names.find do |model_name|
|
162
162
|
method_with_class = "#{clean_class_name(model_name)}_#{method}"
|
163
163
|
break method_with_class if respond_to?(method_with_class)
|
@@ -85,9 +85,9 @@ module ActiveScaffold
|
|
85
85
|
|
86
86
|
def default_value(klass, column_name)
|
87
87
|
if ActiveScaffold::OrmChecks.mongoid? klass
|
88
|
-
columns_hash(klass)[column_name]&.default_val
|
88
|
+
columns_hash(klass)[column_name.to_s]&.default_val
|
89
89
|
elsif ActiveScaffold::OrmChecks.active_record? klass
|
90
|
-
klass._default_attributes[column_name]&.value
|
90
|
+
klass._default_attributes[column_name.to_s]&.value
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
data/test/misc/finder_test.rb
CHANGED
@@ -75,13 +75,13 @@ class FinderTest < Minitest::Test
|
|
75
75
|
|
76
76
|
def test_condition_for_column
|
77
77
|
column = ActiveScaffold::DataStructures::Column.new('adult', Person)
|
78
|
-
assert_equal ['"people"."adult" = ?', false], ClassWithFinder.condition_for_column(column, '0')
|
78
|
+
assert_equal ['"people"."adult" = ?', false], ClassWithFinder.condition_for_column(column, '0', :full, {})
|
79
79
|
end
|
80
80
|
|
81
81
|
def test_condition_for_polymorphic_column
|
82
82
|
column = ActiveScaffold::DataStructures::Column.new('addressable', Address)
|
83
83
|
column.search_sql = [{subquery: [Building, 'name']}]
|
84
|
-
condition = ClassWithFinder.condition_for_column(column, 'test search')
|
84
|
+
condition = ClassWithFinder.condition_for_column(column, 'test search', :full, {})
|
85
85
|
assert_equal Building.where(['name LIKE ?', '%test search%']).select(:id).to_sql, condition[1].to_sql
|
86
86
|
assert_equal '"addresses"."addressable_id" IN (?) AND "addresses"."addressable_type" = ?', condition[0]
|
87
87
|
assert_equal ['Building'], condition[2..-1]
|
@@ -90,7 +90,7 @@ class FinderTest < Minitest::Test
|
|
90
90
|
def test_condition_for_polymorphic_column_with_relation
|
91
91
|
column = ActiveScaffold::DataStructures::Column.new('contactable', Contact)
|
92
92
|
column.search_sql = [{subquery: [Person.joins(:buildings), 'first_name', 'last_name']}]
|
93
|
-
condition = ClassWithFinder.condition_for_column(column, 'test search')
|
93
|
+
condition = ClassWithFinder.condition_for_column(column, 'test search', :full, {})
|
94
94
|
assert_equal Person.joins(:buildings).where(['first_name LIKE ? OR last_name LIKE ?', '%test search%', '%test search%']).select(:id).to_sql, condition[1].to_sql
|
95
95
|
assert_equal '"contacts"."contactable_id" IN (?) AND "contacts"."contactable_type" = ?', condition[0]
|
96
96
|
assert_equal ['Person'], condition[2..-1]
|
@@ -100,7 +100,7 @@ class FinderTest < Minitest::Test
|
|
100
100
|
column = ActiveScaffold::DataStructures::Column.new('owner', Building)
|
101
101
|
column.search_sql = [{subquery: [Person, 'first_name', 'last_name'], conditions: ['floor_count > 0']}]
|
102
102
|
column.search_ui = :text
|
103
|
-
condition = ClassWithFinder.condition_for_column(column, 'test search')
|
103
|
+
condition = ClassWithFinder.condition_for_column(column, 'test search', :full, {})
|
104
104
|
assert_equal Person.where(['first_name LIKE ? OR last_name LIKE ?', '%test search%', '%test search%']).select(:id).to_sql, condition[1].to_sql
|
105
105
|
assert_equal '"buildings"."owner_id" IN (?) AND floor_count > 0', condition[0]
|
106
106
|
assert_equal [], condition[2..-1]
|
@@ -110,7 +110,7 @@ class FinderTest < Minitest::Test
|
|
110
110
|
column = ActiveScaffold::DataStructures::Column.new('owner', Building)
|
111
111
|
column.search_sql = [{subquery: [Person, 'first_name', 'last_name'], conditions: ['floor_count > 0 AND name != ?', '']}]
|
112
112
|
column.search_ui = :text
|
113
|
-
condition = ClassWithFinder.condition_for_column(column, 'test search')
|
113
|
+
condition = ClassWithFinder.condition_for_column(column, 'test search', :full, {})
|
114
114
|
assert_equal Person.where(['first_name LIKE ? OR last_name LIKE ?', '%test search%', '%test search%']).select(:id).to_sql, condition[1].to_sql
|
115
115
|
assert_equal '"buildings"."owner_id" IN (?) AND floor_count > 0 AND name != ?', condition[0]
|
116
116
|
assert_equal [''], condition[2..-1]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_scaffold
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.7.
|
4
|
+
version: 3.7.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Many, see README
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|