<commit_before>module ControllerMixins
  module RendererInstanceMethods
    def render_table_for(logged_user, template = nil, &proc)
      @settings[:template] = template unless template.blank?
      data = yield
      class_obj = data.respond_to?(:klass) ? data.klass : data
      if action_name == "filter"
        default_params = params
        if !params.blank? && params["clear"]
          default_params = @settings[:default].dup
          default_params[:order_by] = @settings[:default][:order_by] + " " + @settings[:default][:order_by_direction] if !@settings[:default][:order_by].blank? && !@settings[:default][:order_by_direction].blank?
          default_params[:order_by] = @settings[:default][:order] if !@settings[:default][:order].blank?
        end

        @settings = class_obj.prepare_settings(logged_user, data, @settings, default_params)
        if !params.blank? && params["clear"]
          session["#{@settings[:form_id]}_params"] = ""
          render :layout => false, :action => :index
        else
          @paginate = render_to_string(:partial => "/helpers/build_table_pager", :locals => {:settings => @settings})
          session["#{@settings[:form_id]}_params"] = params
          if @settings[:template].blank?
            # if there is no template a will return json and tbody renders in javascript template
            returned_t_body = @settings.to_json
          else
            # or there is template so i will return template rendered here in ruby
            returned_t_body = render_to_string(:partial => @settings[:template], :locals => {:settings => @settings})
          end

          render :layout => false, :json => {:settings => returned_t_body, :paginate => @paginate}.to_json
        end
      elsif action_name == "index"
        default_params = @settings[:default]
        default_params = session["#{@settings[:form_id]}_params"] unless session["#{@settings[:form_id]}_params"].blank?
        @settings = class_obj.prepare_settings(logged_user, data, @settings, default_params)
      end
    end

    def fill_settings_with opts
      settings = {}
      settings[:symlink_remote] = true
      unless opts.at(0).nil?
        opts = opts[0]
        settings[:symlink_controller] = opts.include?(:controller) ? opts[:controller] : controller_name
        settings[:symlink_outer_controller] = opts[:outer_controller] if opts.include?(:outer_controller)
        settings[:symlink_outer_id] = opts[:outer_id] if opts.include?(:outer_id)
        settings[:symlink_action] = opts[:action] if opts.include?(:action)<commit_msg>ordering by more columns ,fix<commit_after>module ControllerMixins
  module RendererInstanceMethods
    def render_table_for(logged_user, template = nil, &proc)
      @settings[:template] = template unless template.blank?
      data = yield
      class_obj = data.respond_to?(:klass) ? data.klass : data
      if action_name == "filter"
        default_params = params
        if !params.blank? && params["clear"]
          default_params = @settings[:default].dup
          default_params[:order_by] = @settings[:default][:order_by] + " " + @settings[:default][:order_by_direction] if !@settings[:default][:order_by].blank? && !@settings[:default][:order_by_direction].blank?
          default_params[:order_by] = @settings[:default][:order] if !@settings[:default][:order].blank?
        end

        @settings = class_obj.prepare_settings(logged_user, data, @settings, default_params)
        if !params.blank? && params["clear"]
          session["#{@settings[:form_id]}_params"] = ""
          render :layout => false, :action => :index
        else
          @paginate = render_to_string(:partial => "/helpers/build_table_pager", :locals => {:settings => @settings})
          session["#{@settings[:form_id]}_params"] = params
          if @settings[:template].blank?
            # if there is no template a will return json and tbody renders in javascript template
            returned_t_body = @settings.to_json
          else
            # or there is template so i will return template rendered here in ruby
            returned_t_body = render_to_string(:partial => @settings[:template], :locals => {:settings => @settings})
          end

          render :layout => false, :json => {:settings => returned_t_body, :paginate => @paginate}.to_json
        end
      elsif action_name == "index"
        default_params = @settings[:default]
        default_params[:order_by] = @settings[:default][:order_by] + " " + @settings[:default][:order_by_direction] if !@settings[:default][:order_by].blank? && !@settings[:default][:order_by_direction].blank?
        default_params[:order_by] = @settings[:default][:order] if !@settings[:default][:order].blank?

        default_params = session["#{@settings[:form_id]}_params"] unless session["#{@settings[:form_id]}_params"].blank?
        @settings = class_obj.prepare_settings(logged_user, data, @settings, default_params)
      end
    end

    def fill_settings_with opts
      settings = {}
      settings[:symlink_remote] = true
      unless opts.at(0).nil?
        opts = opts[0]
        settings[:symlink_controller] = opts.include?(:controller) ? opts[:controller] : controller_name
        settings[:symlink_outer_controller] = opts[:outer_controller] if opts.include?(:outer_controller)
        settings[:symlink_outer_id] = opts[:outer_id] if opts.include?(:outer_id)
        settings[:symlink_action] = opts[:action] if opts.include?(:action)
{'fraction_non_alphanumeric': 0.13634706525701787, 'fraction_numerical': 0.0007291286912139992, 'mean_word_length': 3.5801335559265444, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '3743159', 'n_tokens_mistral': 1556, 'n_tokens_neox': 1550, 'n_words': 321}