list optimizations

This commit is contained in:
Andrew Brown 2018-09-24 17:27:16 -05:00
parent ad9c9963da
commit 4e7b1c8bf8
4 changed files with 35 additions and 10 deletions

View File

@ -22,8 +22,6 @@ class MainController < ApplicationController
def dashboard
return redirect_to new_user_session_path unless user_signed_in?
@content_types = @activated_content_types
set_random_content # for questions
end

View File

@ -2,7 +2,21 @@
content_type_name = content_type.to_s.titleize # "Character"
content_type_class = content_type_name.constantize # Character
content_type_pluralized = content_type_name.downcase.pluralize # characters
category_ids_for_this_content_type = AttributeCategory.where(entity_type: content_type_name.downcase, user_id: current_user).pluck(:id)
name_field = AttributeField.find_by(field_type: 'name', attribute_category_id: category_ids_for_this_content_type)
# todo description field
content_ids = content_list.pluck(:id)
list_name_lookup_cache = Hash[
name_field.attribute_values.where(
entity_type: content_type_name
).pluck(:entity_id, :value)
]
#raise list_name_lookup_cache.inspect
%>
<div class="card hoverable">
<div class="card-image">
<% images = ImageUpload.where(content_type: content_type_name, content_id: content_list.pluck(:id)) %>
@ -58,13 +72,13 @@
<table class="content-table bordered">
<tr>
<th>Name</th>
<th class="hide-on-small-only">Description</th>
<th class="hide-on-small-only"><!-- Description --></th>
<th></th>
</tr>
<% content_list.each do |content| %>
<tr>
<td><%= link_to content.name_field_value, polymorphic_path(content) %></td>
<td class="hide-on-small-only"><%= truncate(content.description, length: 200) %></td>
<td><%= link_to list_name_lookup_cache[content.id].presence || content.name, polymorphic_path(content) %></td>
<td class="hide-on-small-only"><%# truncate(content.description, length: 200) %></td>
<td>
<div class="secondary-content">
<%= link_to edit_polymorphic_path(content) do %>

View File

@ -1,5 +1,18 @@
<%# Usage: render partial: 'content/list/list', locals: { content_list: @content, content_type: @content_type_class, show_add_another_form: true } %>
<%
category_ids_for_this_content_type = AttributeCategory.where(entity_type: content_type.name.downcase, user_id: current_user).pluck(:id)
name_field = AttributeField.find_by(field_type: 'name', attribute_category_id: category_ids_for_this_content_type)
# todo description field
content_ids = content_list.pluck(:id)
list_name_lookup_cache = Hash[
name_field.attribute_values.where(
entity_type: content_type.name
).pluck(:entity_id, :value)
]
%>
<ul class="collection <%= 'with-header' if title.present? %>" style='border: 0'>
<% if title.present? %>
<li class="collection-header"><h5><%= title %></h5></li>
@ -11,7 +24,7 @@
<i class="material-icons circle <%= content.class.color %>"><%= content.class.icon %></i>
<% end %>
<span class="title">
<%= link_to (content.respond_to?(:label) ? content.label : content.name_field_value), content %>
<%= link_to (content.respond_to?(:label) ? content.label : list_name_lookup_cache[content.id].presence || content.name), content %>
<small class="grey-text">
<% universe_field_value = content.universe_field_value %>
<% if universe_field_value.present? %>
@ -23,7 +36,7 @@
end
%>
<% if universe_field_value %>
<%= link_to universe_field_value.try(:name_field_value), universe_field_value %>
<%= link_to universe_field_value.try(:name), universe_field_value %>
<% end %>
<% end %>
</small>
@ -37,7 +50,7 @@
<% end %>
</span>
<p class="content-description truncate">
<%= content.description %>
<%# content.description %>
</p>
<p class='grey-text'>
@ -58,7 +71,7 @@
<% end %>
</p>
<span class="secondary-content hide-on-med-and-up">
<% if user_signed_in? && content.user == current_user %>
<% if user_signed_in? && content.user_id == current_user.id %>
<%# todo also show if you're a contributor %>
<%= link_to edit_polymorphic_path(content), class: 'js-edit-hover' do %>
<i class="material-icons">edit</i>

View File

@ -21,7 +21,7 @@
<% if current_user %>
<li class="divider"></li>
<% (@current_user_content['Universe'] + current_user.contributable_universes).sort_by(&:name).each do |universe| %>
<li><%= link_to universe.name + (universe.user == current_user ? '' : ' (contributor)'), "?universe=#{universe.id}" %></li>
<li><%= link_to universe.name + (universe.user_id == current_user.id ? '' : ' (contributor)'), "?universe=#{universe.id}" %></li>
<% end %>
<% end %>
</ul>