Commit d1347c27eab09e352296cfe157a6b37a915b8c6a

Authored by Carlos Purificação
1 parent 01d4176e

Added paragraph id and comment_reply_to

plugins/comment_paragraph/lib/comment_paragraph_plugin/comments_report.rb
@@ -5,22 +5,24 @@ module CommentParagraphPlugin::CommentsReport @@ -5,22 +5,24 @@ module CommentParagraphPlugin::CommentsReport
5 comments_map = article.comments.group_by { |comment| comment.paragraph_uuid } 5 comments_map = article.comments.group_by { |comment| comment.paragraph_uuid }
6 @export = [] 6 @export = []
7 doc = Nokogiri::HTML(article.body) 7 doc = Nokogiri::HTML(article.body)
  8 + paragraph_id = 1
8 doc.css("[data-macro-paragraph_uuid]").map do |paragraph| 9 doc.css("[data-macro-paragraph_uuid]").map do |paragraph|
9 uuid = paragraph.attributes['data-macro-paragraph_uuid'].value 10 uuid = paragraph.attributes['data-macro-paragraph_uuid'].value
10 comments_for_paragraph = comments_map[uuid] 11 comments_for_paragraph = comments_map[uuid]
11 if comments_for_paragraph 12 if comments_for_paragraph
12 # Put comments for the paragraph 13 # Put comments for the paragraph
13 comments_for_paragraph.each do | comment | 14 comments_for_paragraph.each do | comment |
14 - @export << create_comment_element(comment, paragraph) 15 + @export << create_comment_element(comment, paragraph, paragraph_id)
15 end 16 end
16 else # There are no comments for this paragraph 17 else # There are no comments for this paragraph
17 - @export << { paragraph_text: paragraph } 18 + @export << { paragraph_id: paragraph_id, paragraph_text: paragraph }
18 end 19 end
  20 + paragraph_id += 1
19 end 21 end
20 # Now we need to put all other comments that are not attached to a paragraph 22 # Now we need to put all other comments that are not attached to a paragraph
21 comments_without_paragrah = comments_map[nil] || [] 23 comments_without_paragrah = comments_map[nil] || []
22 comments_without_paragrah.each do | comment | 24 comments_without_paragrah.each do | comment |
23 - @export << create_comment_element(comment, nil) 25 + @export << create_comment_element(comment, nil, nil)
24 end 26 end
25 return _("No comments for article[%{id}]: %{path}\n\n") % {:id => article.id, :path => article.path} if @export.empty? 27 return _("No comments for article[%{id}]: %{path}\n\n") % {:id => article.id, :path => article.path} if @export.empty?
26 28
@@ -33,10 +35,12 @@ module CommentParagraphPlugin::CommentsReport @@ -33,10 +35,12 @@ module CommentParagraphPlugin::CommentsReport
33 35
34 private 36 private
35 37
36 - def create_comment_element(comment, paragraph) 38 + def create_comment_element(comment, paragraph, paragraph_id)
37 { 39 {
  40 + paragraph_id: paragraph_id,
38 paragraph_text: paragraph.present? ? paragraph.text : nil, 41 paragraph_text: paragraph.present? ? paragraph.text : nil,
39 comment_id: comment.id, 42 comment_id: comment.id,
  43 + comment_reply_to: comment.reply_of_id,
40 comment_title: comment.title, 44 comment_title: comment.title,
41 comment_content: comment.body, 45 comment_content: comment.body,
42 comment_author_name: comment.author_name, 46 comment_author_name: comment.author_name,