<commit_before>class Admin::Page::ContentsController < Admin::BaseController
  default_param :content, :author_id, :only => [:create, :update], &lambda { current_user.id }

  before_filter :protect_single_content_mode
  before_filter :set_section
  before_filter :set_categories, :only => [:new, :edit]

  guards_permissions :content, :update => :update_all

  def index
    @contents = @section.contents #.filtered params[:filters]
  end

  def update_all
    params[:contents].each do |id, attrs|
      content = Content.find id
      if attrs[:parent_id] =~ /^\d+$/
        content.move_to_child_of attrs[:parent_id]
      else
        content.move_to_root
      end
      content.move_to_right_of attrs[:left_id] if attrs[:left_id]
    end
    render :text => 'OK'
  end
  
  protected 

    def current_resource
      @content || @section
    end

    def set_menu
      @menu = Menus::Admin::Contents.new
    end

    def set_categories
      @categories = @section.categories.roots
    end

    def protect_single_content_mode
      if params[:action] == 'index' and @section.try(:single_article_mode)
        redirect_to @section.contents.empty? ?
          new_admin_article_url(@site, @section, :content => { :title => @section.title }) :<commit_msg>refactor Admin::Page::ContentsController#update_all and fix some bugs.<commit_after>class Admin::Page::ContentsController < Admin::BaseController
  default_param :content, :author_id, :only => [:create, :update], &lambda { current_user.id }

  before_filter :protect_single_content_mode
  before_filter :set_section
  before_filter :set_categories, :only => [:new, :edit]

  guards_permissions :content, :update => :update_all

  def index
    @contents = @section.contents #.filtered params[:filters]
  end

  def update_all
    params[:contents].each do |id, attrs|
      content = Content.find id
      parent = Content.find_by_id attrs[:parent_id]
      left = Content.find_by_id attrs[:left_id]
      if parent
        content.move_to_child_with_index parent, 0
      else
        content.move_to_root
      end
      content.move_to_right_of left if left
    end
    render :text => 'OK'
  end
  
  protected 

    def current_resource
      @content || @section
    end

    def set_menu
      @menu = Menus::Admin::Contents.new
    end

    def set_categories
      @categories = @section.categories.roots
    end

    def protect_single_content_mode
      if params[:action] == 'index' and @section.try(:single_article_mode)
        redirect_to @section.contents.empty? ?
          new_admin_article_url(@site, @section, :content => { :title => @section.title }) :
{'fraction_non_alphanumeric': 0.10596278009874667, 'fraction_numerical': 0.00037979491074819596, 'mean_word_length': 3.382695507487521, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '6717720', 'n_tokens_mistral': 821, 'n_tokens_neox': 802, 'n_words': 185}