<commit_before>class CategoryController < ApplicationController
  public :render_to_string
  protect_from_forgery

  # no layout if xhr request
  layout Proc.new { |controller| controller.request.xhr? ? false : nil }, :only => [:edit, :add_new, :update, :create]

  def edit
  end

  def update
    if @category.update_attributes(params[:category])
      flash[:notice] = "Category has been updated"
      ajax_redirect_to collection_subjects_path(@collection.owner, @collection, {:anchor => "category-#{@category.id }"})
    else
      render :action => 'edit'
    end
  end

  def add_new
    @new_category = Category.new({ :collection_id => @collection.id })
    if @category.present?
      @new_category.parent = @category 
      @new_category.gis_enabled = @category.gis_enabled
    end
  end

  def create
    @new_category = Category.new(params[:category])
    @new_category.parent = Category.find(params[:category][:parent_id]) if params[:category][:parent_id].present?
    if @new_category.save
      flash[:notice] = "Category has been created"
      ajax_redirect_to collection_subjects_path(@collection.owner, @collection, {:anchor => "category-#{@new_category.id }"})
    else
      render :action => 'add_new'
    end
  end

  def delete
    anchor = @category.parent_id.present? ? "category-#{@category.parent_id}" : nil
    @category.destroy #_but_attach_children_to_parent
    
    flash[:notice] = "Category has been deleted"
    ajax_redirect_to collection_subjects_path(@collection.owner, @collection, {:anchor => anchor})
  end
  def enable_gis
    @category.update_attribute(:gis_enabled, true)
    @category.descendants.each {|d| d.update_attribute(:gis_enabled, true)}
    
    flash[:notice] = "GIS Enabled for #{@category.title}"
    ajax_redirect_to collection_subjects_path(@collection.owner, @collection, {:anchor => "category-#{@category.id }"})
  end
  def disable_gis
    @category.update_attribute(:gis_enabled, false)
    @category.descendants.each {|d| d.update_attribute(:gis_enabled, false)}
    
    flash[:notice] = "GIS Disabled for #{@category.title}"
    ajax_redirect_to collection_subjects_path(@collection.owner, @collection, {:anchor => "category-#{@category.id }"})
  end
end<commit_msg>GIS En/Disabled flash messages indicate number of updated child categories<commit_after>class CategoryController < ApplicationController
  public :render_to_string
  protect_from_forgery

  # no layout if xhr request
  layout Proc.new { |controller| controller.request.xhr? ? false : nil }, :only => [:edit, :add_new, :update, :create]

  def edit
  end

  def update
    if @category.update_attributes(params[:category])
      flash[:notice] = "Category has been updated"
      ajax_redirect_to collection_subjects_path(@collection.owner, @collection, {:anchor => "category-#{@category.id }"})
    else
      render :action => 'edit'
    end
  end

  def add_new
    @new_category = Category.new({ :collection_id => @collection.id })
    if @category.present?
      @new_category.parent = @category 
      @new_category.gis_enabled = @category.gis_enabled
    end
  end

  def create
    @new_category = Category.new(params[:category])
    @new_category.parent = Category.find(params[:category][:parent_id]) if params[:category][:parent_id].present?
    if @new_category.save
      flash[:notice] = "Category has been created"
      ajax_redirect_to collection_subjects_path(@collection.owner, @collection, {:anchor => "category-#{@new_category.id }"})
    else
      render :action => 'add_new'
    end
  end

  def delete
    anchor = @category.parent_id.present? ? "category-#{@category.parent_id}" : nil
    @category.destroy #_but_attach_children_to_parent
    
    flash[:notice] = "Category has been deleted"
    ajax_redirect_to collection_subjects_path(@collection.owner, @collection, {:anchor => anchor})
  end
  def enable_gis
    @category.update_attribute(:gis_enabled, true)
    @category.descendants.each {|d| d.update_attribute(:gis_enabled, true)}
    
    notice = "GIS Enabled for #{@category.title}"
    if @category.descendants.count > 0
      notice << " and #{@category.descendants.count} child categories"
    end
    
    flash[:notice] = notice
    ajax_redirect_to collection_subjects_path(@collection.owner, @collection, {:anchor => "category-#{@category.id }"})
  end
  def disable_gis
    @category.update_attribute(:gis_enabled, false)
    @category.descendants.each {|d| d.update_attribute(:gis_enabled, false)}
    
    notice = "GIS Disabled for #{@category.title}"
    if @category.descendants.count > 0
      notice << " and #{@category.descendants.count} child categories"
    end
    
    flash[:notice] = notice
    ajax_redirect_to collection_subjects_path(@collection.owner, @collection, {:anchor => "category-#{@category.id }"})
  end
end
{'fraction_non_alphanumeric': 0.1252336448598131, 'fraction_numerical': 0.0004153686396677051, 'mean_word_length': 4.195253505933118, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, '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': '4539051', 'n_tokens_mistral': 1507, 'n_tokens_neox': 1457, 'n_words': 316}