<commit_before>module EffectiveDatatablesHelper
  def render_datatable(datatable, opts = {}, &block)
    datatable.view = self
    locals = {style: :full, filterable: true, sortable: true, table_class: 'table-bordered table-striped'}.merge(opts)

    render partial: 'effective/datatables/datatable', locals: locals.merge(datatable: datatable)
  end

  def render_simple_datatable(datatable, opts = {})
    datatable.view = self
    datatable.per_page = :all
    locals = {style: :simple, filterable: false, sortable: false, table_class: 'table-bordered table-striped sorting-hidden'}.merge(opts)

    render partial: 'effective/datatables/datatable', locals: locals.merge(datatable: datatable)
  end

  def render_datatable_header_cell(form, name, opts, filterable = true)
    return render(partial: opts[:header_partial], locals: {form: form, name: (opts[:label] || name), column: opts, filterable: filterable}) if opts[:header_partial].present?
    return content_tag(:p, opts[:label] || name) if filterable == false

    case opts[:filter][:type]
    when :string, :text, :number
      form.input name, label: false, required: false, as: :string, placeholder: (opts[:label] || name),
        input_html: { name: nil, autocomplete: 'off', data: {'column-name' => opts[:name], 'column-index' => opts[:index]} }

    when :date
      form.input name, label: false, required: false,
        as: (defined?(EffectiveFormInputs) ? :effective_date_picker : :string),
        placeholder: (opts[:label] || name),
        input_group: false,
        input_html: { name: nil, autocomplete: 'off', data: {'column-name' => opts[:name], 'column-index' => opts[:index]} }
    when :datetime
      form.input name, label: false, required: false,
        as: (defined?(EffectiveFormInputs) ? :effective_date_time_picker : :string),
        placeholder: (opts[:label] || name),
        input_group: false,
        input_html: { name: nil, autocomplete: 'off', data: {'column-name' => opts[:name], 'column-index' => opts[:index]} }
    when :select, :boolean
      form.input name, label: false, required: false,
        as: (defined?(EffectiveFormInputs) ? :effective_select : :select),
        collection: opts[:filter][:values],
        multiple: opts[:filter][:multiple] == true,
        include_blank: (opts[:label] || name.titleize),
        input_html: { name: nil, autocomplete: 'off', data: {'column-name' => opts[:name], 'column-index' => opts[:index]} },
        input_js: { placeholder: (opts[:label] || name.titleize) }
    when :grouped_select
      form.input name, label: false, required: false,
        as: (defined?(EffectiveFormInputs) ? :effective_select : :grouped_select),
        collection: opts[:filter][:values],
        multiple: opts[:filter][:multiple] == true,
        include_blank: (opts[:label] || name.titleize),
        grouped: true,
        polymorphic: opts[:filter][:polymorphic] == true,
        group_label_method: opts[:filter][:group_label_method] || :first,
        group_method: opts[:filter][:group_method] || :last,
        input_html: { name: nil, autocomplete: 'off', data: {'column-name' => opts[:name], 'column-index' => opts[:index]} },
        input_js: { placeholder: (opts[:label] || name.titleize) }
    else
      content_tag(:p, opts[:label] || name)<commit_msg>Allow filterable year-month selections on date time picker<commit_after>module EffectiveDatatablesHelper
  def render_datatable(datatable, opts = {}, &block)
    datatable.view = self
    locals = {style: :full, filterable: true, sortable: true, table_class: 'table-bordered table-striped'}.merge(opts)

    render partial: 'effective/datatables/datatable', locals: locals.merge(datatable: datatable)
  end

  def render_simple_datatable(datatable, opts = {})
    datatable.view = self
    datatable.per_page = :all
    locals = {style: :simple, filterable: false, sortable: false, table_class: 'table-bordered table-striped sorting-hidden'}.merge(opts)

    render partial: 'effective/datatables/datatable', locals: locals.merge(datatable: datatable)
  end

  def render_datatable_header_cell(form, name, opts, filterable = true)
    return render(partial: opts[:header_partial], locals: {form: form, name: (opts[:label] || name), column: opts, filterable: filterable}) if opts[:header_partial].present?
    return content_tag(:p, opts[:label] || name) if filterable == false

    case opts[:filter][:type]
    when :string, :text, :number
      form.input name, label: false, required: false, as: :string, placeholder: (opts[:label] || name),
        input_html: { name: nil, autocomplete: 'off', data: {'column-name' => opts[:name], 'column-index' => opts[:index]} }

    when :date
      form.input name, label: false, required: false,
        as: (defined?(EffectiveFormInputs) ? :effective_date_picker : :string),
        placeholder: (opts[:label] || name),
        input_group: false,
        input_html: { name: nil, autocomplete: 'off', data: {'column-name' => opts[:name], 'column-index' => opts[:index]} },
        input_js: { useStrict: true, keepInvalid: true }
    when :datetime
      form.input name, label: false, required: false,
        as: (defined?(EffectiveFormInputs) ? :effective_date_time_picker : :string),
        placeholder: (opts[:label] || name),
        input_group: false,
        input_html: { name: nil, autocomplete: 'off', data: {'column-name' => opts[:name], 'column-index' => opts[:index]} },
        input_js: { useStrict: true, keepInvalid: true } # Keep invalid format like "2015-11" so we can still filter by year, month or day
    when :select, :boolean
      form.input name, label: false, required: false,
        as: (defined?(EffectiveFormInputs) ? :effective_select : :select),
        collection: opts[:filter][:values],
        multiple: opts[:filter][:multiple] == true,
        include_blank: (opts[:label] || name.titleize),
        input_html: { name: nil, autocomplete: 'off', data: {'column-name' => opts[:name], 'column-index' => opts[:index]} },
        input_js: { placeholder: (opts[:label] || name.titleize) }
    when :grouped_select
      form.input name, label: false, required: false,
        as: (defined?(EffectiveFormInputs) ? :effective_select : :grouped_select),
        collection: opts[:filter][:values],
        multiple: opts[:filter][:multiple] == true,
        include_blank: (opts[:label] || name.titleize),
        grouped: true,
        polymorphic: opts[:filter][:polymorphic] == true,
        group_label_method: opts[:filter][:group_label_method] || :first,
        group_method: opts[:filter][:group_method] || :last,
        input_html: { name: nil, autocomplete: 'off', data: {'column-name' => opts[:name], 'column-index' => opts[:index]} },
        input_js: { placeholder: (opts[:label] || name.titleize) }
    else
      content_tag(:p, opts[:label] || name)
{'fraction_non_alphanumeric': 0.15584415584415584, 'fraction_numerical': 0.0008755289654166059, 'mean_word_length': 4.0397058823529415, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '965193', 'n_tokens_mistral': 2082, 'n_tokens_neox': 2067, 'n_words': 517}