Module: ActiveScaffold::Helpers::SearchColumnHelpers
- Included in:
- ViewHelpers
- Defined in:
- lib/active_scaffold/helpers/search_column_helpers.rb
Overview
Helpers that assist with the rendering of a Form Column
Instance Method Summary collapse
- #active_scaffold_group_column ⇒ Object
- #active_scaffold_group_search_column(record, options) ⇒ Object
- #active_scaffold_group_search_options ⇒ Object
-
#active_scaffold_search_boolean(column, options, ui_options: column.options) ⇒ Object
(also: #active_scaffold_search_checkbox)
we can’t use active_scaffold_input_boolean because we need to have a nil value even when column can’t be null to decide whether search for this field or not.
- #active_scaffold_search_date(column, options, ui_options: column.options) ⇒ Object
- #active_scaffold_search_date_field(column, options, current_search, name, ui_options: column.options) ⇒ Object
- #active_scaffold_search_datetime(column, options, ui_options: column.options, field_ui: column.search_ui || :datetime) ⇒ Object
- #active_scaffold_search_datetime_comparator_options(column, ui_options: column.options) ⇒ Object
- #active_scaffold_search_datetime_comparator_tag(column, options, current_search, ui_options: column.options) ⇒ Object
- #active_scaffold_search_datetime_field(column, options, current_search, name, ui_options: column.options) ⇒ Object
- #active_scaffold_search_datetime_numeric_tag(column, options, current_search, ui_options: column.options, field_ui: column.search_ui) ⇒ Object
- #active_scaffold_search_datetime_range_tag(column, options, current_search) ⇒ Object
- #active_scaffold_search_datetime_trend_tag(column, options, current_search) ⇒ Object
- #active_scaffold_search_datetime_trend_units(column) ⇒ Object
- #active_scaffold_search_decimal(column, options, ui_options: column.options) ⇒ Object (also: #active_scaffold_search_float)
- #active_scaffold_search_draggable(column, options, ui_options: column.options) ⇒ Object
-
#active_scaffold_search_for(column, options = nil) ⇒ Object
This method decides which input to use for the given column.
- #active_scaffold_search_integer(column, options, ui_options: column.options) ⇒ Object
-
#active_scaffold_search_multi_select(column, options, ui_options: column.options) ⇒ Object
Search input methods.
- #active_scaffold_search_null(column, options, ui_options: column.options) ⇒ Object
-
#active_scaffold_search_options(column) ⇒ Object
the standard active scaffold options used for class, name and scope.
- #active_scaffold_search_range(column, options, input_method = :text_field_tag, input_options = {}, ui_options: column.options) ⇒ Object (also: #active_scaffold_search_string)
- #active_scaffold_search_range_comparator_options(column, ui_options: column.options) ⇒ Object
- #active_scaffold_search_range_string?(column) ⇒ Boolean
- #active_scaffold_search_select(column, html_options, options = {}, ui_options: column.options) ⇒ Object
- #active_scaffold_search_select_comparator_options(column, ui_options: column.options) ⇒ Object
- #active_scaffold_search_select_multiple(column, options, ui_options: column.options) ⇒ Object
- #active_scaffold_search_text(column, options, ui_options: column.options) ⇒ Object
- #active_scaffold_search_time(column, options, ui_options: column.options) ⇒ Object
- #active_scaffold_search_time_field(column, options, current_search, name, ui_options: column.options) ⇒ Object
- #active_scaffold_search_timestamp(column, options, ui_options: column.options) ⇒ Object
- #build_active_scaffold_search_range_ui(operators, from, to = nil, name:, id:, opt_value: nil) ⇒ Object
- #column_datetime?(column) ⇒ Boolean
- #field_search_params_range_values(column) ⇒ Object
- #include_null_comparators?(column, ui_options: column.options) ⇒ Boolean
-
#override_search(form_ui) ⇒ Object
the naming convention for overriding search input types with helpers.
- #override_search_field(column) ⇒ Object
- #search_attribute(column, record) ⇒ Object
-
#search_column_label(column, record) ⇒ Object
Search column override signatures.
- #search_label_for(column, options) ⇒ Object
- #searched_by?(column) ⇒ Boolean
- #visibles_and_hiddens(search_config, columns = search_config.columns) ⇒ Object
Instance Method Details
#active_scaffold_group_column ⇒ Object
179 180 181 182 183 184 185 186 187 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 179 def active_scaffold_group_column return if active_scaffold_config.field_search..blank? @_active_scaffold_group_column ||= begin column = ActiveScaffold::DataStructures::Column.new(:active_scaffold_group, active_scaffold_config.model) column.label = :group_by column end end |
#active_scaffold_group_search_column(record, options) ⇒ Object
168 169 170 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 168 def active_scaffold_group_search_column(record, ) select_tag 'search[active_scaffold_group]', (, selected: field_search_params['active_scaffold_group']) end |
#active_scaffold_group_search_options ⇒ Object
172 173 174 175 176 177 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 172 def = active_scaffold_config.field_search..collect do |text, value| active_scaffold_translated_option(active_scaffold_group_column, text, value) end [[as_(:no_group), '']].concat end |
#active_scaffold_search_boolean(column, options, ui_options: column.options) ⇒ Object Also known as: active_scaffold_search_checkbox
we can’t use active_scaffold_input_boolean because we need to have a nil value even when column can’t be null to decide whether search for this field or not
152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 152 def active_scaffold_search_boolean(column, , ui_options: column.) = [] << [as_(:_select_), nil] if column.null? null_label = [:include_blank] || :null null_label = as_(null_label) if null_label.is_a?(Symbol) << [null_label, 'null'] end << [as_(:true), true] # rubocop:disable Lint/BooleanSymbol << [as_(:false), false] # rubocop:disable Lint/BooleanSymbol select_tag([:name], (, ActiveScaffold::Core.column_type_cast([:value], column.column)), id: [:id]) end |
#active_scaffold_search_date(column, options, ui_options: column.options) ⇒ Object
301 302 303 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 301 def active_scaffold_search_date(column, , ui_options: column.) active_scaffold_search_datetime(column, , ui_options: , field_ui: :date) end |
#active_scaffold_search_date_field(column, options, current_search, name, ui_options: column.options) ⇒ Object
380 381 382 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 380 def active_scaffold_search_date_field(column, , current_search, name, ui_options: column.) active_scaffold_search_datetime_field(column, .merge!(discard_time: true), current_search, name, ui_options: ) end |
#active_scaffold_search_datetime(column, options, ui_options: column.options, field_ui: column.search_ui || :datetime) ⇒ Object
280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 280 def active_scaffold_search_datetime(column, , ui_options: column., field_ui: column.search_ui || :datetime) current_search = {'from' => nil, 'to' => nil, 'opt' => 'BETWEEN', 'number' => 1, 'unit' => 'DAYS', 'range' => nil} current_search.merge!([:value]) unless [:value].nil? = [ active_scaffold_search_datetime_comparator_tag(column, , current_search, ui_options: column.), active_scaffold_search_datetime_trend_tag(column, , current_search), active_scaffold_search_datetime_numeric_tag(column, , current_search, ui_options: , field_ui: field_ui), active_scaffold_search_datetime_range_tag(column, , current_search) ] safe_join , ' '.html_safe end |
#active_scaffold_search_datetime_comparator_options(column, ui_options: column.options) ⇒ Object
305 306 307 308 309 310 311 312 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 305 def (column, ui_options: column.) = ActiveScaffold::Finder::DATE_COMPARATORS.collect { |comp| [as_(comp.downcase.to_sym), comp] } .concat(ActiveScaffold::Finder::NUMERIC_COMPARATORS.collect { |comp| [as_(comp.downcase.to_sym), comp] }) if include_null_comparators? column, ui_options: .concat(ActiveScaffold::Finder::NULL_COMPARATORS.collect { |comp| [as_(comp), comp] }) end end |
#active_scaffold_search_datetime_comparator_tag(column, options, current_search, ui_options: column.options) ⇒ Object
314 315 316 317 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 314 def active_scaffold_search_datetime_comparator_tag(column, , current_search, ui_options: column.) choices = ((column, ui_options: ), current_search['opt']) select_tag("#{options[:name]}[opt]", choices, id: "#{options[:id]}_opt", class: 'as_search_range_option as_search_date_time_option') end |
#active_scaffold_search_datetime_field(column, options, current_search, name, ui_options: column.options) ⇒ Object
368 369 370 371 372 373 374 375 376 377 378 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 368 def active_scaffold_search_datetime_field(column, , current_search, name, ui_options: column.) = .merge() type = "#{'date' unless options[:discard_date]}#{'time' unless options[:discard_time]}" field_name = "#{options[:name]}[#{name}]" if [:use_select] send(:"select_#{type}", current_search[name], .reverse_merge(include_blank: true, prefix: field_name)) else helper = "#{type}#{'_local' if type == 'datetime'}_field_tag" send(helper, field_name, current_search[name], .except(:name, :object, :use_select).merge(id: "#{options[:id]}_#{name}")) end end |
#active_scaffold_search_datetime_numeric_tag(column, options, current_search, ui_options: column.options, field_ui: column.search_ui) ⇒ Object
319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 319 def active_scaffold_search_datetime_numeric_tag(column, , current_search, ui_options: column., field_ui: column.search_ui) helper = "active_scaffold_search_#{field_ui}_field" numeric_controls = [ send(helper, column, , current_search, 'from', ui_options: ), content_tag(:span, id: "#{options[:id]}_between", class: 'as_search_range_between', style: ('display: none' unless current_search['opt'] == 'BETWEEN')) do safe_join([' - ', send(helper, column, , current_search, 'to', ui_options: )]) end ] show = current_search.key?(:show) ? current_search[:show] : ActiveScaffold::Finder::NUMERIC_COMPARATORS.include?(current_search['opt']) content_tag('span', safe_join(numeric_controls), id: "#{options[:id]}_numeric", class: 'search-date-numeric', style: ('display: none' unless show)) end |
#active_scaffold_search_datetime_range_tag(column, options, current_search) ⇒ Object
353 354 355 356 357 358 359 360 361 362 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 353 def active_scaffold_search_datetime_range_tag(column, , current_search) values = ActiveScaffold::Finder::DATE_RANGES.collect { |range| [as_(range.downcase.to_sym), range] } range_controls = select_tag("#{options[:name]}[range]", (values, current_search['range']), class: 'text-input', id: nil) show = current_search.key?(:show) ? current_search[:show] : current_search['opt'] == 'RANGE' content_tag('span', range_controls, id: "#{options[:id]}_range", class: 'search-date-range', style: ('display: none' unless show)) end |
#active_scaffold_search_datetime_trend_tag(column, options, current_search) ⇒ Object
334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 334 def active_scaffold_search_datetime_trend_tag(column, , current_search) trend_controls = [ text_field_tag("#{options[:name]}[number]", current_search['number'], class: 'text-input', size: 10, autocomplete: 'off'), select_tag("#{options[:name]}[unit]", (active_scaffold_search_datetime_trend_units(column), current_search['unit']), class: 'text-input') ] show = current_search.key?(:show) ? current_search[:show] : current_search['opt'] == 'PAST' || current_search['opt'] == 'FUTURE' content_tag('span', safe_join(trend_controls, ' '), id: "#{options[:id]}_trend", class: 'search-date-trend', style: ('display: none' unless show)) end |
#active_scaffold_search_datetime_trend_units(column) ⇒ Object
347 348 349 350 351 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 347 def active_scaffold_search_datetime_trend_units(column) = ActiveScaffold::Finder::DATE_UNITS.collect { |unit| [as_(unit.downcase.to_sym), unit] } = ActiveScaffold::Finder::TIME_UNITS.collect { |unit| [as_(unit.downcase.to_sym), unit] } + if column_datetime?(column) end |
#active_scaffold_search_decimal(column, options, ui_options: column.options) ⇒ Object Also known as: active_scaffold_search_float
274 275 276 277 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 274 def active_scaffold_search_decimal(column, , ui_options: column.) number_opts = .slice(:step, :min, :max).reverse_merge(step: :any) active_scaffold_search_range(column, , :number_field_tag, number_opts, ui_options: ) end |
#active_scaffold_search_draggable(column, options, ui_options: column.options) ⇒ Object
142 143 144 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 142 def active_scaffold_search_draggable(column, , ui_options: column.) active_scaffold_search_multi_select(column, .merge(draggable_lists: true), ui_options: ) end |
#active_scaffold_search_for(column, options = nil) ⇒ Object
This method decides which input to use for the given column. It does not do any rendering. It only decides which method is responsible for rendering.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 7 def active_scaffold_search_for(column, = nil) ||= (column) if active_scaffold_config.field_search.update_columns search_columns = active_scaffold_config.field_search.columns.visible_columns_names = (column, nil, , form_columns: search_columns, url_params: {form_action: :field_search}) end record = [:object] if column.delegated_association record = record.send(column.delegated_association.name) || column.active_record_class.new [:object] = record end # first, check if the dev has created an override for this specific field for search if (method = override_search_field(column)) send(method, record, ) # second, check if the dev has specified a valid search_ui for this column, using specific ui for searches # or generic ui for forms elsif column.search_ui && (method = override_search(column.search_ui) || override_input(column.search_ui)) send(method, column, , ui_options: column. || column.) # third, check if the dev has created an override for this specific field elsif (method = override_form_field(column)) # rubocop:disable Lint/DuplicateBranch send(method, record, ) # fallback: we get to make the decision elsif column.association || column.virtual? active_scaffold_search_text(column, ) elsif (method = override_search(column.column_type) || override_input(column.column_type)) # if we (or someone else) have created a custom render option for the column type, use that send(method, column, ) else # final ultimate fallback: use rails' generic input method # for textual fields we pass different options = () if column.text? || column.number? text_field(:record, column.name, .merge(column.)) end rescue StandardError => e Rails.logger.error "#{e.class.name}: #{e.message} -- on the ActiveScaffold column = :#{column.name} in #{controller.class}" raise e end |
#active_scaffold_search_integer(column, options, ui_options: column.options) ⇒ Object
269 270 271 272 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 269 def active_scaffold_search_integer(column, , ui_options: column.) number_opts = .slice(:step, :min, :max).reverse_merge(step: '1') active_scaffold_search_range(column, , :number_field_tag, number_opts, ui_options: ) end |
#active_scaffold_search_multi_select(column, options, ui_options: column.options) ⇒ Object
Search input methods
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 71 def active_scaffold_search_multi_select(column, , ui_options: column.) record = .delete(:object) associated = .delete :value associated = [associated].compact unless associated.is_a? Array if column.association associated.collect!(&:to_i) method = [:label_method] || :to_label helper_method = association_helper_method(column.association, :sorted_association_options_find) = send(helper_method, column.association, nil, record).collect do |r| [r.send(method), r.id] end else = override_helper_per_model(:active_scaffold_enum_options, record.class) = send(, column, record, ui_options: ).collect do |text, value| active_scaffold_translated_option(column, text, value) end end return as_(:no_options) if .empty? active_scaffold_checkbox_list(column, , associated, , ui_options: ) end |
#active_scaffold_search_null(column, options, ui_options: column.options) ⇒ Object
189 190 191 192 193 194 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 189 def active_scaffold_search_null(column, , ui_options: column.) = [] << [as_(:_select_), nil] .concat(ActiveScaffold::Finder::NULL_COMPARATORS.collect { |comp| [as_(comp), comp] }) select_tag([:name], (, [:value]), id: [:id]) end |
#active_scaffold_search_options(column) ⇒ Object
the standard active scaffold options used for class, name and scope
51 52 53 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 51 def (column) {name: "search[#{column.name}]", class: "#{column.name}-input", id: "search_#{column.name}", value: field_search_params[column.name.to_s]} end |
#active_scaffold_search_range(column, options, input_method = :text_field_tag, input_options = {}, ui_options: column.options) ⇒ Object Also known as: active_scaffold_search_string
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 235 def active_scaffold_search_range(column, , input_method = :text_field_tag, = {}, ui_options: column.) opt_value, from_value, to_value = field_search_params_range_values(column) operators = (column, ui_options: ) text_field_size = active_scaffold_search_range_string?(column) ? 15 : 10 from_value = controller.class.condition_value_for_numeric(column, from_value) to_value = controller.class.condition_value_for_numeric(column, to_value) from_value = format_number_value(from_value, ) if from_value.is_a?(Numeric) to_value = format_number_value(to_value, ) if to_value.is_a?(Numeric) = (.merge(id: [:id], size: text_field_size)) = .merge(id: "#{options[:id]}_to") from_field = send(input_method, "#{options[:name]}[from]", from_value, ) to_field = send(input_method, "#{options[:name]}[to]", to_value, ) build_active_scaffold_search_range_ui(operators, from_field, to_field, opt_value: opt_value, **.slice(:name, :id)) end |
#active_scaffold_search_range_comparator_options(column, ui_options: column.options) ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 207 def (column, ui_options: column.) = ActiveScaffold::Finder::NUMERIC_COMPARATORS.collect { |comp| [as_(comp.downcase.to_sym), comp] } if active_scaffold_search_range_string?(column) comparators = ActiveScaffold::Finder::STRING_COMPARATORS.collect { |title, comp| [as_(title), comp] } .unshift(*comparators) end if include_null_comparators? column, ui_options: .concat(ActiveScaffold::Finder::NULL_COMPARATORS.collect { |comp| [as_(comp), comp] }) end end |
#active_scaffold_search_range_string?(column) ⇒ Boolean
203 204 205 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 203 def active_scaffold_search_range_string?(column) column.text? || column.search_ui == :string end |
#active_scaffold_search_select(column, html_options, options = {}, ui_options: column.options) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 94 def active_scaffold_search_select(column, , = {}, ui_options: column.) record = .delete(:object) associated = .delete :value if include_null_comparators?(column, ui_options: ) range_opts = .slice(:name, :id) range_opts[:opt_value], associated, = field_search_params_range_values(column) operators = (column, ui_options: ) [:name] += '[from]' end if column.association associated = associated.is_a?(Array) ? associated.map(&:to_i) : associated.to_i unless associated.nil? method = column.association.belongs_to? ? column.association.foreign_key : column.name helper_method = association_helper_method(column.association, :sorted_association_options_find) = send(helper_method, column.association, false, record) else method = column.name = override_helper_per_model(:active_scaffold_enum_options, record.class) = send(, column, record, ui_options: ).collect do |text, value| active_scaffold_translated_option(column, text, value) end end = .merge(selected: associated).merge .merge! [:html_options] || {} if [:multiple] active_scaffold_select_name_with_multiple else [:include_blank] ||= as_(:_select_) () end select = if (optgroup = .delete(:optgroup)) select(:record, method, (column, , optgroup), , ) elsif column.association collection_select(:record, method, , :id, [:label_method] || :to_label, , ) else select(:record, method, , , ) end operators ? build_active_scaffold_search_range_ui(operators, select, **range_opts) : select end |
#active_scaffold_search_select_comparator_options(column, ui_options: column.options) ⇒ Object
219 220 221 222 223 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 219 def (column, ui_options: column.) = [[as_(:'='), '=']] .concat(ActiveScaffold::Finder::NULL_COMPARATORS.collect { |comp| [as_(comp), comp] }) end |
#active_scaffold_search_select_multiple(column, options, ui_options: column.options) ⇒ Object
138 139 140 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 138 def active_scaffold_search_select_multiple(column, , ui_options: column.) active_scaffold_search_select(column, .merge(multiple: true), ui_options: ) end |
#active_scaffold_search_text(column, options, ui_options: column.options) ⇒ Object
146 147 148 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 146 def active_scaffold_search_text(column, , ui_options: column.) text_field :record, column.name, () end |
#active_scaffold_search_time(column, options, ui_options: column.options) ⇒ Object
297 298 299 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 297 def active_scaffold_search_time(column, , ui_options: column.) active_scaffold_search_datetime(column, , ui_options: , field_ui: :time) end |
#active_scaffold_search_time_field(column, options, current_search, name, ui_options: column.options) ⇒ Object
384 385 386 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 384 def active_scaffold_search_time_field(column, , current_search, name, ui_options: column.) active_scaffold_search_datetime_field(column, .merge!(discard_date: true), current_search, name, ui_options: ) end |
#active_scaffold_search_timestamp(column, options, ui_options: column.options) ⇒ Object
293 294 295 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 293 def (column, , ui_options: column.) active_scaffold_search_datetime(column, , ui_options: , field_ui: :datetime) end |
#build_active_scaffold_search_range_ui(operators, from, to = nil, name:, id:, opt_value: nil) ⇒ Object
254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 254 def build_active_scaffold_search_range_ui(operators, from, to = nil, name:, id:, opt_value: nil) opt_value ||= operators[0][1] html = select_tag("#{name}[opt]", (operators, opt_value), id: "#{id}_opt", class: 'as_search_range_option') if to from << content_tag( :span, safe_join([' - ', to]), id: "#{id}_between", class: 'as_search_range_between', style: ('display: none' unless opt_value == 'BETWEEN') ) end html << content_tag('span', from, id: "#{id}_numeric", style: ActiveScaffold::Finder::NULL_COMPARATORS.include?(opt_value) ? 'display: none' : nil) content_tag :span, html, class: 'search_range' end |
#column_datetime?(column) ⇒ Boolean
364 365 366 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 364 def column_datetime?(column) !column.column.nil? && i[datetime time].include?(column.column_type) end |
#field_search_params_range_values(column) ⇒ Object
196 197 198 199 200 201 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 196 def field_search_params_range_values(column) values = field_search_params[column.name.to_s] return nil unless values.is_a? Hash [values['opt'], values['from'].presence, values['to'].presence] end |
#include_null_comparators?(column, ui_options: column.options) ⇒ Boolean
225 226 227 228 229 230 231 232 233 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 225 def include_null_comparators?(column, ui_options: column.) return [:null_comparators] if .key? :null_comparators if column.association !column.association.belongs_to? || active_scaffold_config.columns[column.association.foreign_key].null? else column.null? end end |
#override_search(form_ui) ⇒ Object
the naming convention for overriding search input types with helpers
401 402 403 404 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 401 def override_search(form_ui) method = "active_scaffold_search_#{form_ui}" method if respond_to? method end |
#override_search_field(column) ⇒ Object
396 397 398 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 396 def override_search_field(column) override_helper column, 'search_column' end |
#search_attribute(column, record) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 55 def search_attribute(column, record) = (column).merge(object: record) content_tag :dl do content_tag(:dt, label_tag(search_label_for(column, ), search_column_label(column, record))) << content_tag(:dd, active_scaffold_search_for(column, )) end end |
#search_column_label(column, record) ⇒ Object
Search column override signatures
392 393 394 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 392 def search_column_label(column, record) column.label end |
#search_label_for(column, options) ⇒ Object
63 64 65 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 63 def search_label_for(column, ) [:id] unless i[range integer decimal float string date_picker datetime_picker calendar_date_select].include? column.search_ui end |
#searched_by?(column) ⇒ Boolean
425 426 427 428 429 430 431 432 433 434 435 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 425 def searched_by?(column) value = field_search_params[column.name.to_s] case value when Hash value['from'].present? when String value.present? else false end end |
#visibles_and_hiddens(search_config, columns = search_config.columns) ⇒ Object
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
# File 'lib/active_scaffold/helpers/search_column_helpers.rb', line 406 def visibles_and_hiddens(search_config, columns = search_config.columns) visibles = [] hiddens = [] columns.each_column do |column| next unless column.respond_to?(:each_column) || column.search_sql if search_config.optional_columns.include?(column.name) && !searched_by?(column) hiddens << column else visibles << column end end if active_scaffold_group_column group = grouped_search? || search_config.optional_columns.empty? ? visibles : hiddens group << active_scaffold_group_column end [visibles, hiddens] end |