<commit_before>module AbAdmin
  module Views
    class SearchFormBuilder < ::Ransack::Helpers::FormBuilder
      delegate :content_tag, :tag, :params,
               :text_field_tag, :check_box_tag, :radio_button_tag, :label_tag, :select_tag,
               :options_for_select, :options_from_collection_for_select, :hidden_field_tag, to: :@template

      def input(attr, options={})
        field_type = field_type(attr, options)
        content_tag :div, class: "clearfix #{field_type} #{options[:wrapper_class]}" do
          send("#{field_type}_field", attr, options)
        end
      end

      def select_field(attr, options={})
        label(attr, options[:label]) + content_tag(:div, class: 'controls') do
          param = options[:param] || "#{options[:value_attr] || attr}_eq"

          if options[:collection].is_a?(Proc)
            collection = options[:collection].call
          else
            collection = options[:collection] || []
          end

          if collection.first.try(:respond_to?, :id)
            collection.map!{|r| [AbAdmin.display_name(r), r.id] }
          end

          options[:input_html] ||= {}
          if options[:fancy] || !options.has_key?(:fancy)
            options[:input_html][:class] = [options[:input_html][:class], 'fancy_select'].join(' ')
          end

          html_options = options[:input_html].merge(include_blank: true, id: "q_#{attr}")
          select_tag("q[#{param}]", options_for_select(collection, params[:q][param]), html_options)
        end
      end

      def date_field(attr, options={})<commit_msg>add ac_select_field<commit_after>module AbAdmin
  module Views
    class SearchFormBuilder < ::Ransack::Helpers::FormBuilder
      delegate :content_tag, :tag, :params,
               :text_field_tag, :check_box_tag, :radio_button_tag, :label_tag, :select_tag,
               :options_for_select, :options_from_collection_for_select, :hidden_field_tag, to: :@template

      def input(attr, options={})
        field_type = field_type(attr, options)
        content_tag :div, class: "clearfix #{field_type} #{options[:wrapper_class]}" do
          send("#{field_type}_field", attr, options)
        end
      end

      def select_field(attr, options={})
        label(attr, options[:label]) + content_tag(:div, class: 'controls') do
          param = options[:param] || "#{options[:value_attr] || attr}_eq"

          if options[:collection].is_a?(Proc)
            collection = options[:collection].call
          else
            collection = options[:collection] || []
          end

          if collection.first.try(:respond_to?, :id)
            collection.map!{|r| [AbAdmin.display_name(r), r.id] }
          end

          options[:input_html] ||= {}
          if options[:fancy] || !options.has_key?(:fancy)
            options[:input_html][:class] = [options[:input_html][:class], 'fancy_select'].join(' ')
          end

          html_options = options[:input_html].merge(include_blank: true, id: "q_#{attr}")
          select_tag("q[#{param}]", options_for_select(collection, params[:q][param]), html_options)
        end
      end

      def ac_select_field(attr, options={})
        klass = options[:klass]
        options[:param] ||= "#{options[:value_attr] || attr}_eq"
        pre_select = params.val(:q, options[:param]) ? klass.where(id: params[:q][options[:param]]).map(&:for_input_token) : []
        options[:input_html] ||= {}
        options[:input_html].deep_merge! class: 'fancy_select', data: {class: klass.name, pre: pre_select.to_json}
        string_field attr, options
      end

      def date_field(attr, options={})
{'fraction_non_alphanumeric': 0.14765840220385676, 'fraction_numerical': 0.0, 'mean_word_length': 2.998898678414097, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '119956', 'n_tokens_mistral': 1094, 'n_tokens_neox': 1088, 'n_words': 204}