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 5 comments_map = article.comments.group_by { |comment| comment.paragraph_uuid }
6 6 @export = []
7 7 doc = Nokogiri::HTML(article.body)
  8 + paragraph_id = 1
8 9 doc.css("[data-macro-paragraph_uuid]").map do |paragraph|
9 10 uuid = paragraph.attributes['data-macro-paragraph_uuid'].value
10 11 comments_for_paragraph = comments_map[uuid]
11 12 if comments_for_paragraph
12 13 # Put comments for the paragraph
13 14 comments_for_paragraph.each do | comment |
14   - @export << create_comment_element(comment, paragraph)
  15 + @export << create_comment_element(comment, paragraph, paragraph_id)
15 16 end
16 17 else # There are no comments for this paragraph
17   - @export << { paragraph_text: paragraph }
  18 + @export << { paragraph_id: paragraph_id, paragraph_text: paragraph }
18 19 end
  20 + paragraph_id += 1
19 21 end
20 22 # Now we need to put all other comments that are not attached to a paragraph
21 23 comments_without_paragrah = comments_map[nil] || []
22 24 comments_without_paragrah.each do | comment |
23   - @export << create_comment_element(comment, nil)
  25 + @export << create_comment_element(comment, nil, nil)
24 26 end
25 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 35  
34 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 41 paragraph_text: paragraph.present? ? paragraph.text : nil,
39 42 comment_id: comment.id,
  43 + comment_reply_to: comment.reply_of_id,
40 44 comment_title: comment.title,
41 45 comment_content: comment.body,
42 46 comment_author_name: comment.author_name,
... ...