From 4e7b1c8bf8094db04ecc66051dbd78860979167e Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Mon, 24 Sep 2018 17:27:16 -0500 Subject: [PATCH] list optimizations --- app/controllers/main_controller.rb | 2 -- .../cards/_in_universe_content_list.html.erb | 20 +++++++++++++++--- app/views/content/list/_list.html.erb | 21 +++++++++++++++---- app/views/universes/_picker.html.erb | 2 +- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index 32994c9e..09ca3920 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -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 diff --git a/app/views/content/cards/_in_universe_content_list.html.erb b/app/views/content/cards/_in_universe_content_list.html.erb index 30641b41..9f16bdd9 100644 --- a/app/views/content/cards/_in_universe_content_list.html.erb +++ b/app/views/content/cards/_in_universe_content_list.html.erb @@ -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 %> +
<% images = ImageUpload.where(content_type: content_type_name, content_id: content_list.pluck(:id)) %> @@ -58,13 +72,13 @@ - + <% content_list.each do |content| %> - - + +
NameDescription
<%= link_to content.name_field_value, polymorphic_path(content) %><%= truncate(content.description, length: 200) %><%= link_to list_name_lookup_cache[content.id].presence || content.name, polymorphic_path(content) %><%# truncate(content.description, length: 200) %>
<%= link_to edit_polymorphic_path(content) do %> diff --git a/app/views/content/list/_list.html.erb b/app/views/content/list/_list.html.erb index d5dbcaea..9d9e2676 100644 --- a/app/views/content/list/_list.html.erb +++ b/app/views/content/list/_list.html.erb @@ -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) + ] +%> +
    <% if title.present? %>
  • <%= title %>
  • @@ -11,7 +24,7 @@ <%= content.class.icon %> <% end %> - <%= 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 %> <% 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 %> @@ -37,7 +50,7 @@ <% end %>

    - <%= content.description %> + <%# content.description %>

    @@ -58,7 +71,7 @@ <% end %>

    - <% 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 %> edit diff --git a/app/views/universes/_picker.html.erb b/app/views/universes/_picker.html.erb index 2eea8bb2..b4040db4 100644 --- a/app/views/universes/_picker.html.erb +++ b/app/views/universes/_picker.html.erb @@ -21,7 +21,7 @@ <% if current_user %>
  • <% (@current_user_content['Universe'] + current_user.contributable_universes).sort_by(&:name).each do |universe| %> -
  • <%= link_to universe.name + (universe.user == current_user ? '' : ' (contributor)'), "?universe=#{universe.id}" %>
  • +
  • <%= link_to universe.name + (universe.user_id == current_user.id ? '' : ' (contributor)'), "?universe=#{universe.id}" %>
  • <% end %> <% end %>