adds comment show view
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
class CommentsController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
before_action :authenticate_user!, only: :create
|
||||
before_action :load_commentable, only: :create
|
||||
before_action :build_comment, only: :create
|
||||
|
||||
@@ -14,6 +14,11 @@ class CommentsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@comment = Comment.find(params[:id])
|
||||
set_comment_flags(@comment.subtree)
|
||||
end
|
||||
|
||||
def vote
|
||||
@comment.vote_by(voter: current_user, vote: params[:value])
|
||||
respond_with @comment
|
||||
|
||||
@@ -13,8 +13,11 @@ module CommentsHelper
|
||||
end
|
||||
|
||||
def child_comments_of(parent)
|
||||
return [] unless @comment_tree
|
||||
@comment_tree.children_of(parent)
|
||||
if @comment_tree.present?
|
||||
@comment_tree.ordered_children_of(parent)
|
||||
else
|
||||
parent.children
|
||||
end
|
||||
end
|
||||
|
||||
def user_level_class(comment)
|
||||
|
||||
@@ -5,6 +5,7 @@ module Abilities
|
||||
def initialize(user)
|
||||
can :read, Debate
|
||||
can :read, Proposal
|
||||
can :read, Comment
|
||||
can :read, Legislation
|
||||
can :read, User
|
||||
can [:search, :read], Annotation
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<% cache [locale_and_user_status(comment), comment, commentable_cache_key(@commentable), comment.author, (@comment_flags[comment.id] if @comment_flags)] do %>
|
||||
<% cache [locale_and_user_status(comment), comment, commentable_cache_key(comment.commentable), comment.author, (@comment_flags[comment.id] if @comment_flags)] do %>
|
||||
<div class="row">
|
||||
<div id="<%= dom_id(comment) %>" class="comment small-12 column">
|
||||
|
||||
<% if comment.hidden? || comment.user.hidden? %>
|
||||
<% if child_comments_of(comment).size > 0 %>
|
||||
<% if comment.children.size > 0 %>
|
||||
<div class="is-deleted">
|
||||
<p><%= t("comments.comment.deleted") %></p>
|
||||
</div>
|
||||
@@ -49,7 +49,7 @@
|
||||
<%= t("shared.collective") %>
|
||||
</span>
|
||||
<% end %>
|
||||
<% if comment.user_id == @commentable.author_id %>
|
||||
<% if comment.user_id == comment.commentable.author_id %>
|
||||
•
|
||||
<span class="label round is-author">
|
||||
<%= t("comments.comment.author") %>
|
||||
@@ -63,7 +63,7 @@
|
||||
|
||||
<div class="comment-user
|
||||
<%= user_level_class comment %>
|
||||
<%= comment_author_class comment, @commentable.author_id %>">
|
||||
<%= comment_author_class comment, comment.commentable.author_id %>">
|
||||
<%= simple_format text_with_links comment.body %>
|
||||
</div>
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
</span>
|
||||
|
||||
<div class="reply">
|
||||
<%= t("comments.comment.responses", count: child_comments_of(comment).size) %>
|
||||
<%= t("comments.comment.responses", count: comment.children.size) %>
|
||||
|
||||
<% if user_signed_in? %>
|
||||
<span class="divider"> | </span>
|
||||
@@ -81,11 +81,12 @@
|
||||
|
||||
<%= render 'comments/actions', comment: comment %>
|
||||
|
||||
<%= render 'comments/form', {commentable: @commentable, parent_id: comment.id, toggeable: true} %>
|
||||
<%= render 'comments/form', {commentable: comment.commentable, parent_id: comment.id, toggeable: true} %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="comment-children">
|
||||
<% child_comments_of(comment).each do |child| %>
|
||||
<%= render 'comments/comment', comment: child %>
|
||||
|
||||
12
app/views/comments/show.html.erb
Normal file
12
app/views/comments/show.html.erb
Normal file
@@ -0,0 +1,12 @@
|
||||
<div>
|
||||
<%= link_to t("comments.show.return_to_commentable") + @comment.commentable.title,
|
||||
@comment.commentable %>
|
||||
</div>
|
||||
|
||||
<section class="row-full comments">
|
||||
<div class="row">
|
||||
<div id="comments" class="small-12 column">
|
||||
<%= render @comment %>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
Reference in New Issue
Block a user