<commit_before>module Noodall
  module Admin
    module NodesHelper
      include Noodall::Permalinks
      include Noodall::NodesHelper
      include AssetsHelper

      def admin_breadcrumb
        breadcrumbs = breadcrumb_for(
                        @parent,
                        :node_path => :noodall_admin_node_nodes_path,
                        :home_link => content_tag('li', link_to('Contents', noodall_admin_nodes_path))
                      )
        content_tag('ul', breadcrumbs.join.html_safe, :class => 'breadcrumb') if breadcrumbs
      end

      def sorted_node_tree(tree)
        nodes = []
        tree.each do |node|
          nodes << node
          unless node.children.empty?
            nodes += sorted_node_tree(node.children)
          end
        end

        nodes
      end

      def formatted_node_tree_options
        sorted_node_tree(Node.roots).reject{|n| n._id == @node._id}.collect{|n|
          [n.title, n._id]
        }
      end

      def slot_link(node,type,index)
        link_to( "#{type.to_s.titleize} Slot", "##{type}_component_form_#{index}", :id=> "#{type}_slot_#{index}_selector", :class => 'slot_link') +
          "<span id=\"#{type}_slot_#{index}_tag\" class=\"slot_tag\">#{node.send("#{type}_slot_#{index}").class.model_name.human.titleize unless @node.send("#{type}_slot_#{index}").nil?}</span>".html_safe
      end

      def slot_form(node,type,index)
        component = @node.send("#{type}_slot_#{index}")
        options = options_for_select([''] + component_options(type), (component.class.name.titleize unless component.nil?))

        render :partial => 'slot_form', :locals => { :type => type, :index => index, :component => component, :options => options, :slot_name => "#{ type }_slot_#{ index }" }
      end

      def component_options(type)
        Component.positions_classes(type).map do |component|
          [component.model_name.human.titleize, component.name.titleize]
        end
      end

      def can_change_templates?(node)
        can_publish?(node) and !node.is_a?(Home) and (node.parent.nil? ? Node.template_names : node.parent.class.template_names).length > 1
      end

      def updater_name(node)
        begin
          node.updater.full_name if node.updater
        rescue
          logger.warn 'Unable to resolve updater name: ' +  $!.message
          'Unknown'
        end
      end

      def popular_tags(limit = 10)
        Noodall::Node.tag_cloud(:limit => limit).map do |tagging|
          link_to tagging.name, '#node_keywords', :class => "count#{tagging.count}"
        end.join(', ').html_safe
      end

      def admin_nodes_column_headings
        html = Array.new
        html << sortable_table_header(:name => "Name", :sort => "admin_title", :class => 'sort')
        html << sortable_table_header(:name => "Type", :sort => "_type", :class => 'sort')

        # Change 'position' header if we are sorting by position
        if(params[:sort] && params[:sort] != "position" || params[:order] == "descending")
          html << sortable_table_header(:name => "Position", :sort => "position", :class => 'sort')<commit_msg>prevent template changing on sitemap nodes/pages<commit_after>module Noodall
  module Admin
    module NodesHelper
      include Noodall::Permalinks
      include Noodall::NodesHelper
      include AssetsHelper

      def admin_breadcrumb
        breadcrumbs = breadcrumb_for(
                        @parent,
                        :node_path => :noodall_admin_node_nodes_path,
                        :home_link => content_tag('li', link_to('Contents', noodall_admin_nodes_path))
                      )
        content_tag('ul', breadcrumbs.join.html_safe, :class => 'breadcrumb') if breadcrumbs
      end

      def sorted_node_tree(tree)
        nodes = []
        tree.each do |node|
          nodes << node
          unless node.children.empty?
            nodes += sorted_node_tree(node.children)
          end
        end

        nodes
      end

      def formatted_node_tree_options
        sorted_node_tree(Node.roots).reject{|n| n._id == @node._id}.collect{|n|
          [n.title, n._id]
        }
      end

      def slot_link(node,type,index)
        link_to( "#{type.to_s.titleize} Slot", "##{type}_component_form_#{index}", :id=> "#{type}_slot_#{index}_selector", :class => 'slot_link') +
          "<span id=\"#{type}_slot_#{index}_tag\" class=\"slot_tag\">#{node.send("#{type}_slot_#{index}").class.model_name.human.titleize unless @node.send("#{type}_slot_#{index}").nil?}</span>".html_safe
      end

      def slot_form(node,type,index)
        component = @node.send("#{type}_slot_#{index}")
        options = options_for_select([''] + component_options(type), (component.class.name.titleize unless component.nil?))

        render :partial => 'slot_form', :locals => { :type => type, :index => index, :component => component, :options => options, :slot_name => "#{ type }_slot_#{ index }" }
      end

      def component_options(type)
        Component.positions_classes(type).map do |component|
          [component.model_name.human.titleize, component.name.titleize]
        end
      end

      def can_change_templates?(node)
        can_publish?(node)       \
        and !node.is_a?(Home)    \
        and !node.in_site_map?   \
        and (node.parent.nil? ? Node.template_names : node.parent.class.template_names).length > 1
      end

      def updater_name(node)
        begin
          node.updater.full_name if node.updater
        rescue
          logger.warn 'Unable to resolve updater name: ' +  $!.message
          'Unknown'
        end
      end

      def popular_tags(limit = 10)
        Noodall::Node.tag_cloud(:limit => limit).map do |tagging|
          link_to tagging.name, '#node_keywords', :class => "count#{tagging.count}"
        end.join(', ').html_safe
      end

      def admin_nodes_column_headings
        html = Array.new
        html << sortable_table_header(:name => "Name", :sort => "admin_title", :class => 'sort')
        html << sortable_table_header(:name => "Type", :sort => "_type", :class => 'sort')

        # Change 'position' header if we are sorting by position
        if(params[:sort] && params[:sort] != "position" || params[:order] == "descending")
          html << sortable_table_header(:name => "Position", :sort => "position", :class => 'sort')
{'fraction_non_alphanumeric': 0.13850023581197926, 'fraction_numerical': 0.0009432479169941833, 'mean_word_length': 2.5601566871852266, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 55, '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': '239098', 'n_tokens_mistral': 1944, 'n_tokens_neox': 1929, 'n_words': 382}