active_scaffold 3.7.7 → 3.7.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.rdoc +4 -0
- data/README.md +1 -2
- data/lib/active_scaffold/data_structures/column.rb +3 -1
- data/lib/active_scaffold/finder.rb +6 -2
- data/lib/active_scaffold/helpers/human_condition_helpers.rb +4 -0
- data/lib/active_scaffold/helpers/search_column_helpers.rb +44 -21
- data/lib/active_scaffold/version.rb +1 -1
- data/test/test_helper.rb +8 -1
- 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: 91fd5ea7093e75c0b38bab3de974135ab0502fedb6627341403ff6ea0800eca4
|
4
|
+
data.tar.gz: 4949444e01d9e06d8e277e15698a97593868bcd3a297378d2cf421ece2e00ad2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbafb7483143581f8430dcf3cbce154f160022e05c2e0760627d7e571fdff1718d68a883e6fc152fb943f1d480e259d2001ae0579fc5788df0cca7469cef77f9
|
7
|
+
data.tar.gz: b64826066e5e12fa27636680ea15647ab8072323c078a032398fe49f187693f9ada4555004fcda0244b9493de544c57cfac08f0d80c4eadf98fab5880170bb0e
|
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
= 3.7.8
|
2
|
+
- Rollback previous behaviour when submitting empty values, broken when default_value was added. Default value set in column is not used when trying to save empty value, DB default is used in that case, and save NULL when string is empty, as before.
|
3
|
+
- Support operators =, null and not null for :select search_ui, so it's possible to search for NULL with :select search UI.
|
4
|
+
|
1
5
|
= 3.7.7
|
2
6
|
- Fix usage with mongoid, broken on 3.7.5
|
3
7
|
- Support proc or lambda in label of action links
|
data/README.md
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
|
2
2
|
Overview
|
3
3
|
========
|
4
|
-
[![Build status](https://
|
4
|
+
[![Build status](https://github.com/activescaffold/active_scaffold/actions/workflows/ci.yml/badge.svg)](https://github.com/activescaffold/active_scaffold/actions/workflows/ci.yml)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/activescaffold/active_scaffold/badges/gpa.svg)](https://codeclimate.com/github/activescaffold/active_scaffold)
|
6
6
|
[![Test Coverage](https://codeclimate.com/github/activescaffold/active_scaffold/badges/coverage.svg)](https://codeclimate.com/github/activescaffold/active_scaffold)
|
7
|
-
[![Dependency Status](https://gemnasium.com/activescaffold/active_scaffold.svg)](https://gemnasium.com/activescaffold/active_scaffold)
|
8
7
|
[![Gem Version](https://badge.fury.io/rb/active_scaffold.svg)](https://badge.fury.io/rb/active_scaffold)
|
9
8
|
[![Inline docs](https://inch-ci.org/github/activescaffold/active_scaffold.svg?branch=master)](https://inch-ci.org/github/activescaffold/active_scaffold)
|
10
9
|
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
|
@@ -169,8 +169,12 @@ module ActiveScaffold
|
|
169
169
|
when :date, :time, :datetime, :timestamp
|
170
170
|
condition_for_datetime(column, value)
|
171
171
|
when :select, :select_multiple, :draggable, :multi_select, :country, :usa_state, :chosen, :multi_chosen
|
172
|
-
|
173
|
-
|
172
|
+
if value.is_a?(Hash)
|
173
|
+
condition_for_range(column, value, like_pattern)
|
174
|
+
else
|
175
|
+
values = Array(value).select(&:present?)
|
176
|
+
['%<search_sql>s in (?)', values] if values.present?
|
177
|
+
end
|
174
178
|
else
|
175
179
|
if column.text?
|
176
180
|
value = column.active_record? ? column.active_record_class.sanitize_sql_like(value) : value
|
@@ -104,6 +104,10 @@ module ActiveScaffold
|
|
104
104
|
|
105
105
|
def active_scaffold_human_condition_select(column, associated)
|
106
106
|
attribute = column.active_record_class.human_attribute_name(column.name)
|
107
|
+
if associated.is_a?(Hash)
|
108
|
+
return active_scaffold_human_condition_range(column, associated) unless associated['opt'] == '='
|
109
|
+
associated = associated['from']
|
110
|
+
end
|
107
111
|
associated = [associated].compact unless associated.is_a? Array
|
108
112
|
if column.association
|
109
113
|
method = column.options[:label_method] || :to_label
|
@@ -54,7 +54,7 @@ module ActiveScaffold
|
|
54
54
|
|
55
55
|
# the standard active scaffold options used for class, name and scope
|
56
56
|
def active_scaffold_search_options(column)
|
57
|
-
{:
|
57
|
+
{name: "search[#{column.name}]", class: "#{column.name}-input", id: "search_#{column.name}", value: field_search_params[column.name.to_s]}
|
58
58
|
end
|
59
59
|
|
60
60
|
def search_attribute(column, record)
|
@@ -98,6 +98,13 @@ module ActiveScaffold
|
|
98
98
|
def active_scaffold_search_select(column, html_options, options = {}, ui_options: column.options)
|
99
99
|
record = html_options.delete(:object)
|
100
100
|
associated = html_options.delete :value
|
101
|
+
if include_null_comparators?(column)
|
102
|
+
range_opts = html_options.slice(:name, :id)
|
103
|
+
range_opts[:opt_value], associated, = field_search_params_range_values(column)
|
104
|
+
operators = active_scaffold_search_select_comparator_options(column, ui_options: ui_options)
|
105
|
+
html_options[:name] += '[from]'
|
106
|
+
end
|
107
|
+
|
101
108
|
if column.association
|
102
109
|
associated = associated.is_a?(Array) ? associated.map(&:to_i) : associated.to_i unless associated.nil?
|
103
110
|
method = column.association.belongs_to? ? column.association.foreign_key : column.name
|
@@ -119,13 +126,16 @@ module ActiveScaffold
|
|
119
126
|
active_scaffold_translate_select_options(options)
|
120
127
|
end
|
121
128
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
+
select =
|
130
|
+
if (optgroup = options.delete(:optgroup))
|
131
|
+
select(:record, method, active_scaffold_grouped_options(column, select_options, optgroup), options, html_options)
|
132
|
+
elsif column.association
|
133
|
+
collection_select(:record, method, select_options, :id, ui_options[:label_method] || :to_label, options, html_options)
|
134
|
+
else
|
135
|
+
select(:record, method, select_options, options, html_options)
|
136
|
+
end
|
137
|
+
|
138
|
+
operators ? build_active_scaffold_search_range_ui(operators, select, **range_opts) : select
|
129
139
|
end
|
130
140
|
|
131
141
|
def active_scaffold_search_select_multiple(column, options, ui_options: column.options)
|
@@ -207,6 +217,12 @@ module ActiveScaffold
|
|
207
217
|
select_options
|
208
218
|
end
|
209
219
|
|
220
|
+
def active_scaffold_search_select_comparator_options(column, ui_options: column.options)
|
221
|
+
select_options = [[as_('='.to_sym), '=']]
|
222
|
+
select_options.concat(ActiveScaffold::Finder::NULL_COMPARATORS.collect { |comp| [as_(comp), comp] })
|
223
|
+
select_options
|
224
|
+
end
|
225
|
+
|
210
226
|
def include_null_comparators?(column, ui_options: column.options)
|
211
227
|
return ui_options[:null_comparators] if ui_options.key? :null_comparators
|
212
228
|
if column.association
|
@@ -219,30 +235,37 @@ module ActiveScaffold
|
|
219
235
|
def active_scaffold_search_range(column, options, input_method = :text_field_tag, input_options = {}, ui_options: column.options)
|
220
236
|
opt_value, from_value, to_value = field_search_params_range_values(column)
|
221
237
|
|
222
|
-
|
238
|
+
operators = active_scaffold_search_range_comparator_options(column, ui_options: ui_options)
|
223
239
|
text_field_size = active_scaffold_search_range_string?(column) ? 15 : 10
|
224
|
-
opt_value ||= select_options[0][1]
|
225
240
|
|
226
241
|
from_value = controller.class.condition_value_for_numeric(column, from_value)
|
227
242
|
to_value = controller.class.condition_value_for_numeric(column, to_value)
|
228
243
|
from_value = format_number_value(from_value, ui_options) if from_value.is_a?(Numeric)
|
229
244
|
to_value = format_number_value(to_value, ui_options) if to_value.is_a?(Numeric)
|
230
|
-
html = select_tag("#{options[:name]}[opt]", options_for_select(select_options, opt_value),
|
231
|
-
:id => "#{options[:id]}_opt", :class => 'as_search_range_option')
|
232
245
|
from_options = active_scaffold_input_text_options(input_options.merge(:id => options[:id], :size => text_field_size))
|
233
246
|
to_options = from_options.merge(:id => "#{options[:id]}_to")
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
safe_join([' - ', send(input_method, "#{options[:name]}[to]", to_value, to_options)]),
|
239
|
-
:id => "#{options[:id]}_between", :class => 'as_search_range_between', :style => ('display: none' unless opt_value == 'BETWEEN')
|
240
|
-
)
|
241
|
-
end
|
242
|
-
content_tag :span, html, :class => 'search_range'
|
247
|
+
|
248
|
+
from_field = send(input_method, "#{options[:name]}[from]", from_value, input_options)
|
249
|
+
to_field = send(input_method, "#{options[:name]}[to]", to_value, to_options)
|
250
|
+
build_active_scaffold_search_range_ui(operators, from_field, to_field, opt_value: opt_value, **options.slice(:name, :id))
|
243
251
|
end
|
244
252
|
alias active_scaffold_search_string active_scaffold_search_range
|
245
253
|
|
254
|
+
def build_active_scaffold_search_range_ui(operators, from, to = nil, name:, id:, opt_value: nil)
|
255
|
+
opt_value ||= operators[0][1]
|
256
|
+
html = select_tag("#{name}[opt]", options_for_select(operators, opt_value),
|
257
|
+
id: "#{id}_opt", class: 'as_search_range_option')
|
258
|
+
if to
|
259
|
+
from << content_tag(
|
260
|
+
:span,
|
261
|
+
safe_join([' - ', to]),
|
262
|
+
id: "#{id}_between", class: 'as_search_range_between', style: ('display: none' unless opt_value == 'BETWEEN')
|
263
|
+
)
|
264
|
+
end
|
265
|
+
html << content_tag('span', from, id: "#{id}_numeric", style: ActiveScaffold::Finder::NULL_COMPARATORS.include?(opt_value) ? 'display: none' : nil)
|
266
|
+
content_tag :span, html, class: 'search_range'
|
267
|
+
end
|
268
|
+
|
246
269
|
def active_scaffold_search_integer(column, options, ui_options: column.options)
|
247
270
|
number_opts = ui_options.slice(:step, :min, :max).reverse_merge(step: '1')
|
248
271
|
active_scaffold_search_range(column, options, :number_field_tag, number_opts, ui_options: ui_options)
|
data/test/test_helper.rb
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
-
|
1
|
+
if ENV['COVERAGE'] == 'true'
|
2
|
+
require 'simplecov'
|
3
|
+
require 'simplecov_json_formatter'
|
4
|
+
SimpleCov.formatters = [
|
5
|
+
SimpleCov::Formatter::HTMLFormatter,
|
6
|
+
SimpleCov::Formatter::JSONFormatter
|
7
|
+
]
|
8
|
+
end
|
2
9
|
|
3
10
|
ENV['RAILS_ENV'] = 'test'
|
4
11
|
require 'mock_app/config/environment'
|
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.8
|
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-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|