<commit_before>##
## PAGE FORM HELPERS
##

module Common::Page::FormHelper

  protected

  def display_page_class_grouping(group)
    I18n.t("page_group_#{group.gsub(':','_')}".to_sym)
  end

  #
  # The various page types form a hierarchy.
  # golly, this seems overly complicated.
  #
  # produces a structure that looks like this:
  # [{:pages => [classproxy, classproxy], :display => "Multimedia", :name => "media", :url => "media"},{..}]
  #
  #
  def tree_of_page_types(options={})
    if @group
      available_page_classes = current_site.tools_for(@group)
    else
      available_page_classes = current_site.available_page_types
    end
    page_groupings = []
    available_page_classes.each do |page_class_string|
      page_class = Page.class_name_to_class(page_class_string)
      next if page_class.nil? or page_class.internal or page_class.forbid_new
      if options[:simple]
        page_groupings << page_class.class_group.to_a.first
      else
        page_groupings.concat page_class.class_group
      end
    end
    page_groupings.uniq!
    tree = []
    page_groupings.each do |grouping|
      entry = {:name => grouping, :display => display_page_class_grouping(grouping),
         :url => grouping.gsub(':','-')}
      entry[:pages] = Page.class_group_to_class(grouping).select{ |page_klass|
       !page_klass.internal && available_page_classes.include?(page_klass.full_class_name)
      }.sort_by{|page_klass| page_klass.order }
      tree << entry
    end
    return tree.sort_by{|entry| Crabgrass::Page::ClassProxy::ORDER.index(entry[:name])||100 }
  end

  #
  # options for a page type dropdown menu for searching
  #
  #def options_for_select_page_type(default_selected=nil)
  #  default_selected.sub!(' ', '+') if default_selected
  #  menu_items = []
  #  tree_of_page_types.each do |grouping|
  #    menu_items << [grouping[:display], grouping[:url]]
  #    sub_items = grouping[:pages].collect do |page_class|
  #       ["#{grouping[:display]} > #{page_class.class_display_name}",
  #       "#{grouping[:url]}+#{page_class.url}"]
  #     end
  #     menu_items.concat sub_items if sub_items.size > 1
  #  end
  #  options_for_select([['all page types'.t,'']] + menu_items, default_selected)
  #end

  #
  # options for a page type dropdown menu for searching
  # (this one does not list the types in a tree)
  #
  def options_for_select_page_type(default_selected='')
    available_types = current_site.available_page_types
    menu_items = []<commit_msg>Finish to prevent adding of pages where the page type has forbid_new set to true.<commit_after>##
## PAGE FORM HELPERS
##

module Common::Page::FormHelper

  protected

  def display_page_class_grouping(group)
    I18n.t("page_group_#{group.gsub(':','_')}".to_sym)
  end

  #
  # The various page types form a hierarchy.
  # golly, this seems overly complicated.
  #
  # produces a structure that looks like this:
  # [{:pages => [classproxy, classproxy], :display => "Multimedia", :name => "media", :url => "media"},{..}]
  #
  #
  def tree_of_page_types(options={})
    if @group
      available_page_classes = current_site.tools_for(@group)
    else
      available_page_classes = current_site.available_page_types
    end
    page_groupings = []
    available_page_classes.each do |page_class_string|
      page_class = Page.class_name_to_class(page_class_string)
      next if page_class.nil? or page_class.internal or page_class.forbid_new
      if options[:simple]
        page_groupings << page_class.class_group.to_a.first
      else
        page_groupings.concat page_class.class_group
      end
    end
    page_groupings.uniq!
    tree = []
    page_groupings.each do |grouping|
      entry = {:name => grouping, :display => display_page_class_grouping(grouping),
         :url => grouping.gsub(':','-')}
      entry[:pages] = Page.class_group_to_class(grouping).select{ |page_klass|
       !page_klass.internal && !page_klass.forbid_new && available_page_classes.include?(page_klass.full_class_name)
      }.sort_by{|page_klass| page_klass.order }
      tree << entry
    end
    return tree.sort_by{|entry| Crabgrass::Page::ClassProxy::ORDER.index(entry[:name])||100 }
  end

  #
  # options for a page type dropdown menu for searching
  #
  #def options_for_select_page_type(default_selected=nil)
  #  default_selected.sub!(' ', '+') if default_selected
  #  menu_items = []
  #  tree_of_page_types.each do |grouping|
  #    menu_items << [grouping[:display], grouping[:url]]
  #    sub_items = grouping[:pages].collect do |page_class|
  #       ["#{grouping[:display]} > #{page_class.class_display_name}",
  #       "#{grouping[:url]}+#{page_class.url}"]
  #     end
  #     menu_items.concat sub_items if sub_items.size > 1
  #  end
  #  options_for_select([['all page types'.t,'']] + menu_items, default_selected)
  #end

  #
  # options for a page type dropdown menu for searching
  # (this one does not list the types in a tree)
  #
  def options_for_select_page_type(default_selected='')
    available_types = current_site.available_page_types
    menu_items = []
{'fraction_non_alphanumeric': 0.12396531336223887, 'fraction_numerical': 0.002364998029168309, 'mean_word_length': 3.7742238946378177, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, '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': '4653918', 'n_tokens_mistral': 1711, 'n_tokens_neox': 1681, 'n_words': 339}