<commit_before>module SmarterListing::ControllerExtension

  def self.included base
    base.helper_method :collection, :resource
    base.include SmarterListing::Helper
  end

  def index
    collection
    respond_to do |format|
      format.html { render layout: self.class._layout }
      format.js { render action: 'index.js.erb' }
    end
  end

  def new
    instance_variable_get(resource_ivar) || instance_variable_set(resource_ivar, model.new(_resource_params))
    render 'smarter_listing/new'
  end

  def create
    instance_variable_get(resource_ivar) || instance_variable_set(resource_ivar, model.create(_resource_params))
    render 'smarter_listing/create'
  end

  def copy
    instance_variable_set resource_ivar, resource.dup
    render 'smarter_listing/copy'
  end

  def show
    resource
    render resource, object: resource
  end

  def edit
    resource
    render 'smarter_listing/edit'
  end

  def multi_edit
    @multi = true
    edit
  end

  def update
    resource.update _resource_params
    render 'smarter_listing/update'
  end

  def destroy
    resource.destroy
    render 'smarter_listing/destroy'
  end

  def filter_parameter
    self.class.instance_variable_get :@filter_parameter
  end

  def filtered(model)
    results = model.all
    unless params[filter_parameter].blank?
      if model.respond_to?(:search)
        results = results.search { fulltext "#{params[filter_parameter]}" }.results
      elsif model.respond_to?(:name)
        results = results.where("name LIKE ?", "%#{params[filter_parameter]}%")
      end
    end
    results = results.where.not(deleted_at: nil) if params[:show_deleted]
    results
  end

  def load_collection
    instance_variable_set collection_ivar, smart_listing_create(collection_sym, filtered(model), partial: "#{current_engine}/#{table_name}/table_header")
  end

  def load_resource
    instance_variable_set resource_ivar, (model.find(params[:id]) rescue (action_name == 'new' ? model.new(_resource_params) : nil))
  end

  def resource
    instance_variable_get(resource_ivar) || load_resource
  end

  def collection
    instance_variable_get(collection_ivar) || load_collection
  end

end<commit_msg>support show_deleted filter and search names<commit_after>module SmarterListing::ControllerExtension

  def self.included base
    base.helper_method :collection, :resource
    base.include SmarterListing::Helper
  end

  def index
    collection
    respond_to do |format|
      format.html { render layout: self.class._layout }
      format.js { render action: 'index.js.erb' }
    end
  end

  def new
    instance_variable_get(resource_ivar) || instance_variable_set(resource_ivar, model.new(_resource_params))
    render 'smarter_listing/new'
  end

  def create
    instance_variable_get(resource_ivar) || instance_variable_set(resource_ivar, model.create(_resource_params))
    render 'smarter_listing/create'
  end

  def copy
    instance_variable_set resource_ivar, resource.dup
    render 'smarter_listing/copy'
  end

  def show
    resource
    render resource, object: resource
  end

  def edit
    resource
    render 'smarter_listing/edit'
  end

  def multi_edit
    @multi = true
    edit
  end

  def update
    resource.update _resource_params
    render 'smarter_listing/update'
  end

  def destroy
    resource.destroy
    render 'smarter_listing/destroy'
  end

  def filter_parameter
    self.class.instance_variable_get :@filter_parameter
  end

  def filtered(model)
    results = model.all
    unless params[filter_parameter].blank?
      if model.respond_to?(:search)
        results = results.search { fulltext "#{params[filter_parameter]}" }.results
      elsif model.respond_to?(:name)
        results = results.where("name LIKE ?", "%#{params[filter_parameter]}%")
      end
    end
    if params[:show_deleted] == "1" && model.instance_methods.include?(:deleted?)
      if model.column_names.include?("deleted_at")
        results = results.where.not(deleted_at: nil)
      else
        results = results.where.not(status: model.statuses[:deleted])
      end
    end
    results
  end

  def load_collection
    instance_variable_set collection_ivar, smart_listing_create(collection_sym, filtered(model), partial: "#{current_engine}/#{table_name}/table_header")
  end

  def load_resource
    instance_variable_set resource_ivar, (model.find(params[:id]) rescue (action_name == 'new' ? model.new(_resource_params) : nil))
  end

  def resource
    instance_variable_get(resource_ivar) || load_resource
  end

  def collection
    instance_variable_get(collection_ivar) || load_collection
  end

end
{'fraction_non_alphanumeric': 0.0847750865051903, 'fraction_numerical': 0.00021626297577854672, 'mean_word_length': 3.787784679089027, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6260780', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1389, 'n_words': 310}