active_scaffold 3.7.5 → 3.7.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.rdoc +5 -0
- data/lib/active_scaffold/actions/common_search.rb +3 -3
- data/lib/active_scaffold/actions/field_search.rb +28 -17
- data/lib/active_scaffold/data_structures/sorting.rb +3 -3
- data/lib/active_scaffold/finder.rb +1 -1
- data/lib/active_scaffold/helpers/list_column_helpers.rb +5 -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: cfe45d0a0b28f5cb324e7104add97e7a105de6986accf8d64db02cf5f65f19ea
|
4
|
+
data.tar.gz: f8461b6a58ce6b1c93df2eaf95540a759fdcd73d21f256ee1a38ea4436b73987
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a65de91f886605e57d0f183295d9d1f8ea358b4657826143265f8359f4d41761b6325644fcb6d5dc1d5e5d4b87bbc966bf8cd9d4ee66db0ae4048455eb0c6b62
|
7
|
+
data.tar.gz: 9fb4e3b6a38c5f340cdf430146ae9616a5e9a93e66c11e32dece9cb5704229499610da861916371e3bafb973d43705c9716228b5d04c50f896d5538320e0125c
|
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
= 3.7.6
|
2
|
+
- Respect :label_method set in form_ui_options on list.
|
3
|
+
- Fix grouped search for PostgreSQL
|
4
|
+
- Fix loading current search params when search form is open and store_user_settings is disabled
|
5
|
+
|
1
6
|
= 3.7.5
|
2
7
|
- Fix always show search for nested list on multi-level through associations
|
3
8
|
- Support changing step, min and max options with column options or search_ui options for decimal and integer search_ui
|
@@ -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
|
|
@@ -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)
|
@@ -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 = {
|
@@ -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)
|
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.6
|
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-06-
|
11
|
+
date: 2024-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|