<commit_before>module ResourceListItemHelper

  def get_list_item_content_partial resource
    get_original_model_name(resource).pluralize.underscore + "/resource_list_item"
  end

  def get_list_item_actions_partial resource
    if resource.authorization_supported? && resource.is_downloadable_asset?
      actions_partial = "assets/resource_actions_td"
    else
      actions_partial = nil
    end
    actions_partial
  end

  def get_list_item_avatar_partial resource
    if resource.show_contributor_avatars?
      "assets/asset_avatars"
    elsif resource.class.name.downcase=="event"
      ""
    else
      "layouts/avatars"
    end
  end

  def list_item_title resource, options={}
    title=options[:title]
    url=options[:url]
    include_avatar=options[:include_avatar]
    include_avatar=true if include_avatar.nil?

    if title.nil?
      title = get_object_title(resource)
    end

    html = "<div class=\"list_item_title\">"

    if resource.class.name.split("::")[0] == "Person"
      icons = seek_role_icons(resource)
      html << "<p>#{link_to title, (url.nil? ? show_resource_path(resource) : url)} #{icons}</p>"
    else
      if include_avatar && (resource.avatar_key || resource.use_mime_type_for_avatar?)
        image=resource_avatar resource,:style=>"width: 24px; height: 24px; vertical-align: middle"

        icon  = link_to_draggable(image, show_resource_path(resource), :id=>model_to_drag_id(resource), :class=> "asset", :title=>tooltip_title_attrib(get_object_title(resource)))

        html << "<p style=\"float:left;width:95%;\">#{icon} #{link_to title, (url.nil? ? show_resource_path(resource) : url)}</p>"
        html << list_item_visibility(resource.policy) if resource.authorization_supported? && resource.can_manage?
        html << "<br style=\"clear:both\"/>"
      else
        html << "<p>#{link_to title, (url.nil? ? show_resource_path(resource) : url)}</p>"
      end
    end
    html << "</div>"
  end

  def list_item_tag_list resource
    list_item_simple_list(resource.annotations.collect{|a| a.value}, "Tags") {|i| link_for_ann(i)}
  end

  def list_item_simple_list items, attribute
    html = "<p class=\"list_item_attribute\"><b>#{attribute}:</b> "
    if items.empty?
      html << "<span class='none_text'>Not specified</span>"<commit_msg>cache resource list item title<commit_after>module ResourceListItemHelper

  def get_list_item_content_partial resource
    get_original_model_name(resource).pluralize.underscore + "/resource_list_item"
  end

  def get_list_item_actions_partial resource
    if resource.authorization_supported? && resource.is_downloadable_asset?
      actions_partial = "assets/resource_actions_td"
    else
      actions_partial = nil
    end
    actions_partial
  end

  def get_list_item_avatar_partial resource
    if resource.show_contributor_avatars?
      "assets/asset_avatars"
    elsif resource.class.name.downcase=="event"
      ""
    else
      "layouts/avatars"
    end
  end

  def list_item_title resource, options={}
    cache_key = "rli_title_#{resource.cache_key}_#{resource.authorization_supported? && resource.can_manage?}"
    result = Rails.cache.fetch(cache_key) do
      title=options[:title]
      url=options[:url]
      include_avatar=options[:include_avatar]
      include_avatar=true if include_avatar.nil?

      if title.nil?
        title = get_object_title(resource)
      end

      html = "<div class=\"list_item_title\">"

      if resource.class.name.split("::")[0] == "Person"
        icons = seek_role_icons(resource)
        html << "<p>#{link_to title, (url.nil? ? show_resource_path(resource) : url)} #{icons}</p>"
      else
        if include_avatar && (resource.avatar_key || resource.use_mime_type_for_avatar?)
          image=resource_avatar resource,:style=>"width: 24px; height: 24px; vertical-align: middle"

          icon  = link_to_draggable(image, show_resource_path(resource), :id=>model_to_drag_id(resource), :class=> "asset", :title=>tooltip_title_attrib(get_object_title(resource)))

          html << "<p style=\"float:left;width:95%;\">#{icon} #{link_to title, (url.nil? ? show_resource_path(resource) : url)}</p>"
          html << "#item_visibility"
          html << "<br style=\"clear:both\"/>"
        else
          html << "<p>#{link_to title, (url.nil? ? show_resource_path(resource) : url)}</p>"
        end
      end
      html << "</div>"
    end
    visibility = resource.authorization_supported? && resource.can_manage? ? list_item_visibility(resource.policy) : ""
    result = result.gsub("#item_visibility",visibility)
    result
  end

  def list_item_tag_list resource
    list_item_simple_list(resource.annotations.collect{|a| a.value}, "Tags") {|i| link_for_ann(i)}
  end

  def list_item_simple_list items, attribute
    html = "<p class=\"list_item_attribute\"><b>#{attribute}:</b> "
    if items.empty?
      html << "<span class='none_text'>Not specified</span>"
{'fraction_non_alphanumeric': 0.1296672077922078, 'fraction_numerical': 0.002840909090909091, 'mean_word_length': 3.9191616766467066, 'pattern_counts': {'":': 2, '<': 59, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4215523', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1570, 'n_words': 280}