<commit_before>module ActiveScaffold::Actions
  module List
    def self.included(base)
      base.before_filter :list_authorized_filter, :only => [:index, :row]
      base.helper_method :list_columns
    end

    def index
      list
    end

    # get just a single row
    def row
      get_row
      respond_to_action(:row)
    end

    def list
      if %w(index list).include? action_name
        do_list
      else
        do_refresh_list
      end
      @nested_auto_open = active_scaffold_config.list.nested_auto_open
      respond_to_action(:list)
    end
    
    protected
    def list_respond_to_html
      if embedded?
        render :action => 'list', :layout => false
      else
        render :action => 'list'
      end
    end
    def list_respond_to_js
      if params[:adapter] || embedded?
        render(:partial => 'list_with_header')
      else
        render :partial => 'refresh_list', :formats => [:js]
      end
    end
    def list_respond_to_xml
      render :xml => response_object.to_xml(:only => list_columns_names), :content_type => Mime::XML, :status => response_status
    end
    def list_respond_to_json
      render :text => response_object.to_json(:only => list_columns_names), :content_type => Mime::JSON, :status => response_status
    end
    def list_respond_to_yaml
      render :text => Hash.from_xml(response_object.to_xml(:only => list_columns_names)).to_yaml, :content_type => Mime::YAML, :status => response_status
    end
    
    def row_respond_to_html
      render(:partial => 'row', :locals => {:record => @record})
    end
    
    def row_respond_to_js
      render :action => 'row'
    end

    # The actual algorithm to prepare for the list view
    def set_includes_for_columns(action = :list)
      @cache_associations = true
      includes_for_list_columns = active_scaffold_config.send(action).columns.collect{ |c| c.includes }.flatten.uniq.compact
      self.active_scaffold_includes.concat includes_for_list_columns
    end
    
    def get_row
      set_includes_for_columns
      klass = beginning_of_chain.includes(active_scaffold_includes)
      @record = find_if_allowed(params[:id], :read, klass)
    end

    # The actual algorithm to prepare for the list view
    def do_list
      set_includes_for_columns

      options = { :sorting => active_scaffold_config.list.user.sorting,
        :count_includes => active_scaffold_config.list.user.count_includes }
      paginate = (params[:format].nil?) ? (accepts? :html, :js) : ['html', 'js'].include?(params[:format])
      if paginate
        options.merge!({
            :per_page => active_scaffold_config.list.user.per_page,
            :page => active_scaffold_config.list.user.page,
            :pagination => active_scaffold_config.list.pagination
          })
      end
      if active_scaffold_config.list.auto_select_columns
        options[:select] = active_scaffold_config.list.columns.map(&:select_columns).compact.flatten + active_scaffold_config.columns[active_scaffold_config.model.primary_key].auto_select_columns
      end

      page = find_page(options)
      total_pages = page.pager.number_of_pages
      if !page.pager.infinite? && !total_pages.zero? && page.number > total_pages<commit_msg>fix auto_select_columns<commit_after>module ActiveScaffold::Actions
  module List
    def self.included(base)
      base.before_filter :list_authorized_filter, :only => [:index, :row]
      base.helper_method :list_columns
    end

    def index
      list
    end

    # get just a single row
    def row
      get_row
      respond_to_action(:row)
    end

    def list
      if %w(index list).include? action_name
        do_list
      else
        do_refresh_list
      end
      @nested_auto_open = active_scaffold_config.list.nested_auto_open
      respond_to_action(:list)
    end
    
    protected
    def list_respond_to_html
      if embedded?
        render :action => 'list', :layout => false
      else
        render :action => 'list'
      end
    end
    def list_respond_to_js
      if params[:adapter] || embedded?
        render(:partial => 'list_with_header')
      else
        render :partial => 'refresh_list', :formats => [:js]
      end
    end
    def list_respond_to_xml
      render :xml => response_object.to_xml(:only => list_columns_names), :content_type => Mime::XML, :status => response_status
    end
    def list_respond_to_json
      render :text => response_object.to_json(:only => list_columns_names), :content_type => Mime::JSON, :status => response_status
    end
    def list_respond_to_yaml
      render :text => Hash.from_xml(response_object.to_xml(:only => list_columns_names)).to_yaml, :content_type => Mime::YAML, :status => response_status
    end
    
    def row_respond_to_html
      render(:partial => 'row', :locals => {:record => @record})
    end
    
    def row_respond_to_js
      render :action => 'row'
    end

    # The actual algorithm to prepare for the list view
    def set_includes_for_columns(action = :list)
      @cache_associations = true
      includes_for_list_columns = active_scaffold_config.send(action).columns.collect{ |c| c.includes }.flatten.uniq.compact
      self.active_scaffold_includes.concat includes_for_list_columns
    end
    
    def get_row
      set_includes_for_columns
      klass = beginning_of_chain.includes(active_scaffold_includes)
      @record = find_if_allowed(params[:id], :read, klass)
    end

    # The actual algorithm to prepare for the list view
    def do_list
      set_includes_for_columns

      options = { :sorting => active_scaffold_config.list.user.sorting,
        :count_includes => active_scaffold_config.list.user.count_includes }
      paginate = (params[:format].nil?) ? (accepts? :html, :js) : ['html', 'js'].include?(params[:format])
      if paginate
        options.merge!({
            :per_page => active_scaffold_config.list.user.per_page,
            :page => active_scaffold_config.list.user.page,
            :pagination => active_scaffold_config.list.pagination
          })
      end
      if active_scaffold_config.list.auto_select_columns
        options[:select] = active_scaffold_config.list.columns.map(&:select_columns).compact.flatten + active_scaffold_config.columns[active_scaffold_config.model.primary_key].select_columns
      end

      page = find_page(options)
      total_pages = page.pager.number_of_pages
      if !page.pager.infinite? && !total_pages.zero? && page.number > total_pages
{'fraction_non_alphanumeric': 0.0957824810752356, 'fraction_numerical': 0.0, 'mean_word_length': 3.041198501872659, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '7468557', 'n_tokens_mistral': 2022, 'n_tokens_neox': 2003, 'n_words': 402}