indentlabs/notebook

View on GitHub
app/views/content/display/attribute_value/_link.html.erb

Summary

Maintainability
Test Coverage
<% value.each do |link_code| %>
  <%
    klass, id = link_code.split('-')
  %>

  <%#
    In most cases, a user will be seeing their own content most of the time.
    This allows us to primarily rely on @current_user_content but fall back
    on js-load-page-name to fetch & load in post-page-load if the content isn't ours.
  %>
  <%
    content = if user_signed_in?
      @current_user_content.fetch(klass, []).detect do |page|
        page.page_type === klass && page.id === id.to_i
      end
    else
      nil
    end
  %>

  <%# TODO: we should extract chips out into a react component, probably %>
  <div class="chip <%= 'js-load-page-name' if content.nil? %>" 
       data-klass="<%= klass %>" 
       data-id="<%= id %>"
  >
    <%= link_to send("#{klass.downcase}_path", id) do %>
      <span class="<%= content_class_from_name(klass).text_color %>">
        <i class="material-icons left">
          <%= content_class_from_name(klass).icon %>
        </i>
      </span>
      <span class="name-container">
        <%= content.try(:name) || "<em>Loading #{klass}</em>".html_safe %>
      </span>
    <% end %>
  </div>
<% end %>
<br/><br/>