Skip to content

Commit

Permalink
merge 3-7-stable
Browse files Browse the repository at this point in the history
  • Loading branch information
scambra committed Nov 4, 2024
2 parents 8e897dc + 6241142 commit bce7d9b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Add buttons to check all and uncheck all on :select form ui for collection associations, and draggable lists (active_scaffold_checkbox_list).
- Add hidden field with locking column in base_form partial for persisted records automatically, if model uses optimistic locking.
- Add on_stale_object_error when StaleObjectError is rescued, to allow customization.
- Fix search_ui :select_multiple, which was broken when operator select was added.

= 3.7.8
- 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.
Expand Down
6 changes: 5 additions & 1 deletion app/assets/stylesheets/active_scaffold_layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,11 @@ font-size: 100%;
float:left;
}

.active-scaffold .search .search_range .as_search_range_option {
vertical-align: top;
margin-right: 5px;
}

.active-scaffold .tabbed .nav-tabs {
border-bottom: 1px solid #ddd;
padding-left: 0;
Expand Down Expand Up @@ -1027,7 +1032,6 @@ font-size: 100%;
display: block;
}


.as_touch a.inline-adapter-close {
width: 25px;
height: 27px;
Expand Down
34 changes: 19 additions & 15 deletions lib/active_scaffold/finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ def condition_for_search_ui(column, value, like_pattern, search_ui)
when :integer, :decimal, :float
condition_for_numeric(column, value)
when :string, :range
condition_for_range(column, value, like_pattern)
if value.is_a?(Hash)
condition_for_range(column, value, like_pattern)
else
condition_for_single_value(column, value, like_pattern)
end
when :date, :time, :datetime, :timestamp
condition_for_datetime(column, value)
when :select, :select_multiple, :draggable, :multi_select, :country, :usa_state, :chosen, :multi_chosen
Expand All @@ -176,12 +180,7 @@ def condition_for_search_ui(column, value, like_pattern, search_ui)
['%<search_sql>s in (?)', values] if values.present?
end
else
if column.text?
value = column.active_record? ? column.active_record_class.sanitize_sql_like(value) : value
["%<search_sql>s #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)]
else
['%<search_sql>s = ?', ActiveScaffold::Core.column_type_cast(value, column.column)]
end
condition_for_single_value(column, value, like_pattern)
end
end

Expand All @@ -199,16 +198,21 @@ def condition_for_numeric(column, value)
end
end

def condition_for_single_value(column, value, like_pattern = nil)
if column.text?
value = column.active_record? ? column.active_record_class.sanitize_sql_like(value) : value
["%<search_sql>s #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)]
else
['%<search_sql>s = ?', ActiveScaffold::Core.column_type_cast(value, column.column)]
end
end

def condition_for_range(column, value, like_pattern = nil)
if !value.is_a?(Hash)
if column.text?
value = column.active_record? ? column.active_record_class.sanitize_sql_like(value) : value
["%<search_sql>s #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)]
else
['%<search_sql>s = ?', ActiveScaffold::Core.column_type_cast(value, column.column)]
end
elsif ActiveScaffold::Finder::NULL_COMPARATORS.include?(value[:opt])
if ActiveScaffold::Finder::NULL_COMPARATORS.include?(value[:opt])
condition_for_null_type(column, value[:opt], like_pattern)
elsif value[:from].is_a?(Array) # opt can be only =
from = Array(value[:from]).select(&:present?)
['%<search_sql>s in (?)', from] if from.present?
elsif value[:from].blank?
nil
elsif ActiveScaffold::Finder::STRING_COMPARATORS.values.include?(value[:opt])
Expand Down
4 changes: 3 additions & 1 deletion lib/active_scaffold/helpers/human_condition_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ def active_scaffold_human_condition_select(column, associated)
return active_scaffold_human_condition_range(column, associated) unless associated['opt'] == '='
associated = associated['from']
end
associated = [associated].compact unless associated.is_a? Array
associated = [associated] unless associated.is_a? Array
associated = associated.select(&:present?)
if column.association
method = column.options[:label_method] || :to_label
associated = column.association.klass.where(:id => associated.map(&:to_i)).map(&method)
Expand All @@ -122,6 +123,7 @@ def active_scaffold_human_condition_select(column, associated)
as_(:association, :scope => :human_conditions, :column => attribute, :value => associated.join(', '))
end
alias active_scaffold_human_condition_multi_select active_scaffold_human_condition_select
alias active_scaffold_human_condition_select_multiple active_scaffold_human_condition_select
alias active_scaffold_human_condition_record_select active_scaffold_human_condition_select
alias active_scaffold_human_condition_chosen active_scaffold_human_condition_select
alias active_scaffold_human_condition_multi_chosen active_scaffold_human_condition_select
Expand Down
2 changes: 1 addition & 1 deletion lib/active_scaffold/helpers/search_column_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def active_scaffold_search_multi_select(column, options, ui_options: column.opti
def active_scaffold_search_select(column, html_options, options = {}, ui_options: column.options)
record = html_options.delete(:object)
associated = html_options.delete :value
if include_null_comparators?(column)
if include_null_comparators?(column, ui_options: ui_options)
range_opts = html_options.slice(:name, :id)
range_opts[:opt_value], associated, = field_search_params_range_values(column)
operators = active_scaffold_search_select_comparator_options(column, ui_options: ui_options)
Expand Down

0 comments on commit bce7d9b

Please sign in to comment.