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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5777dd56be3d144f2c62d8b2fa3cf8a0e765155d3afd445b5d150ce25c203155
4
- data.tar.gz: 2c2ef1fbe12d539b84d81d48d1a2d373f3634a864664d61ab27099c783f404c4
3
+ metadata.gz: 91fd5ea7093e75c0b38bab3de974135ab0502fedb6627341403ff6ea0800eca4
4
+ data.tar.gz: 4949444e01d9e06d8e277e15698a97593868bcd3a297378d2cf421ece2e00ad2
5
5
  SHA512:
6
- metadata.gz: e13283f6ae89cf8618e070ee0e6afa87a47389eaee7043a669ab771f82c6aec2dbbdf2317c57ca6872785622e601d0d1278140e53cf24ca5245a88f9353dfe97
7
- data.tar.gz: ea569709001c16bae097715c62fe9a9717597c288b2504d2c930e55aa01b28e77b53c29583d3e0462c86f329aebae8c8a82d73c832b14332a8999ee777d42e3c
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://api.travis-ci.com/activescaffold/active_scaffold.svg?branch=master)](https://app.travis-ci.com/activescaffold/active_scaffold)
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)
@@ -469,8 +469,10 @@ module ActiveScaffold::DataStructures
469
469
  return nil unless column
470
470
  if column.is_a?(ActiveModel::Attribute)
471
471
  column.value
472
+ elsif active_record? && null?
473
+ nil
472
474
  else
473
- default_value
475
+ @db_default_value
474
476
  end
475
477
  end
476
478
 
@@ -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
- values = Array(value).select(&:present?)
173
- ['%<search_sql>s in (?)', values] if values.present?
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
- {:name => "search[#{column.name}]", :class => "#{column.name}-input", :id => "search_#{column.name}", :value => field_search_params[column.name.to_s]}
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
- if (optgroup = options.delete(:optgroup))
123
- select(:record, method, active_scaffold_grouped_options(column, select_options, optgroup), options, html_options)
124
- elsif column.association
125
- collection_select(:record, method, select_options, :id, ui_options[:label_method] || :to_label, options, html_options)
126
- else
127
- select(:record, method, select_options, options, html_options)
128
- end
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
- select_options = active_scaffold_search_range_comparator_options(column, ui_options: ui_options)
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
- html << content_tag('span', :id => "#{options[:id]}_numeric", :style => ActiveScaffold::Finder::NULL_COMPARATORS.include?(opt_value) ? 'display: none' : nil) do
235
- send(input_method, "#{options[:name]}[from]", from_value, input_options) <<
236
- content_tag(
237
- :span,
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)
@@ -2,7 +2,7 @@ module ActiveScaffold
2
2
  module Version
3
3
  MAJOR = 3
4
4
  MINOR = 7
5
- PATCH = 7
5
+ PATCH = 8
6
6
  FIX = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, FIX].compact.join('.')
data/test/test_helper.rb CHANGED
@@ -1,4 +1,11 @@
1
- require 'simplecov' if ENV['COVERAGE']
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.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-09-18 00:00:00.000000000 Z
11
+ date: 2024-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails