Only show activated content types on user dashboards

This commit is contained in:
Andrew Brown 2017-12-27 20:20:17 -06:00
parent 349039c343
commit 9600a6fb32
2 changed files with 7 additions and 6 deletions

View File

@ -22,6 +22,8 @@ class MainController < ApplicationController
def dashboard
return redirect_to new_user_session_path unless user_signed_in?
@content_types = current_user.user_content_type_activators.pluck(:content_type)
ask_question
end

View File

@ -26,24 +26,23 @@
%>
<div class="row">
<% [:universe, :character, :location, :item, :creature, :race, :religion, :group, :magic, :language, :flora, :scene].each do |type| %>
<% @content_types.reverse.each do |content_type| %>
<%
pluralized_content_name = type.to_s.pluralize
pluralized_content_name = content_type.downcase.pluralize
if @universe_scope.present? && type != :universe
if @universe_scope.present? && content_type != 'Universe'
content_list = @universe_scope.send(pluralized_content_name)
else
content_list = current_user.send(pluralized_content_name) + current_user.send("contributable_#{pluralized_content_name}")
unless type == :universe
unless content_type == 'Universe'
content_list.concat(current_user.universes.flat_map { |universe| universe.send(pluralized_content_name) }).uniq!
end
end
%>
<% next if !current_user.can_create?(type.to_s.capitalize.constantize) && content_list.empty? %>
<div class="dashboard-row col <%= "s#{s_width} m#{m_width} l#{l_width}" %>">
<%= render partial: 'content/cards/in_universe_content_list', locals: { content_type: type, content_list: content_list } %>
<%= render partial: 'content/cards/in_universe_content_list', locals: { content_type: content_type.downcase, content_list: content_list } %>
</div>
<% end %>
</div>