<commit_before>class Admin::TagsController < Admin::BaseController
  def index
    @tags       = ActsAsTaggableOn::Tag.all.sort_by {|tag| tag.name.downcase}
    @categories = Category.all
  end

  def edit
    @tag = ActsAsTaggableOn::Tag.find(params[:id])
  end

  def update
    @tag = ActsAsTaggableOn::Tag.find(params[:id])
    if existing_tag = ActsAsTaggableOn::Tag.where(name: params[:tag][:name]).first
      existing_tag.merge(@tag)
      redirect_to categorization_admin_tags_path, notice: ("'#{@tag.name}' was merged with the tag '#{existing_tag.name}'.")
    elsif @tag.update_attributes(params[:tag])
      redirect_to categorization_admin_tags_path, notice: ("'#{@tag.name}' was updated.")
    else
      render action: "edit"
    end
  end

  def destroy
    @tag = ActsAsTaggableOn::Tag.find(params[:id])
    @tag.destroy
    redirect_to categorization_admin_tags_path, notice: ("'#{@tag.name}' was destroyed.")

  end

  def remove_category
    @tag      = ActsAsTaggableOn::Tag.find(params[:id])
    @category = Category.find(params[:category_id])
    @tag.categories.delete @category
    redirect_to categorization_admin_tags_path(page: params[:page], q: params[:q]), alert: ("The tag '#{@tag.name}' is deleted from the category '#{@category.name}'.")
  end

  def set_category
    @tag      = ActsAsTaggableOn::Tag.find(params[:id])
    @category = Category.find(params[:category_id])
    @tag.categories << @category
    redirect_to categorization_admin_tags_path(page: params[:page], q: params[:q]), notice: ("Just added the tag '#{@tag.name}' to the category '#{@category.name}'.")
  end

  def categorization
    if params[:q] && params[:uncategorized]
        @tags       = ActsAsTaggableOn::Tag
                      .where("name ILIKE ?", "%" + params[:q] + "%")
                      .joins(:categories).where(categories: { id: nil})
                      .order('name ASC')
                      .page(params[:page])
                      .per(100)
    elsif params[:q]
        @tags       = ActsAsTaggableOn::Tag.where("name ILIKE ?", "%" + params[:q] + "%")
                      .order('name ASC')
                      .page(params[:page])
                      .per(100)
    elsif params[:uncategorized]
        @tags       = ActsAsTaggableOn::Tag
                      .joins(:categories_tags).where(categories_tags: { id: nil})
                      .order('name ASC')
                      .page(params[:page])
                      .per(100)
    else
      @tags       = ActsAsTaggableOn::Tag.order('name ASC').page(params[:page]).per(100)
    end
    @categories = Category.all
  end
end
<commit_msg>checkbox does not work yet<commit_after>class Admin::TagsController < Admin::BaseController
  def index
    @tags       = ActsAsTaggableOn::Tag.all.sort_by {|tag| tag.name.downcase}
    @categories = Category.all
  end

  def edit
    @tag = ActsAsTaggableOn::Tag.find(params[:id])
  end

  def update
    @tag = ActsAsTaggableOn::Tag.find(params[:id])
    if existing_tag = ActsAsTaggableOn::Tag.where(name: params[:tag][:name]).first
      existing_tag.merge(@tag)
      redirect_to categorization_admin_tags_path, notice: ("'#{@tag.name}' was merged with the tag '#{existing_tag.name}'.")
    elsif @tag.update_attributes(params[:tag])
      redirect_to categorization_admin_tags_path, notice: ("'#{@tag.name}' was updated.")
    else
      render action: "edit"
    end
  end

  def destroy
    @tag = ActsAsTaggableOn::Tag.find(params[:id])
    @tag.destroy
    redirect_to categorization_admin_tags_path, notice: ("'#{@tag.name}' was destroyed.")

  end

  def remove_category
    @tag      = ActsAsTaggableOn::Tag.find(params[:id])
    @category = Category.find(params[:category_id])
    @tag.categories.delete @category
    redirect_to categorization_admin_tags_path(page: params[:page], q: params[:q]), alert: ("The tag '#{@tag.name}' is deleted from the category '#{@category.name}'.")
  end

  def set_category
    @tag      = ActsAsTaggableOn::Tag.find(params[:id])
    @category = Category.find(params[:category_id])
    @tag.categories << @category
    redirect_to categorization_admin_tags_path(page: params[:page], q: params[:q]), notice: ("Just added the tag '#{@tag.name}' to the category '#{@category.name}'.")
  end

  def categorization
    if params[:q] && params[:uncategorized]
        @tags       = ActsAsTaggableOn::Tag
                      .where("name ILIKE ?", "%" + params[:q] + "%")
                      .joins(:categories).where(categories: { id: nil})
                      .order('name ASC')
                      .page(params[:page])
                      .per(100)
    elsif params[:q]
        @tags       = ActsAsTaggableOn::Tag.where("name ILIKE ?", "%" + params[:q] + "%")
                      .order('name ASC')
                      .page(params[:page])
                      .per(100)
    elsif params[:uncategorized]
        @tags       = ActsAsTaggableOn::Tag
                      .joins(:categories).where(categories: { id: nil})
                      .order('name ASC')
                      .page(params[:page])
                      .per(100)
    else
      @tags       = ActsAsTaggableOn::Tag.order('name ASC').page(params[:page]).per(100)
    end
    @categories = Category.all
  end
end

{'fraction_non_alphanumeric': 0.14656315091838668, 'fraction_numerical': 0.0045445938269267185, 'mean_word_length': 2.595643294758339, 'pattern_counts': {'":': 0, '<': 9, '<?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': '7045539', 'n_tokens_mistral': 1685, 'n_tokens_neox': 1610, 'n_words': 318}