Commit f9937d0e20ba80fd92d7200e129ce0d7080e78ec
1 parent
af792624
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
before rename paragraph_id paragraph_uuid
Showing
5 changed files
with
131 additions
and
111 deletions
Show diff stats
plugins/comment_paragraph/db/migrate/20140715201649_add_paragraph_id_to_comment.rb
plugins/comment_paragraph/db/migrate/20141223184902_add_paragraph_uuid_to_comments.rb
0 → 100644
plugins/comment_paragraph/lib/comment_paragraph_plugin.rb
... | ... | @@ -40,48 +40,47 @@ class CommentParagraphPlugin < Noosfero::Plugin |
40 | 40 | true |
41 | 41 | end |
42 | 42 | |
43 | - def cms_controller_filters | |
44 | - block = proc do | |
45 | - if params['commit'] == 'Save' | |
43 | +# def cms_controller_filters | |
44 | +# block = proc do | |
45 | +# if params['commit'] == 'Save' | |
46 | +# | |
47 | +# settings = Noosfero::Plugin::Settings.new(environment, CommentParagraphPlugin, params[:settings]) | |
48 | +# | |
49 | +# extend CommentParagraphPlugin::CommentParagraphHelper | |
50 | +# if !@article.id.blank? && self.auto_marking_enabled?(settings, @article.class.name) | |
51 | +# | |
52 | +# parsed_paragraphs = [] | |
53 | +# paragraph_id = 0 | |
54 | +# | |
55 | +# doc = Hpricot(@article.body) | |
56 | +# paragraphs = doc.search("/*").each do |paragraph| | |
57 | +# | |
58 | +# if paragraph.to_html =~ /^<div(.*)paragraph_comment(.*)$/ || paragraph.to_html =~ /^<p>\W<\/p>$/ | |
59 | +# parsed_paragraphs << paragraph.to_html | |
60 | +# else | |
61 | +# if paragraph.to_html =~ /^(<div|<table|<p|<ul).*/ | |
62 | +# parsed_paragraphs << CommentParagraphPlugin.parse_paragraph(paragraph.to_html, paragraph_id) | |
63 | +# else | |
64 | +# parsed_paragraphs << paragraph.to_html | |
65 | +# end | |
66 | +# end | |
67 | +# | |
68 | +# paragraph_id += 1 | |
69 | +# | |
70 | +# end | |
71 | +# | |
72 | +# @article.body = parsed_paragraphs.join() | |
73 | +# @article.save | |
74 | +# | |
75 | +# end | |
76 | +# end | |
77 | +# end | |
78 | +# | |
79 | +# { :type => 'after_filter', | |
80 | +# :method_name => 'new', | |
81 | +# :block => block } | |
82 | +# end | |
46 | 83 | |
47 | - settings = Noosfero::Plugin::Settings.new(environment, CommentParagraphPlugin, params[:settings]) | |
48 | - | |
49 | - extend CommentParagraphPlugin::CommentParagraphHelper | |
50 | - if !@article.id.blank? && self.auto_marking_enabled?(settings, @article.class.name) | |
51 | - | |
52 | - parsed_paragraphs = [] | |
53 | - paragraph_id = 0 | |
54 | - | |
55 | - doc = Hpricot(@article.body) | |
56 | - paragraphs = doc.search("/*").each do |paragraph| | |
57 | - | |
58 | - if paragraph.to_html =~ /^<div(.*)paragraph_comment(.*)$/ || paragraph.to_html =~ /^<p>\W<\/p>$/ | |
59 | - parsed_paragraphs << paragraph.to_html | |
60 | - else | |
61 | - if paragraph.to_html =~ /^(<div|<table|<p|<ul).*/ | |
62 | - parsed_paragraphs << CommentParagraphPlugin.parse_paragraph(paragraph.to_html, paragraph_id) | |
63 | - else | |
64 | - parsed_paragraphs << paragraph.to_html | |
65 | - end | |
66 | - end | |
67 | - | |
68 | - paragraph_id += 1 | |
69 | - | |
70 | - end | |
71 | - | |
72 | - @article.body = parsed_paragraphs.join() | |
73 | - @article.save | |
74 | - | |
75 | - end | |
76 | - end | |
77 | - end | |
78 | - | |
79 | - { :type => 'after_filter', | |
80 | - :method_name => 'new', | |
81 | - :block => block } | |
82 | - end | |
83 | - | |
84 | - private | |
85 | 84 | |
86 | 85 | def self.parse_paragraph( paragraph_content, paragraph_id ) |
87 | 86 | "<div class='macro article_comments paragraph_comment' " + | ... | ... |
plugins/comment_paragraph/lib/ext/article.rb
... | ... | @@ -2,16 +2,40 @@ require_dependency 'article' |
2 | 2 | |
3 | 3 | class Article |
4 | 4 | |
5 | - has_many :paragraph_comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc', :conditions => [ 'paragraph_id IS NOT NULL'] | |
5 | + has_many :paragraph_comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc', :conditions => [ 'paragraph_uuid IS NOT NULL'] | |
6 | 6 | |
7 | - validate :body_change_with_comments | |
7 | + # validate :body_change_with_comments | |
8 | + | |
9 | + before_save :parse_html | |
8 | 10 | |
9 | 11 | def body_change_with_comments |
10 | 12 | if body && body_changed? && !self.comments.empty? |
11 | - paragraphs_with_comments = self.comments.where("paragraph_id IS NOT NULL") | |
13 | + paragraphs_with_comments = self.comments.where("paragraph_uuid IS NOT NULL") | |
12 | 14 | errors[:base] << (N_('You are unable to change the body of the article when paragraphs are commented')) unless (paragraphs_with_comments).empty? |
13 | 15 | end |
14 | 16 | end |
17 | + | |
18 | + def parse_html | |
19 | + if body && body_changed? | |
20 | + parsed_paragraphs = [] | |
21 | + updated = body_change[1] | |
22 | + doc = Hpricot(updated) | |
23 | + paragraphs = doc.search("/*").each do |paragraph| | |
24 | + uuid = SecureRandom.uuid | |
25 | + if paragraph.to_html =~ /^<div(.*)paragraph_comment(.*)$/ || paragraph.to_html =~ /^<p>\W<\/p>$/ | |
26 | + parsed_paragraphs << paragraph.to_html | |
27 | + else | |
28 | + if paragraph.to_html =~ /^(<div|<table|<p|<ul).*/ | |
29 | + parsed_paragraphs << CommentParagraphPlugin.parse_paragraph(paragraph.to_html, uuid) | |
30 | + else | |
31 | + parsed_paragraphs << paragraph.to_html | |
32 | + end | |
33 | + end | |
34 | + end | |
35 | + self.body = parsed_paragraphs.join() | |
36 | + #@article.save | |
37 | + end | |
38 | + end | |
39 | + | |
15 | 40 | |
16 | 41 | end |
17 | - | ... | ... |
plugins/comment_paragraph/public/comment_paragraph.js
1 | -String.prototype.startsWith = function(needle){ | |
2 | - return(this.indexOf(needle) == 0); | |
3 | -}; | |
4 | - | |
5 | -function makeAllCommentable() { | |
6 | - var paragraphsTxt=""; | |
7 | - var selectedTextCount=0; | |
8 | - var notSelectedTextCount=0; | |
9 | - var text; | |
10 | - | |
11 | - //Search for text that is not selected in the middle of selected text, in this case unselect everything | |
12 | - jQuery('#article_body_ifr').contents().find('body').children().each(function( index ) { | |
13 | - //Check if there are other texts not selected | |
14 | - var element=jQuery(this).prop('outerHTML'); | |
15 | - if(element.startsWith('<div')){ | |
16 | - selectedTextCount++; | |
17 | - }else{ | |
18 | - if(! element.startsWith('<p><br></p>') && ! element.startsWith('<p> </p>') ){ | |
19 | - notSelectedTextCount++; | |
20 | - } | |
21 | - } | |
22 | - }); | |
23 | - | |
24 | - if(selectedTextCount > 0 && notSelectedTextCount>0){ | |
25 | - jQuery('#article_body_ifr').contents().find('body').children('.paragraph_comment').contents().unwrap(); | |
26 | - //Workaround necessary to post the body of the article | |
27 | - tinymce.activeEditor.execCommand('mceInsertContent', false, " "); | |
28 | - return; | |
29 | - } | |
30 | - | |
31 | - //Add p tag, when opening the editor. For some season it appear at the end without p tag | |
32 | - foundCommentableParagraph = false; | |
33 | - jQuery('#article_body_ifr').contents().find('body').children('div.article_comments').each(function( index ) { | |
34 | - if(jQuery(this).html()!="" && jQuery(this).html()!=" " && jQuery(this).html()!="<br>"){ | |
35 | - paragraphsTxt+="<p>" + jQuery(this).html() + "</p>"; | |
36 | - } | |
37 | - foundCommentableParagraph = true; | |
38 | - }); | |
39 | - | |
40 | - //undo the paragraph comment tags | |
41 | - if(foundCommentableParagraph === true){ | |
42 | - tinyMCE.activeEditor.setContent(paragraphsTxt); | |
43 | - return; | |
44 | - } | |
45 | - | |
46 | - //Wraps the paragraph using the chosen class | |
47 | - jQuery('#article_body_ifr').contents().find('body').children('p,table,img').each(function( index ) { | |
48 | - text=jQuery(this).prop('outerHTML'); | |
49 | - if(text!="" && text!=" " && text!="<br>"){ | |
50 | - paragraphsTxt+='<div class="macro article_comments paragraph_comment" data-macro="comment_paragraph_plugin/allow_comment" data-macro-paragraph_id="' + index + '">' + text + '</div><br>' | |
51 | - } | |
52 | - }); | |
53 | - tinyMCE.activeEditor.setContent(paragraphsTxt); | |
54 | - | |
55 | - //Workaround necessary to post the body of the article | |
56 | - tinymce.activeEditor.execCommand('mceInsertContent', false, " "); | |
57 | -} | |
1 | +//String.prototype.startsWith = function(needle){ | |
2 | +// return(this.indexOf(needle) == 0); | |
3 | +//}; | |
4 | +// | |
5 | +//function makeAllCommentable() { | |
6 | +// var paragraphsTxt=""; | |
7 | +// var selectedTextCount=0; | |
8 | +// var notSelectedTextCount=0; | |
9 | +// var text; | |
10 | +// | |
11 | +// //Search for text that is not selected in the middle of selected text, in this case unselect everything | |
12 | +// jQuery('#article_body_ifr').contents().find('body').children().each(function( index ) { | |
13 | +// //Check if there are other texts not selected | |
14 | +// var element=jQuery(this).prop('outerHTML'); | |
15 | +// if(element.startsWith('<div')){ | |
16 | +// selectedTextCount++; | |
17 | +// }else{ | |
18 | +// if(! element.startsWith('<p><br></p>') && ! element.startsWith('<p> </p>') ){ | |
19 | +// notSelectedTextCount++; | |
20 | +// } | |
21 | +// } | |
22 | +// }); | |
23 | +// | |
24 | +// if(selectedTextCount > 0 && notSelectedTextCount>0){ | |
25 | +// jQuery('#article_body_ifr').contents().find('body').children('.paragraph_comment').contents().unwrap(); | |
26 | +// //Workaround necessary to post the body of the article | |
27 | +// tinymce.activeEditor.execCommand('mceInsertContent', false, " "); | |
28 | +// return; | |
29 | +// } | |
30 | +// | |
31 | +// //Add p tag, when opening the editor. For some season it appear at the end without p tag | |
32 | +// foundCommentableParagraph = false; | |
33 | +// jQuery('#article_body_ifr').contents().find('body').children('div.article_comments').each(function( index ) { | |
34 | +// if(jQuery(this).html()!="" && jQuery(this).html()!=" " && jQuery(this).html()!="<br>"){ | |
35 | +// paragraphsTxt+="<p>" + jQuery(this).html() + "</p>"; | |
36 | +// } | |
37 | +// foundCommentableParagraph = true; | |
38 | +// }); | |
39 | +// | |
40 | +// //undo the paragraph comment tags | |
41 | +// if(foundCommentableParagraph === true){ | |
42 | +// tinyMCE.activeEditor.setContent(paragraphsTxt); | |
43 | +// return; | |
44 | +// } | |
45 | +// | |
46 | +// //Wraps the paragraph using the chosen class | |
47 | +// jQuery('#article_body_ifr').contents().find('body').children('p,table,img').each(function( index ) { | |
48 | +// text=jQuery(this).prop('outerHTML'); | |
49 | +// if(text!="" && text!=" " && text!="<br>"){ | |
50 | +// paragraphsTxt+='<div class="macro article_comments paragraph_comment" data-macro="comment_paragraph_plugin/allow_comment" data-macro-paragraph_id="' + index + '">' + text + '</div><br>' | |
51 | +// } | |
52 | +// }); | |
53 | +// tinyMCE.activeEditor.setContent(paragraphsTxt); | |
54 | +// | |
55 | +// //Workaround necessary to post the body of the article | |
56 | +// tinymce.activeEditor.execCommand('mceInsertContent', false, " "); | |
57 | +//} | ... | ... |