<commit_before>module Admin::Resources::TableHelper

  def build_table(model, fields, items, link_options = {}, association = nil, association_name = nil)
    locals = { :model => model,
               :fields => fields,
               :items => items,
               :link_options => link_options,
               :headers => table_header(model, fields),
               :association_name => association_name }

    render "helpers/admin/resources/table", locals
  end

  def table_header(model, fields, params = params)
    fields.map do |key, value|

      key = key.gsub(".", " ") if key.to_s.match(/\./)
      content = model.human_attribute_name(key)

      if params[:action].eql?('index') && model.typus_options_for(:sortable)
        association = model.reflect_on_association(key.to_sym)
        order_by = association ? association.foreign_key : key

        if (model.model_fields.map(&:first).map { |i| i.to_s }.include?(key) || model.reflect_on_all_associations(:belongs_to).map(&:name).include?(key.to_sym))
          sort_order = case params[:sort_order]
                       when 'asc' then ['desc', '&darr;']
                       when 'desc' then ['asc', '&uarr;']
                       else [nil, nil]
                       end
          switch = sort_order.last if params[:order_by].eql?(order_by)
          options = { :order_by => order_by, :sort_order => sort_order.first }
          message = [content, switch].compact.join(" ").html_safe
          content = link_to(message, params.merge(options))
        end
      end

      content
    end
  end

  def table_fields_for_item(item, fields)
    fields.map { |k, v| send("table_#{v}_field", k, item) }
  end

  def table_actions(model, item, association_name = nil)
    resource_actions.reject! do |body, url, options, proc|
      admin_user.cannot?(url[:action], model.name)
    end

    resource_actions.map do |body, url, options, proc|
      next if proc && proc.respond_to?(:call) && proc.call(item) == false
      { :message => Typus::I18n.t(body),
        :url => params.dup.cleanup.merge(url).merge(:controller => "/admin/#{model.to_resource}", :id => item.id),
        :options => options }
    end
  end

end
<commit_msg>Reverse merge of Hash so we can override the controller.<commit_after>module Admin::Resources::TableHelper

  def build_table(model, fields, items, link_options = {}, association = nil, association_name = nil)
    locals = { :model => model,
               :fields => fields,
               :items => items,
               :link_options => link_options,
               :headers => table_header(model, fields),
               :association_name => association_name }

    render "helpers/admin/resources/table", locals
  end

  def table_header(model, fields, params = params)
    fields.map do |key, value|

      key = key.gsub(".", " ") if key.to_s.match(/\./)
      content = model.human_attribute_name(key)

      if params[:action].eql?('index') && model.typus_options_for(:sortable)
        association = model.reflect_on_association(key.to_sym)
        order_by = association ? association.foreign_key : key

        if (model.model_fields.map(&:first).map { |i| i.to_s }.include?(key) || model.reflect_on_all_associations(:belongs_to).map(&:name).include?(key.to_sym))
          sort_order = case params[:sort_order]
                       when 'asc' then ['desc', '&darr;']
                       when 'desc' then ['asc', '&uarr;']
                       else [nil, nil]
                       end
          switch = sort_order.last if params[:order_by].eql?(order_by)
          options = { :order_by => order_by, :sort_order => sort_order.first }
          message = [content, switch].compact.join(" ").html_safe
          content = link_to(message, params.merge(options))
        end
      end

      content
    end
  end

  def table_fields_for_item(item, fields)
    fields.map { |k, v| send("table_#{v}_field", k, item) }
  end

  def table_actions(model, item, association_name = nil)
    resource_actions.reject! do |body, url, options, proc|
      admin_user.cannot?(url[:action], model.name)
    end

    resource_actions.map do |body, url, options, proc|
      next if proc && proc.respond_to?(:call) && proc.call(item) == false
      { :message => Typus::I18n.t(body),
        :url => { :controller => "/admin/#{model.to_resource}", :id => item.id }.merge(params.dup.cleanup.merge(url)),
        :options => options }
    end
  end

end

{'fraction_non_alphanumeric': 0.1399149317215133, 'fraction_numerical': 0.0008954555630176853, 'mean_word_length': 2.577261809447558, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, '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': '663319', 'n_tokens_mistral': 1381, 'n_tokens_neox': 1359, 'n_words': 300}