Item context aggregates

This commit is contained in:
Andrew Brown 2017-03-26 17:09:05 +01:00
parent e25329cb82
commit f37639aed4
2 changed files with 44 additions and 31 deletions

View File

@ -1,6 +1,8 @@
<%=
<%#
# TODO: Reflect on content_type to pull `relates` relations instead of hard-coding each here.
%>
<%=
render partial: 'content/contexts/relation', locals: {
content_type: Location,
content: content,

View File

@ -1,35 +1,32 @@
<% religions = Artifactship.where(artifact_id: content.id).map(&:religion).select { |content| content.readable_by?(current_user || User.new) } %>
<% if religions.any? %>
<div class="col s12 m6 l4">
<%= render partial: 'content/cards/in_universe_content_list', locals: {
content_type: :religion,
content_list: religions,
card_title: "Artifact of #{pluralize(religions.count, 'religion')}"
} %>
</div>
<% end %>
<%=
render partial: 'content/contexts/relation', locals: {
content_type: Religion,
content: content,
relation_class: Artifactship,
relation_class_id: :artifact_id,
relation_text: :artifact_of
}
%>
<% groups = GroupEquipmentship.where(equipment_id: content.id).map(&:group).select { |content| content.readable_by?(current_user || User.new) } %>
<% if groups.any? %>
<div class="col s12 m6 l4">
<%= render partial: 'content/cards/in_universe_content_list', locals: {
content_type: :group,
content_list: groups,
card_title: "Equipment for #{pluralize(groups.count, 'group')}"
} %>
</div>
<% end %>
<%=
render partial: 'content/contexts/relation', locals: {
content_type: Group,
content: content,
relation_class: GroupEquipmentship,
relation_class_id: :equipment_id,
relation_text: :equipment_for
}
%>
<% groups = KeyItemship.where(key_item_id: content.id).map(&:group).select { |content| content.readable_by?(current_user || User.new) } %>
<% if groups.any? %>
<div class="col s12 m6 l4">
<%= render partial: 'content/cards/in_universe_content_list', locals: {
content_type: :group,
content_list: groups,
card_title: "Key item for #{pluralize(groups.count, 'group')}"
} %>
</div>
<% end %>
<%=
render partial: 'content/contexts/relation', locals: {
content_type: Group,
content: content,
relation_class: KeyItemship,
relation_class_id: :key_item_id,
relation_text: :key_item_for
}
%>
<% scenes = SceneItemship.where(scene_item_id: content.id).map(&:scene).select { |content| content.readable_by?(current_user || User.new) } %>
<% if scenes.any? %>
@ -40,4 +37,18 @@
card_title: "Appears in #{pluralize(scenes.count, 'scene')}"
} %>
</div>
<% end %>
<% @references.each do |content_type, relations| %>
<% next unless relations.any? %>
<div class="col s12 m6 l4">
<%= render partial: 'content/cards/content_relation_list', locals: {
content_type: content_type,
relations: relations,
card_title: [
'Related to ',
pluralize(relations.count, "other #{content_type.to_s.singularize}")
].join
} %>
</div>
<% end %>