Merge branch 'master' into notifications
This commit is contained in:
@@ -1645,7 +1645,6 @@ table {
|
|||||||
font-family: $font-sans;
|
font-family: $font-sans;
|
||||||
font-size: $small-font-size;
|
font-size: $small-font-size;
|
||||||
line-height: $line-height;
|
line-height: $line-height;
|
||||||
margin: rem-calc(10) $line-height/2 $line-height/4 0;
|
|
||||||
|
|
||||||
a {
|
a {
|
||||||
color: $text-light;
|
color: $text-light;
|
||||||
@@ -1666,15 +1665,12 @@ table {
|
|||||||
.comment-body {
|
.comment-body {
|
||||||
margin-left: rem-calc(42);
|
margin-left: rem-calc(42);
|
||||||
|
|
||||||
p {
|
|
||||||
font-size: $small-font-size;
|
|
||||||
}
|
|
||||||
|
|
||||||
.reply {
|
.reply {
|
||||||
background: white;
|
background: white;
|
||||||
border: 1px solid $border;
|
border: 1px solid $border;
|
||||||
font-family: $font-sans;
|
border-left: 0;
|
||||||
font-size: rem-calc(12);
|
border-right: 0;
|
||||||
|
font-size: $small-font-size;
|
||||||
margin: rem-calc(6) 0;
|
margin: rem-calc(6) 0;
|
||||||
padding: rem-calc(6);
|
padding: rem-calc(6);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class CommentsController < ApplicationController
|
class CommentsController < ApplicationController
|
||||||
before_action :authenticate_user!
|
before_action :authenticate_user!, only: :create
|
||||||
before_action :load_commentable, only: :create
|
before_action :load_commentable, only: :create
|
||||||
before_action :build_comment, only: :create
|
before_action :build_comment, only: :create
|
||||||
|
|
||||||
@@ -15,6 +15,11 @@ class CommentsController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
@comment = Comment.find(params[:id])
|
||||||
|
set_comment_flags(@comment.subtree)
|
||||||
|
end
|
||||||
|
|
||||||
def vote
|
def vote
|
||||||
@comment.vote_by(voter: current_user, vote: params[:value])
|
@comment.vote_by(voter: current_user, vote: params[:value])
|
||||||
respond_with @comment
|
respond_with @comment
|
||||||
|
|||||||
@@ -13,8 +13,11 @@ module CommentsHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def child_comments_of(parent)
|
def child_comments_of(parent)
|
||||||
return [] unless @comment_tree
|
if @comment_tree.present?
|
||||||
@comment_tree.children_of(parent)
|
@comment_tree.ordered_children_of(parent)
|
||||||
|
else
|
||||||
|
parent.children
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_level_class(comment)
|
def user_level_class(comment)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ module Abilities
|
|||||||
def initialize(user)
|
def initialize(user)
|
||||||
can :read, Debate
|
can :read, Debate
|
||||||
can :read, Proposal
|
can :read, Proposal
|
||||||
|
can :read, Comment
|
||||||
can :read, Legislation
|
can :read, Legislation
|
||||||
can :read, User
|
can :read, User
|
||||||
can [:search, :read], Annotation
|
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 class="row">
|
||||||
<div id="<%= dom_id(comment) %>" class="comment small-12 column">
|
<div id="<%= dom_id(comment) %>" class="comment small-12 column">
|
||||||
|
|
||||||
<% if comment.hidden? || comment.user.hidden? %>
|
<% if comment.hidden? || comment.user.hidden? %>
|
||||||
<% if child_comments_of(comment).size > 0 %>
|
<% if comment.children.size > 0 %>
|
||||||
<div class="is-deleted">
|
<div class="is-deleted">
|
||||||
<p><%= t("comments.comment.deleted") %></p>
|
<p><%= t("comments.comment.deleted") %></p>
|
||||||
</div>
|
</div>
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
<%= t("shared.collective") %>
|
<%= t("shared.collective") %>
|
||||||
</span>
|
</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if comment.user_id == @commentable.author_id %>
|
<% if comment.user_id == comment.commentable.author_id %>
|
||||||
•
|
•
|
||||||
<span class="label round is-author">
|
<span class="label round is-author">
|
||||||
<%= t("comments.comment.author") %>
|
<%= t("comments.comment.author") %>
|
||||||
@@ -63,16 +63,16 @@
|
|||||||
|
|
||||||
<div class="comment-user
|
<div class="comment-user
|
||||||
<%= user_level_class comment %>
|
<%= 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 %>
|
<%= simple_format text_with_links comment.body %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<span id="<%= dom_id(comment) %>_votes" class="comment-votes right">
|
<div class="reply">
|
||||||
<%= render 'comments/votes', comment: comment %>
|
<span id="<%= dom_id(comment) %>_votes" class="comment-votes right">
|
||||||
</span>
|
<%= render 'comments/votes', comment: comment %>
|
||||||
|
</span>
|
||||||
|
|
||||||
<div id="<%= dom_id(comment) %>_reply" class="reply">
|
<%= t("comments.comment.responses", count: comment.children.size) %>
|
||||||
<%= t("comments.comment.responses", count: child_comments_of(comment).size) %>
|
|
||||||
|
|
||||||
<% if user_signed_in? %>
|
<% if user_signed_in? %>
|
||||||
<span class="divider"> | </span>
|
<span class="divider"> | </span>
|
||||||
@@ -81,11 +81,12 @@
|
|||||||
|
|
||||||
<%= render 'comments/actions', comment: comment %>
|
<%= 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 %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<div class="comment-children">
|
<div class="comment-children">
|
||||||
<% child_comments_of(comment).each do |child| %>
|
<% child_comments_of(comment).each do |child| %>
|
||||||
<%= render 'comments/comment', comment: child %>
|
<%= render 'comments/comment', comment: child %>
|
||||||
|
|||||||
16
app/views/comments/show.html.erb
Normal file
16
app/views/comments/show.html.erb
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<div class="row">
|
||||||
|
<div class="small-12 column margin-top">
|
||||||
|
<%= link_to @comment.commentable, class: "left back" do %>
|
||||||
|
<i class="icon-angle-left left"></i>
|
||||||
|
<%= t("comments.show.return_to_commentable") + @comment.commentable.title %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<section class="comments">
|
||||||
|
<div class="row">
|
||||||
|
<div id="comments" class="small-12 column">
|
||||||
|
<%= render @comment %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
@@ -243,6 +243,8 @@ en:
|
|||||||
form:
|
form:
|
||||||
submit_button: "Save changes"
|
submit_button: "Save changes"
|
||||||
comments:
|
comments:
|
||||||
|
show:
|
||||||
|
return_to_commentable: "Go back to "
|
||||||
select_order: "Sort by"
|
select_order: "Sort by"
|
||||||
orders:
|
orders:
|
||||||
most_voted: "Most voted"
|
most_voted: "Most voted"
|
||||||
|
|||||||
@@ -243,6 +243,8 @@ es:
|
|||||||
form:
|
form:
|
||||||
submit_button: "Guardar cambios"
|
submit_button: "Guardar cambios"
|
||||||
comments:
|
comments:
|
||||||
|
show:
|
||||||
|
return_to_commentable: "Volver a "
|
||||||
select_order: "Ordenar por"
|
select_order: "Ordenar por"
|
||||||
orders:
|
orders:
|
||||||
most_voted: "Más votados"
|
most_voted: "Más votados"
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :comments, only: :create, shallow: true do
|
resources :comments, only: [:create, :show], shallow: true do
|
||||||
member do
|
member do
|
||||||
post :vote
|
post :vote
|
||||||
put :flag
|
put :flag
|
||||||
|
|||||||
@@ -2,24 +2,34 @@ class CommentTree
|
|||||||
|
|
||||||
ROOT_COMMENTS_PER_PAGE = 10
|
ROOT_COMMENTS_PER_PAGE = 10
|
||||||
|
|
||||||
attr_accessor :root_comments, :comments
|
attr_accessor :root_comments, :comments, :commentable, :page, :order
|
||||||
|
|
||||||
def initialize(commentable, page, order = 'confidence_score')
|
def initialize(commentable, page, order = 'confidence_score')
|
||||||
@root_comments = commentable.comments.roots.send("sort_by_#{order}").page(page).per(ROOT_COMMENTS_PER_PAGE).for_render
|
@commentable = commentable
|
||||||
|
@page = page
|
||||||
root_descendants = @root_comments.each_with_object([]) do |root, col|
|
@order = order
|
||||||
col.concat(Comment.descendants_of(root).send("sort_descendants_by_#{order}").for_render.to_a)
|
|
||||||
end
|
|
||||||
|
|
||||||
@comments = root_comments + root_descendants
|
@comments = root_comments + root_descendants
|
||||||
|
end
|
||||||
|
|
||||||
@comments_by_parent_id = @comments.each_with_object({}) do |comment, col|
|
def root_comments
|
||||||
(col[comment.parent_id] ||= []) << comment
|
commentable.comments.roots.send("sort_by_#{order}").page(page).per(ROOT_COMMENTS_PER_PAGE).for_render
|
||||||
|
end
|
||||||
|
|
||||||
|
def root_descendants
|
||||||
|
root_comments.each_with_object([]) do |root, array|
|
||||||
|
array.concat(Comment.descendants_of(root).send("sort_descendants_by_#{order}").for_render.to_a)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def children_of(parent)
|
def ordered_children_of(parent)
|
||||||
@comments_by_parent_id[parent.id] || []
|
comments_by_parent_id[parent.id] || []
|
||||||
|
end
|
||||||
|
|
||||||
|
def comments_by_parent_id
|
||||||
|
comments.each_with_object({}) do |comment, array|
|
||||||
|
(array[comment.parent_id] ||= []) << comment
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def comment_authors
|
def comment_authors
|
||||||
|
|||||||
@@ -20,6 +20,21 @@ feature 'Commenting debates' do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario 'Show' do
|
||||||
|
parent_comment = create(:comment, commentable: debate)
|
||||||
|
first_child = create(:comment, commentable: debate, parent: parent_comment)
|
||||||
|
second_child = create(:comment, commentable: debate, parent: parent_comment)
|
||||||
|
|
||||||
|
visit comment_path(parent_comment)
|
||||||
|
|
||||||
|
expect(page).to have_css(".comment", count: 3)
|
||||||
|
expect(page).to have_content parent_comment.body
|
||||||
|
expect(page).to have_content first_child.body
|
||||||
|
expect(page).to have_content second_child.body
|
||||||
|
|
||||||
|
expect(page).to have_link "Go back to #{debate.title}", debate_path(debate)
|
||||||
|
end
|
||||||
|
|
||||||
scenario 'Comment order' do
|
scenario 'Comment order' do
|
||||||
c1 = create(:comment, :with_confidence_score, commentable: debate, cached_votes_up: 100, cached_votes_total: 120, created_at: Time.now - 2)
|
c1 = create(:comment, :with_confidence_score, commentable: debate, cached_votes_up: 100, cached_votes_total: 120, created_at: Time.now - 2)
|
||||||
c2 = create(:comment, :with_confidence_score, commentable: debate, cached_votes_up: 10, cached_votes_total: 12, created_at: Time.now - 1)
|
c2 = create(:comment, :with_confidence_score, commentable: debate, cached_votes_up: 10, cached_votes_total: 12, created_at: Time.now - 1)
|
||||||
|
|||||||
@@ -20,6 +20,21 @@ feature 'Commenting proposals' do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario 'Show' do
|
||||||
|
parent_comment = create(:comment, commentable: proposal)
|
||||||
|
first_child = create(:comment, commentable: proposal, parent: parent_comment)
|
||||||
|
second_child = create(:comment, commentable: proposal, parent: parent_comment)
|
||||||
|
|
||||||
|
visit comment_path(parent_comment)
|
||||||
|
|
||||||
|
expect(page).to have_css(".comment", count: 3)
|
||||||
|
expect(page).to have_content parent_comment.body
|
||||||
|
expect(page).to have_content first_child.body
|
||||||
|
expect(page).to have_content second_child.body
|
||||||
|
|
||||||
|
expect(page).to have_link "Go back to #{proposal.title}", proposal_path(proposal)
|
||||||
|
end
|
||||||
|
|
||||||
scenario 'Comment order' do
|
scenario 'Comment order' do
|
||||||
c1 = create(:comment, :with_confidence_score, commentable: proposal, cached_votes_up: 100, cached_votes_total: 120, created_at: Time.now - 2)
|
c1 = create(:comment, :with_confidence_score, commentable: proposal, cached_votes_up: 100, cached_votes_total: 120, created_at: Time.now - 2)
|
||||||
c2 = create(:comment, :with_confidence_score, commentable: proposal, cached_votes_up: 10, cached_votes_total: 12, created_at: Time.now - 1)
|
c2 = create(:comment, :with_confidence_score, commentable: proposal, cached_votes_up: 10, cached_votes_total: 12, created_at: Time.now - 1)
|
||||||
|
|||||||
@@ -21,4 +21,6 @@ describe "Abilities::Everyone" do
|
|||||||
it { should_not be_able_to(:vote, Proposal) }
|
it { should_not be_able_to(:vote, Proposal) }
|
||||||
it { should_not be_able_to(:flag, Proposal) }
|
it { should_not be_able_to(:flag, Proposal) }
|
||||||
it { should_not be_able_to(:unflag, Proposal) }
|
it { should_not be_able_to(:unflag, Proposal) }
|
||||||
|
|
||||||
|
it { should be_able_to(:show, Comment) }
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user