Merges annotations

This commit is contained in:
rgarcia
2017-06-07 14:58:34 +02:00
parent f66102abdc
commit 792b15b224
9 changed files with 235 additions and 41 deletions

View File

@@ -8,7 +8,7 @@ class Legislation::AnnotationsController < ApplicationController
load_and_authorize_resource :draft_version, through: :process
load_and_authorize_resource
has_orders %w{most_voted newest oldest}, only: :show
has_orders %w{most_voted newest}, only: :show
def index
@annotations = @draft_version.annotations
@@ -16,7 +16,15 @@ class Legislation::AnnotationsController < ApplicationController
def show
@commentable = @annotation
@comment_tree = CommentTree.new(@commentable, params[:page], @current_order)
if params[:sub_annotation_ids].present?
@sub_annotations = Legislation::Annotation.where(id: params[:sub_annotation_ids].split(','))
annotations = [@commentable, @sub_annotations]
else
annotations = [@commentable]
end
@comment_tree = MergedCommentTree.new(annotations, params[:page], @current_order)
set_comment_flags(@comment_tree.comments)
end

View File

@@ -0,0 +1,3 @@
<%= link_to legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation, sub_annotation_ids: "") do %>
<span class="icon-expand" aria-hidden="true"></span>
<% end %>

View File

@@ -0,0 +1,10 @@
<span class="icon-comment" aria-hidden="true"></span>
<div class="comment-number">
<%= t('legislation.annotations.comments.comments_count',
count: annotation.comments.roots.count) %>
</div>
<span id="annotation-link" data-sub-annotation-ids="8">
<%= render "annotation_link", annotation: annotation %>
<span>

View File

@@ -0,0 +1,29 @@
<% annotation.comments.roots.sort_by_most_voted.
limit(Legislation::Annotation::COMMENTS_PAGE_SIZE).each do |comment| %>
<div class="comment">
<div class="comment-text">
<p><%= truncate comment.body, length: 250 %></p>
</div>
<div class="comment-meta">
<div class="comment-more-info">
<% if comment.body.length > 250 %>
<div class="comment-expand">
<%= link_to legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation) do %>
<%= t('legislation.annotations.comments.see_complete') %>
<% end %>
</div>
<% end %>
<div class="comment-replies" id="annotation-<%= annotation.id %>-comments">
<%= link_to legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation, anchor: "comment_#{comment.id}") do %>
<%= t('legislation.annotations.comments.replies_count', count: comment.children.size) %>
<% end %>
</div>
</div>
<div class="comment-votes">
<div id="<%= dom_id(comment) %>_votes" class="comment-votes float-right">
<%= render 'comments/votes', comment: comment %>
</div>
</div>
</div>
</div>
<% end %>

View File

@@ -1,41 +1,11 @@
<div class="comment-box" id="comments-box-<%= annotation.id %>">
<div class="comment-header">
<span class="icon-comment" aria-hidden="true"></span>
<div class="comment-number"><%= t('legislation.annotations.comments.comments_count', count: annotation.comments.roots.count) %></div>
<%= link_to legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation) do %>
<span class="icon-expand" aria-hidden="true"></span>
<% end %>
<%= render "comment_header", annotation: annotation %>
</div>
<div class="comments-wrapper">
<% annotation.comments.roots.sort_by_most_voted.limit(Legislation::Annotation::COMMENTS_PAGE_SIZE).each do |comment| %>
<div class="comment">
<div class="comment-text">
<p><%= truncate comment.body, length: 250 %></p>
</div>
<div class="comment-meta">
<div class="comment-more-info">
<% if comment.body.length > 250 %>
<div class="comment-expand">
<%= link_to legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation) do %>
<%= t('legislation.annotations.comments.see_complete') %>
<% end %>
</div>
<% end %>
<div class="comment-replies">
<%= link_to legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation, anchor: "comment_#{comment.id}") do %>
<%= t('legislation.annotations.comments.replies_count', count: comment.children.size) %>
<% end %>
</div>
</div>
<div class="comment-votes">
<div id="<%= dom_id(comment) %>_votes" class="comment-votes float-right">
<%= render 'comments/votes', comment: comment %>
</div>
</div>
</div>
<div id="comments">
<%= render "comments", annotation: annotation %>
</div>
<% end %>
</div>
<div class="comment-footer">

View File

@@ -1,3 +1,24 @@
$("#comments-box").append("<%= j render('comments_box', annotation: @annotation) %>").show();
if ($(".comment").length == 0) {
$("#comments-box").append("<%= j render('comments_box', annotation: @annotation) %>").show();
} else {
$("#comments-box #comments").append("<%= j render('comments', annotation: @annotation) %>");
var current_annotation_link = $("#annotation-link a").attr("href")
var sub_annotation_ids = current_annotation_link.split('=')[1];
if (sub_annotation_ids.length == 0) {
var new_annotation_link = current_annotation_link + <%= "#{@annotation.id}" %>
}
else {
var new_annotation_link = current_annotation_link + "," + <%= "#{@annotation.id}" %>
}
$("#annotation-link a").attr("href", new_annotation_link)
var current_comment_text = $(".comment-number").text()
var current_comment_count = current_comment_text.match(/\d+/)[0]
var new_comment_count = parseInt(current_comment_count) + parseInt(<%= @annotation.comments.roots.count %>)
var new_comment_count_text = current_comment_text.replace(/(\d+)/, new_comment_count);
$(".comment-number").text(new_comment_count_text)
}
<%= render 'comments_box_form', comment: @comment, annotation: @annotation %>