caches comments

This commit is contained in:
rgarcia
2015-09-05 21:54:14 +02:00
parent 93378eea98
commit 5200d76be6
3 changed files with 141 additions and 105 deletions

View File

@@ -1,101 +1,104 @@
<div class="row">
<div id="<%= dom_id(comment) %>" class="comment small-12 column">
<% cache [locale_and_user_status, comment, @commentable, Flag.flagged?(current_user, comment)] do %>
<div class="row">
<div id="<%= dom_id(comment) %>" class="comment small-12 column">
<% if comment.hidden? || comment.user.hidden? %>
<% if select_children(@comments, comment).size > 0 %>
<div class="is-deleted">
<p><%= t("debates.comment.deleted") %></p>
</div>
<% end %>
<% else %>
<% if comment.as_administrator? %>
<%= image_tag("admin_avatar.png", size: 32, class: "admin-avatar left") %>
<% elsif comment.as_moderator? %>
<%= image_tag("moderator_avatar.png", size: 32, class: "moderator-avatar left") %>
<% if comment.hidden? || comment.user.hidden? %>
<% if select_children(@comments, comment).size > 0 %>
<div class="is-deleted">
<p><%= t("debates.comment.deleted") %></p>
</div>
<% end %>
<% else %>
<% if comment.user.organization? %>
<%= image_tag("collective_avatar.png", size: 32, class: "avatar left") %>
<% if comment.as_administrator? %>
<%= image_tag("admin_avatar.png", size: 32, class: "admin-avatar left") %>
<% elsif comment.as_moderator? %>
<%= image_tag("moderator_avatar.png", size: 32, class: "moderator-avatar left") %>
<% else %>
<%= avatar_image(comment.user, seed: comment.user_id, size: 32, class: "left") %>
<% end %>
<% if comment.user.hidden? %>
<i class="icon-deleted user-deleted"></i>
<% end %>
<% end %>
<div class="comment-body">
<div class="comment-info">
<% if comment.as_administrator? %>
<span class="user-name"><%= t("debates.comment.admin") %> #<%= comment.administrator_id%></span>
<% elsif comment.as_moderator? %>
<span class="user-name"><%= t("debates.comment.moderator") %> #<%= comment.moderator_id%></span>
<% if comment.user.organization? %>
<%= image_tag("collective_avatar.png", size: 32, class: "avatar left") %>
<% else %>
<%= avatar_image(comment.user, seed: comment.user_id, size: 32, class: "left") %>
<% end %>
<% if comment.user.hidden? %>
<i class="icon-deleted user-deleted"></i>
<% end %>
<% end %>
<% if comment.user.hidden? %>
<span class="user-name"><%= t("debates.comment.user_deleted") %></span>
<div class="comment-body">
<div class="comment-info">
<% if comment.as_administrator? %>
<span class="user-name"><%= t("debates.comment.admin") %> #<%= comment.administrator_id%></span>
<% elsif comment.as_moderator? %>
<span class="user-name"><%= t("debates.comment.moderator") %> #<%= comment.moderator_id%></span>
<% else %>
<span class="user-name"><%= comment.user.name %></span>
<% if comment.user.official? %>
<% if comment.user.hidden? %>
<span class="user-name"><%= t("debates.comment.user_deleted") %></span>
<% else %>
<span class="user-name"><%= comment.user.name %></span>
<% if comment.user.official? %>
&nbsp;&bullet;&nbsp;
<span class="label round level-<%= comment.user.official_level %>">
<%= comment.user.official_position %>
</span>
<% end %>
<% end %>
<% if comment.user.verified_organization? %>
&nbsp;&bullet;&nbsp;
<span class="label round level-<%= comment.user.official_level %>">
<%= comment.user.official_position %>
<span class="label round is-association">
<%= t("shared.collective") %>
</span>
<% end %>
<% end %>
<% if comment.user.verified_organization? %>
&nbsp;&bullet;&nbsp;
<span class="label round is-association">
<%= t("shared.collective") %>
</span>
<% end %>
<% if comment.user_id == @commentable.author_id %>
&nbsp;&bullet;&nbsp;
<span class="label round is-author">
<%= t("debates.comment.author") %>
</span>
<% if comment.user_id == @commentable.author_id %>
&nbsp;&bullet;&nbsp;
<span class="label round is-author">
<%= t("debates.comment.author") %>
</span>
<% end %>
<% end %>
&nbsp;&bullet;&nbsp;<%= time_ago_in_words(comment.created_at) %>
</div>
<% if comment.as_administrator? %>
<p class="comment-user is-admin"><%= comment.body %></p>
<% elsif comment.as_moderator? %>
<p class="comment-user is-moderator"><%= comment.body %></p>
<% elsif comment.user.official? && comment.user_id == @commentable.author_id %>
<p class="comment-user level-<%= comment.user.official_level %> is-author"><%= comment.body %></p>
<% elsif comment.user.official? %>
<p class="comment-user level-<%= comment.user.official_level %>"><%= comment.body %></p>
<% elsif comment.user_id == @commentable.author_id %>
<p class="comment-user is-author"><%= comment.body %></p>
<% else %>
<p class="comment-user"><%= comment.body %></p>
<% end %>
<span id="<%= dom_id(comment) %>_votes" class="comment-votes right">
<%= render 'comments/votes', comment: comment %>
</span>
&nbsp;&bullet;&nbsp;<%= time_ago_in_words(comment.created_at) %>
<div class="reply">
<%= t("debates.comment.responses", count: select_children(@comments, comment).size) %>
<% if user_signed_in? %>
<span class="divider">&nbsp;|&nbsp;</span>
<%= link_to(comment_link_text(comment), "",
class: "js-add-comment-link", data: {'id': dom_id(comment)}) %>
<%= render 'comments/actions', comment: comment %>
<%= render 'comments/form', {commentable: @commentable, parent_id: comment.id, toggeable: true} %>
<% end %>
</div>
</div>
<% if comment.as_administrator? %>
<p class="comment-user is-admin"><%= comment.body %></p>
<% elsif comment.as_moderator? %>
<p class="comment-user is-moderator"><%= comment.body %></p>
<% elsif comment.user.official? && comment.user_id == @commentable.author_id %>
<p class="comment-user level-<%= comment.user.official_level %> is-author"><%= comment.body %></p>
<% elsif comment.user.official? %>
<p class="comment-user level-<%= comment.user.official_level %>"><%= comment.body %></p>
<% elsif comment.user_id == @commentable.author_id %>
<p class="comment-user is-author"><%= comment.body %></p>
<% else %>
<p class="comment-user"><%= comment.body %></p>
<% end %>
<span id="<%= dom_id(comment) %>_votes" class="comment-votes right">
<%= render 'comments/votes', comment: comment %>
</span>
<div class="reply">
<%= t("debates.comment.responses", count: select_children(@comments, comment).size) %>
<% if user_signed_in? %>
<span class="divider">&nbsp;|&nbsp;</span>
<%= link_to(comment_link_text(comment), "",
class: "js-add-comment-link", data: {'id': dom_id(comment)}) %>
<%= render 'comments/actions', comment: comment %>
<%= render 'comments/form', {commentable: @commentable, parent_id: comment.id, toggeable: true} %>
<% end %>
</div>
</div>
<% end %>
<% end %>
<% end %>
<div class="comment-children">
<%= render select_children(@comments, comment) if @comments.present? %>
<% select_children(@comments, comment).each do |child| %>
<%= render 'comments/comment', comment: child %>
<% end %>
</div>
</div>
</div>
</div>