caches comments
This commit is contained in:
@@ -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? %>
|
||||
•
|
||||
<span class="label round level-<%= comment.user.official_level %>">
|
||||
<%= comment.user.official_position %>
|
||||
</span>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if comment.user.verified_organization? %>
|
||||
•
|
||||
<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? %>
|
||||
•
|
||||
<span class="label round is-association">
|
||||
<%= t("shared.collective") %>
|
||||
</span>
|
||||
<% end %>
|
||||
<% if comment.user_id == @commentable.author_id %>
|
||||
•
|
||||
<span class="label round is-author">
|
||||
<%= t("debates.comment.author") %>
|
||||
</span>
|
||||
<% if comment.user_id == @commentable.author_id %>
|
||||
•
|
||||
<span class="label round is-author">
|
||||
<%= t("debates.comment.author") %>
|
||||
</span>
|
||||
<% end %>
|
||||
|
||||
<% end %>
|
||||
|
||||
• <%= 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>
|
||||
|
||||
• <%= 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"> | </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"> | </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>
|
||||
@@ -1,25 +1,28 @@
|
||||
<% css_id = parent_or_commentable_dom_id(parent_id, commentable) %>
|
||||
<div id="js-comment-form-<%= css_id %>" <%= "style='display:none'".html_safe if toggeable %>>
|
||||
<%= form_for [commentable, Comment.new], remote: true do |f| %>
|
||||
<%= label_tag "comment-body-#{css_id}", t("comments.form.leave_comment") %>
|
||||
<%= f.text_area :body, id: "comment-body-#{css_id}", label: false %>
|
||||
<%= f.hidden_field :commentable_type, value: commentable.class.name %>
|
||||
<%= f.hidden_field :commentable_id, value: commentable.id %>
|
||||
<%= f.hidden_field :parent_id, value: parent_id %>
|
||||
<% cache [locale_and_user_status, css_id] do %>
|
||||
<div id="js-comment-form-<%= css_id %>" <%= "style='display:none'".html_safe if toggeable %>>
|
||||
<%= form_for [commentable, Comment.new], remote: true do |f| %>
|
||||
<%= label_tag "comment-body-#{css_id}", t("comments.form.leave_comment") %>
|
||||
<%= f.text_area :body, id: "comment-body-#{css_id}", label: false %>
|
||||
<%= f.hidden_field :commentable_type, value: commentable.class.name %>
|
||||
<%= f.hidden_field :commentable_id, value: commentable.id %>
|
||||
<%= f.hidden_field :parent_id, value: parent_id %>
|
||||
|
||||
<%= f.submit comment_button_text(parent_id), class: "button radius small inline-block" %>
|
||||
<%= f.submit comment_button_text(parent_id), class: "button radius small inline-block" %>
|
||||
|
||||
<% if can? :comment_as_moderator, commentable %>º
|
||||
<div class="right">
|
||||
<%= f.check_box :as_moderator, id: "comment-as-moderator-#{css_id}", label: false %>
|
||||
<%= label_tag "comment-as-moderator-#{css_id}", t("comments.form.comment_as_moderator"), class: "checkbox" %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if can? :comment_as_administrator, commentable %>
|
||||
<div class="right">
|
||||
<%= f.check_box :as_administrator, id: "comment-as-administrator-#{css_id}",label: false %>
|
||||
<%= label_tag "comment-as-administrator-#{css_id}", t("comments.form.comment_as_admin"), class: "checkbox" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if can? :comment_as_moderator, commentable %>º
|
||||
<div class="right">
|
||||
<%= f.check_box :as_moderator, id: "comment-as-moderator-#{css_id}", label: false %>
|
||||
<%= label_tag "comment-as-moderator-#{css_id}", t("comments.form.comment_as_moderator"), class: "checkbox" %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if can? :comment_as_administrator, commentable %>
|
||||
<div class="right">
|
||||
<%= f.check_box :as_administrator, id: "comment-as-administrator-#{css_id}",label: false %>
|
||||
<%= label_tag "comment-as-administrator-#{css_id}", t("comments.form.comment_as_admin"), class: "checkbox" %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
30
app/views/debates/_comments.html.erb
Normal file
30
app/views/debates/_comments.html.erb
Normal file
@@ -0,0 +1,30 @@
|
||||
<% cache [locale_and_user_status, @all_visible_comments.map(&:cache_key), @debate.comments_count, @comment_flags.to_a] do %>
|
||||
<section class="row-full comments">
|
||||
<div class="row">
|
||||
<div id="comments" class="small-12 column">
|
||||
|
||||
<h2>
|
||||
<%= t("debates.show.comments_title") %>
|
||||
<span>(<%= @debate.comments_count %>)</span>
|
||||
</h2>
|
||||
|
||||
<% if user_signed_in? %>
|
||||
<%= render 'comments/form', {commentable: @debate, parent_id: nil, toggeable: false} %>
|
||||
<% else %>
|
||||
<br>
|
||||
|
||||
<div class="alert-box radius info">
|
||||
<%= t("debates.show.login_to_comment",
|
||||
signin: link_to(t("votes.signin"), new_user_session_path),
|
||||
signup: link_to(t("votes.signup"), new_user_registration_path)).html_safe %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% @root_comments.each do |comment| %>
|
||||
<%= render 'comments/comment', comment: comment %>
|
||||
<% end %>
|
||||
<%= paginate @root_comments %>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<% end %>
|
||||
Reference in New Issue
Block a user