From 449745851ac74d900fba08c6deb2a9f4ddaa30d3 Mon Sep 17 00:00:00 2001 From: Sergio Cambra Date: Mon, 4 Nov 2024 20:01:58 +0100 Subject: [PATCH 1/5] Improve styles on search_ui :select_multiple with operator select. --- CHANGELOG.rdoc | 1 + app/assets/stylesheets/active_scaffold_layout.css | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index e04167062..5f29e0e85 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -2,6 +2,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. +- Improve styles on search_ui :multi_select with operator select. = 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. diff --git a/app/assets/stylesheets/active_scaffold_layout.css b/app/assets/stylesheets/active_scaffold_layout.css index 0156ba83b..8cf31bc1d 100644 --- a/app/assets/stylesheets/active_scaffold_layout.css +++ b/app/assets/stylesheets/active_scaffold_layout.css @@ -974,6 +974,11 @@ font-size: 100%; float:left; } +.active-scaffold .search .search_range .as_search_range_option { + vertical-align: top; + margin-right: 5px; +} + .as_touch a.inline-adapter-close { width: 25px; height: 27px; From c6df022954af0ec180d29e7d8edff0de562ce7a6 Mon Sep 17 00:00:00 2001 From: Sergio Cambra Date: Mon, 4 Nov 2024 20:46:40 +0100 Subject: [PATCH 2/5] fix search for :select_multiple with operators --- CHANGELOG.rdoc | 2 +- lib/active_scaffold/finder.rb | 35 ++++++++++++++++++++--------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 5f29e0e85..4c4926a32 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -2,7 +2,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. -- Improve styles on search_ui :multi_select with operator select. +- 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. diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index a99d6dc8e..0970e195b 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -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 @@ -176,12 +180,7 @@ def condition_for_search_ui(column, value, like_pattern, search_ui) ['%s in (?)', values] if values.present? end else - if column.text? - value = column.active_record? ? column.active_record_class.sanitize_sql_like(value) : value - ["%s #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)] - else - ['%s = ?', ActiveScaffold::Core.column_type_cast(value, column.column)] - end + condition_for_single_value(column, value, like_pattern) end end @@ -199,16 +198,22 @@ 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 + ["%s #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)] + else + ['%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 - ["%s #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)] - else - ['%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?) + return unless from.present? + ["%s in (?)", from] elsif value[:from].blank? nil elsif ActiveScaffold::Finder::STRING_COMPARATORS.values.include?(value[:opt]) From ebf74652fceef4a37f89e75dec8e15e1cd58ab78 Mon Sep 17 00:00:00 2001 From: Sergio Cambra Date: Mon, 4 Nov 2024 20:46:57 +0100 Subject: [PATCH 3/5] fix human condition for select_multiple --- lib/active_scaffold/helpers/human_condition_helpers.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/human_condition_helpers.rb b/lib/active_scaffold/helpers/human_condition_helpers.rb index 14f46c2da..5253cacd9 100644 --- a/lib/active_scaffold/helpers/human_condition_helpers.rb +++ b/lib/active_scaffold/helpers/human_condition_helpers.rb @@ -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) @@ -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 From a2f4c15380f8b40239414ada4d7549ebdf48100a Mon Sep 17 00:00:00 2001 From: Sergio Cambra Date: Mon, 4 Nov 2024 20:52:57 +0100 Subject: [PATCH 4/5] fix disabling null comparators in :select and :select_multiple with search_ui_options --- lib/active_scaffold/helpers/search_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index a24a220b7..f903cebe8 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -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) From 6241142f7233064d6eb8a65c78732f2077955b47 Mon Sep 17 00:00:00 2001 From: Sergio Cambra Date: Mon, 4 Nov 2024 20:57:31 +0100 Subject: [PATCH 5/5] fix rubocop offenses --- lib/active_scaffold/finder.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 0970e195b..827ead37a 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -212,8 +212,7 @@ def condition_for_range(column, value, like_pattern = nil) 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?) - return unless from.present? - ["%s in (?)", from] + ['%s in (?)', from] if from.present? elsif value[:from].blank? nil elsif ActiveScaffold::Finder::STRING_COMPARATORS.values.include?(value[:opt])