<commit_before>require "action_view"

module Datagrid
  module FormBuilder

    # Returns a form input html for the corresponding filter name
    def datagrid_filter(filter_or_attribute, options = {})
      filter = datagrid_get_filter(filter_or_attribute)
      options = add_html_classes(options, filter.name, datagrid_filter_html_class(filter))
      self.send(filter.form_builder_helper_name, filter, options)
    end

    # Returns a form label html for the corresponding filter name
    def datagrid_label(filter_or_attribute, options = {})
      filter = datagrid_get_filter(filter_or_attribute)
      self.label(filter.name, filter.header, options)
    end

    protected
    def datagrid_boolean_enum_filter(attribute_or_filter, options = {})
      datagrid_enum_filter(attribute_or_filter, options)
    end

    def datagrid_boolean_filter(attribute_or_filter, options = {})
      check_box(datagrid_get_attribute(attribute_or_filter), options.reverse_merge(datagrid_extra_checkbox_options))
    end

    def datagrid_date_filter(attribute_or_filter, options = {})
      datagrid_range_filter(:date, attribute_or_filter, options)
    end

    def datagrid_default_filter(attribute_or_filter, options = {})
      filter = datagrid_get_filter(attribute_or_filter)
      text_field filter.name, options.reverse_merge(:value => object.filter_value_as_string(filter))
    end

    def datagrid_enum_filter(attribute_or_filter, options = {})
      filter = datagrid_get_filter(attribute_or_filter)
      if !options.has_key?(:multiple) && filter.multiple?
        options[:multiple] = true
      end
      if filter.checkboxes?
        filter.select(object).map do |element|
          text, value = @template.send(:option_text_and_value, element)
          id = [object_name, filter.name, value.underscore].join('_')
          input = check_box(filter.name, options.merge(datagrid_extra_checkbox_options).reverse_merge(:id => id, :multiple => true), value, nil)
          label(filter.name, input + text, :for => id)
        end.join("\n").html_safe
      else
        select filter.name, filter.select(object) || [], {:include_blank => filter.include_blank, :prompt => filter.prompt, :include_hidden => false}, options
      end
    end

    def datagrid_integer_filter(attribute_or_filter, options = {})
      filter = datagrid_get_filter(attribute_or_filter)
      if filter.multiple? && self.object[filter.name].blank?
        options[:value] = ""
      end
      datagrid_range_filter(:integer, filter, options)
    end
<commit_msg>Bugfix select filter with checkboxes<commit_after>require "action_view"

module Datagrid
  module FormBuilder

    # Returns a form input html for the corresponding filter name
    def datagrid_filter(filter_or_attribute, options = {})
      filter = datagrid_get_filter(filter_or_attribute)
      options = add_html_classes(options, filter.name, datagrid_filter_html_class(filter))
      self.send(filter.form_builder_helper_name, filter, options)
    end

    # Returns a form label html for the corresponding filter name
    def datagrid_label(filter_or_attribute, options = {})
      filter = datagrid_get_filter(filter_or_attribute)
      self.label(filter.name, filter.header, options)
    end

    protected
    def datagrid_boolean_enum_filter(attribute_or_filter, options = {})
      datagrid_enum_filter(attribute_or_filter, options)
    end

    def datagrid_boolean_filter(attribute_or_filter, options = {})
      check_box(datagrid_get_attribute(attribute_or_filter), options.reverse_merge(datagrid_extra_checkbox_options))
    end

    def datagrid_date_filter(attribute_or_filter, options = {})
      datagrid_range_filter(:date, attribute_or_filter, options)
    end

    def datagrid_default_filter(attribute_or_filter, options = {})
      filter = datagrid_get_filter(attribute_or_filter)
      text_field filter.name, options.reverse_merge(:value => object.filter_value_as_string(filter))
    end

    def datagrid_enum_filter(attribute_or_filter, options = {})
      filter = datagrid_get_filter(attribute_or_filter)
      if !options.has_key?(:multiple) && filter.multiple?
        options[:multiple] = true
      end
      if filter.checkboxes?
        filter.select(object).map do |element|
          text, value = @template.send(:option_text_and_value, element)
          id = [object_name, filter.name, value].join('_').underscore
          input = check_box(filter.name, options.merge(datagrid_extra_checkbox_options).reverse_merge(:id => id, :multiple => true), value, nil)
          label(filter.name, input + text, :for => id)
        end.join("\n").html_safe
      else
        select filter.name, filter.select(object) || [], {:include_blank => filter.include_blank, :prompt => filter.prompt, :include_hidden => false}, options
      end
    end

    def datagrid_integer_filter(attribute_or_filter, options = {})
      filter = datagrid_get_filter(attribute_or_filter)
      if filter.multiple? && self.object[filter.name].blank?
        options[:value] = ""
      end
      datagrid_range_filter(:integer, filter, options)
    end

{'fraction_non_alphanumeric': 0.09520078354554358, 'fraction_numerical': 0.0, 'mean_word_length': 4.020648967551622, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '747972', 'n_tokens_mistral': 1531, 'n_tokens_neox': 1521, 'n_words': 290}