diff --git a/plugins/comment_paragraph/controllers/profile/comment_paragraph_plugin_profile_controller.rb b/plugins/comment_paragraph/controllers/profile/comment_paragraph_plugin_profile_controller.rb index 19f2c7a..06ab1a6 100644 --- a/plugins/comment_paragraph/controllers/profile/comment_paragraph_plugin_profile_controller.rb +++ b/plugins/comment_paragraph/controllers/profile/comment_paragraph_plugin_profile_controller.rb @@ -3,9 +3,9 @@ class CommentParagraphPluginProfileController < ProfileController def view_comments @article_id = params[:article_id] - @paragraph_id = params[:paragraph_id] + @paragraph_uuid = params[:paragraph_uuid] article = profile.articles.find(@article_id) - @comments = article.comments.without_spam.in_paragraph(@paragraph_id) + @comments = article.comments.without_spam.in_paragraph(@paragraph_uuid) @comments_count = @comments.count @comments = @comments.without_reply end diff --git a/plugins/comment_paragraph/controllers/public/comment_paragraph_plugin_public_controller.rb b/plugins/comment_paragraph/controllers/public/comment_paragraph_plugin_public_controller.rb index a8bd78e..e34d4b9 100644 --- a/plugins/comment_paragraph/controllers/public/comment_paragraph_plugin_public_controller.rb +++ b/plugins/comment_paragraph/controllers/public/comment_paragraph_plugin_public_controller.rb @@ -3,7 +3,7 @@ class CommentParagraphPluginPublicController < PublicController def comment_paragraph @comment = Comment.find(params[:id]) - render :json => { :paragraph_id => @comment.paragraph_id } + render :json => { :paragraph_uuid => @comment.paragraph_uuid } end end diff --git a/plugins/comment_paragraph/lib/comment_paragraph_plugin.rb b/plugins/comment_paragraph/lib/comment_paragraph_plugin.rb index b9d7ca7..56a13d6 100644 --- a/plugins/comment_paragraph/lib/comment_paragraph_plugin.rb +++ b/plugins/comment_paragraph/lib/comment_paragraph_plugin.rb @@ -14,11 +14,11 @@ class CommentParagraphPlugin < Noosfero::Plugin def comment_form_extra_contents(args) comment = args[:comment] - paragraph_id = comment.paragraph_id || args[:paragraph_id] + paragraph_uuid = comment.paragraph_uuid || args[:paragraph_uuid] proc { arr = [] arr << hidden_field_tag('comment[id]', comment.id) - arr << hidden_field_tag('comment[paragraph_id]', paragraph_id) if paragraph_id + arr << hidden_field_tag('comment[paragraph_uuid]', paragraph_uuid) if paragraph_uuid arr << hidden_field_tag('comment[comment_paragraph_selected_area]', comment.comment_paragraph_selected_area) unless comment.comment_paragraph_selected_area.blank? arr << hidden_field_tag('comment[comment_paragraph_selected_content]', comment.comment_paragraph_selected_content) unless comment.comment_paragraph_selected_content.blank? arr @@ -50,22 +50,22 @@ class CommentParagraphPlugin < Noosfero::Plugin # if !@article.id.blank? && self.auto_marking_enabled?(settings, @article.class.name) # # parsed_paragraphs = [] -# paragraph_id = 0 +# paragraph_uuid = 0 # # doc = Hpricot(@article.body) # paragraphs = doc.search("/*").each do |paragraph| # -# if paragraph.to_html =~ /^\W<\/p>$/ +# if paragraph.to_html =~ /^\W<\/p>$/ # parsed_paragraphs << paragraph.to_html # else # if paragraph.to_html =~ /^(#{paragraph_content}\r\n" + + "data-macro-paragraph_uuid='#{paragraph_uuid}'>#{paragraph_content}\r\n" + "

 

" end diff --git a/plugins/comment_paragraph/lib/comment_paragraph_plugin/macros/allow_comment.rb b/plugins/comment_paragraph/lib/comment_paragraph_plugin/macros/allow_comment.rb index 9807376..3765480 100644 --- a/plugins/comment_paragraph/lib/comment_paragraph_plugin/macros/allow_comment.rb +++ b/plugins/comment_paragraph/lib/comment_paragraph_plugin/macros/allow_comment.rb @@ -1,5 +1,5 @@ #FIXME See a better way to generalize this parameter. -ActionView::Base.sanitized_allowed_attributes += ['data-macro', 'data-macro-paragraph_id'] +ActionView::Base.sanitized_allowed_attributes += ['data-macro', 'data-macro-paragraph_uuid'] class CommentParagraphPlugin::AllowComment < Noosfero::Plugin::Macro def self.configuration @@ -12,13 +12,13 @@ class CommentParagraphPlugin::AllowComment < Noosfero::Plugin::Macro end def parse(params, inner_html, source) - paragraph_id = params[:paragraph_id].to_i + paragraph_uuid = params[:paragraph_uuid] article = source - count = article.paragraph_comments.without_spam.in_paragraph(paragraph_id).count + count = article.paragraph_comments.without_spam.in_paragraph(paragraph_uuid).count proc { render :partial => 'comment_paragraph_plugin_profile/comment_paragraph', - :locals => {:paragraph_id => paragraph_id, :article_id => article.id, :inner_html => inner_html, :count => count, :profile_identifier => article.profile.identifier } + :locals => {:paragraph_uuid => paragraph_uuid, :article_id => article.id, :inner_html => inner_html, :count => count, :profile_identifier => article.profile.identifier } } end end diff --git a/plugins/comment_paragraph/lib/ext/comment.rb b/plugins/comment_paragraph/lib/ext/comment.rb index 5401e1f..edc26de 100644 --- a/plugins/comment_paragraph/lib/ext/comment.rb +++ b/plugins/comment_paragraph/lib/ext/comment.rb @@ -2,17 +2,17 @@ require_dependency 'comment' class Comment - scope :without_paragraph, :conditions => {:paragraph_id => nil } + scope :without_paragraph, :conditions => {:paragraph_uuid => nil } settings_items :comment_paragraph_selected_area, :type => :string settings_items :comment_paragraph_selected_content, :type => :string - scope :in_paragraph, proc { |paragraph_id| { - :conditions => ['paragraph_id = ?', paragraph_id] + scope :in_paragraph, proc { |paragraph_uuid| { + :conditions => ['paragraph_uuid = ?', paragraph_uuid] } } - attr_accessible :paragraph_id, :comment_paragraph_selected_area, :id, :comment_paragraph_selected_content + attr_accessible :paragraph_uuid, :comment_paragraph_selected_area, :id, :comment_paragraph_selected_content before_validation do |comment| comment.comment_paragraph_selected_area = nil if comment.comment_paragraph_selected_area.blank? diff --git a/plugins/comment_paragraph/public/comment_paragraph.js b/plugins/comment_paragraph/public/comment_paragraph.js index 78094e8..497f10a 100644 --- a/plugins/comment_paragraph/public/comment_paragraph.js +++ b/plugins/comment_paragraph/public/comment_paragraph.js @@ -47,7 +47,7 @@ // jQuery('#article_body_ifr').contents().find('body').children('p,table,img').each(function( index ) { // text=jQuery(this).prop('outerHTML'); // if(text!="" && text!=" " && text!="
"){ -// paragraphsTxt+='
' + text + '

' +// paragraphsTxt+='
' + text + '

' // } // }); // tinyMCE.activeEditor.setContent(paragraphsTxt); diff --git a/plugins/comment_paragraph/public/comment_paragraph_macro.js b/plugins/comment_paragraph/public/comment_paragraph_macro.js index cc80a8b..8777280 100644 --- a/plugins/comment_paragraph/public/comment_paragraph_macro.js +++ b/plugins/comment_paragraph/public/comment_paragraph_macro.js @@ -20,9 +20,9 @@ jQuery(document).ready(function($) { all_paragraphs = $('.comment_paragraph'); all_paragraphs.each( function(paragraph) { - var paragraph_id = $( all_paragraphs.get(paragraph) ).attr('data-paragraph'); + var paragraph_uuid = $( all_paragraphs.get(paragraph) ).attr('data-paragraph'); var paragraph_content = all_paragraphs.get(paragraph).innerHTML; - original_paragraphs.push( { id: paragraph_id, content: paragraph_content } ); + original_paragraphs.push( { id: paragraph_uuid, content: paragraph_content } ); }); $(document).keyup(function(e) { @@ -248,8 +248,8 @@ jQuery(document).ready(function($) { $(document).on('mouseenter', 'li.article-comment', function() { var selected_area = $(this).find('input.paragraph_comment_area').val(); - var paragraph_id = $(this).find('input.paragraph_id').val(); - var rootElement = $('#comment_paragraph_' + paragraph_id).get(0); + var paragraph_uuid = $(this).find('input.paragraph_uuid').val(); + var rootElement = $('#comment_paragraph_' + paragraph_uuid).get(0); if(selected_area != ""){ rangy.deserializeSelection(selected_area, rootElement); @@ -258,11 +258,11 @@ jQuery(document).ready(function($) { }); $(document).on('mouseleave', 'li.article-comment', function() { - var paragraph_id = $(this).find('input.paragraph_id').val(); - var rootElement = $('#comment_paragraph_'+ paragraph_id).get(0); + var paragraph_uuid = $(this).find('input.paragraph_uuid').val(); + var rootElement = $('#comment_paragraph_'+ paragraph_uuid).get(0); original_paragraphs.each( function(paragraph) { - if (paragraph.id == paragraph_id) { + if (paragraph.id == paragraph_uuid) { rootElement.innerHTML = paragraph.content; } }); diff --git a/plugins/comment_paragraph/test/functional/comment_paragraph_plugin_profile_controller_test.rb b/plugins/comment_paragraph/test/functional/comment_paragraph_plugin_profile_controller_test.rb index 9e08f4d..791e4fc 100644 --- a/plugins/comment_paragraph/test/functional/comment_paragraph_plugin_profile_controller_test.rb +++ b/plugins/comment_paragraph/test/functional/comment_paragraph_plugin_profile_controller_test.rb @@ -19,28 +19,28 @@ class CommentParagraphPluginProfileControllerTest < ActionController::TestCase attr_reader :profile should 'be able to show paragraph comments' do - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) - xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_id => 0 + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_uuid => 0) + xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_uuid => 0 assert_template 'comment_paragraph_plugin_profile/view_comments' assert_match /comments_list_paragraph_0/, @response.body assert_match /\"comment-count-0\", \"1\"/, @response.body end should 'do not show global comments' do - fast_create(Comment, :source_id => article, :author_id => profile, :title => 'global comment', :body => 'global', :paragraph_id => nil) - fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) - xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_id => 0 + fast_create(Comment, :source_id => article, :author_id => profile, :title => 'global comment', :body => 'global', :paragraph_uuid => nil) + fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_uuid => 0) + xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_uuid => 0 assert_template 'comment_paragraph_plugin_profile/view_comments' assert_match /comments_list_paragraph_0/, @response.body assert_match /\"comment-count-0\", \"1\"/, @response.body end should 'be able to show all comments of a paragraph' do - comment1 = fast_create(Comment, :created_at => Time.now - 1.days, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'a comment', :paragraph_id => 0) - comment2 = fast_create(Comment, :created_at => Time.now - 2.days, :source_id => article, :author_id => profile, :title => 'b comment', :body => 'b comment', :paragraph_id => 0) - comment3 = fast_create(Comment, :created_at => Time.now - 3.days, :source_id => article, :author_id => profile, :title => 'c comment', :body => 'c comment', :paragraph_id => 0) - comment4 = fast_create(Comment, :created_at => Time.now - 4.days, :source_id => article, :author_id => profile, :title => 'd comment', :body => 'd comment', :paragraph_id => 0) - xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_id => 0 + comment1 = fast_create(Comment, :created_at => Time.now - 1.days, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'a comment', :paragraph_uuid => 0) + comment2 = fast_create(Comment, :created_at => Time.now - 2.days, :source_id => article, :author_id => profile, :title => 'b comment', :body => 'b comment', :paragraph_uuid => 0) + comment3 = fast_create(Comment, :created_at => Time.now - 3.days, :source_id => article, :author_id => profile, :title => 'c comment', :body => 'c comment', :paragraph_uuid => 0) + comment4 = fast_create(Comment, :created_at => Time.now - 4.days, :source_id => article, :author_id => profile, :title => 'd comment', :body => 'd comment', :paragraph_uuid => 0) + xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_uuid => 0 assert_match /a comment/, @response.body assert_match /b comment/, @response.body assert_match /c comment/, @response.body diff --git a/plugins/comment_paragraph/test/functional/comment_paragraph_plugin_public_controller_test.rb b/plugins/comment_paragraph/test/functional/comment_paragraph_plugin_public_controller_test.rb index 43c12f5..3f4bf32 100644 --- a/plugins/comment_paragraph/test/functional/comment_paragraph_plugin_public_controller_test.rb +++ b/plugins/comment_paragraph/test/functional/comment_paragraph_plugin_public_controller_test.rb @@ -20,17 +20,17 @@ class CommentParagraphPluginPublicControllerTest < ActionController::TestCase attr_reader :profile - should 'be able to return paragraph_id for a comment' do - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) + should 'be able to return paragraph_uuid for a comment' do + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_uuid => 0) cid = comment.id xhr :get, :comment_paragraph, :id => cid - assert_match /\{\"paragraph_id\":0\}/, @response.body + assert_match /\{\"paragraph_uuid\":0\}/, @response.body end - should 'return paragraph_id=null for a global comment' do + should 'return paragraph_uuid=null for a global comment' do comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala' ) xhr :get, :comment_paragraph, :id => comment.id - assert_match /\{\"paragraph_id\":null\}/, @response.body + assert_match /\{\"paragraph_uuid\":null\}/, @response.body end diff --git a/plugins/comment_paragraph/test/functional/content_viewer_controller_test.rb b/plugins/comment_paragraph/test/functional/content_viewer_controller_test.rb index 573c7d7..e932348 100644 --- a/plugins/comment_paragraph/test/functional/content_viewer_controller_test.rb +++ b/plugins/comment_paragraph/test/functional/content_viewer_controller_test.rb @@ -11,7 +11,7 @@ class ContentViewerControllerTest < ActionController::TestCase def setup @profile = fast_create(Community) - @page = fast_create(Article, :profile_id => @profile.id, :body => "
") + @page = fast_create(Article, :profile_id => @profile.id, :body => "
") @environment = Environment.default @environment.enable_plugin(CommentParagraphPlugin) end @@ -19,7 +19,7 @@ class ContentViewerControllerTest < ActionController::TestCase attr_reader :page should 'parse article body and render comment paragraph view' do - comment1 = fast_create(Comment, :paragraph_id => 0, :source_id => page.id) + comment1 = fast_create(Comment, :paragraph_uuid => 0, :source_id => page.id) get :view_page, @page.url assert_tag 'div', :attributes => {:class => 'comment_paragraph'} end diff --git a/plugins/comment_paragraph/test/unit/allow_comment_test.rb b/plugins/comment_paragraph/test/unit/allow_comment_test.rb index f37a6f5..2b550cc 100644 --- a/plugins/comment_paragraph/test/unit/allow_comment_test.rb +++ b/plugins/comment_paragraph/test/unit/allow_comment_test.rb @@ -15,11 +15,11 @@ class AllowCommentTest < ActiveSupport::TestCase should 'parse contents to include comment paragraph view' do profile = fast_create(Community) article = fast_create(Article, :profile_id => profile.id) - comment = fast_create(Comment, :paragraph_id => 1, :source_id => article.id) + comment = fast_create(Comment, :paragraph_uuid => 1, :source_id => article.id) inner_html = 'inner' - content = macro.parse({:paragraph_id => comment.paragraph_id}, inner_html, article) + content = macro.parse({:paragraph_uuid => comment.paragraph_uuid}, inner_html, article) - expects(:render).with({:partial => 'comment_paragraph_plugin_profile/comment_paragraph', :locals => {:paragraph_id => comment.paragraph_id, :article_id => article.id, :inner_html => inner_html, :count => 1, :profile_identifier => profile.identifier} }) + expects(:render).with({:partial => 'comment_paragraph_plugin_profile/comment_paragraph', :locals => {:paragraph_uuid => comment.paragraph_uuid, :article_id => article.id, :inner_html => inner_html, :count => 1, :profile_identifier => profile.identifier} }) instance_eval(&content) end diff --git a/plugins/comment_paragraph/test/unit/article_test.rb b/plugins/comment_paragraph/test/unit/article_test.rb index 3f77cf1..b83340e 100644 --- a/plugins/comment_paragraph/test/unit/article_test.rb +++ b/plugins/comment_paragraph/test/unit/article_test.rb @@ -11,14 +11,14 @@ class ArticleTest < ActiveSupport::TestCase attr_reader :article should 'return paragraph comments from article' do - comment1 = fast_create(Comment, :paragraph_id => 1, :source_id => article.id) - comment2 = fast_create(Comment, :paragraph_id => nil, :source_id => article.id) + comment1 = fast_create(Comment, :paragraph_uuid => 1, :source_id => article.id) + comment2 = fast_create(Comment, :paragraph_uuid => nil, :source_id => article.id) assert_equal [comment1], article.paragraph_comments end should 'allow save if comment paragraph macro is not removed for paragraph with comments' do - article.body = "
" - comment1 = fast_create(Comment, :paragraph_id => 0, :source_id => article.id) + article.body = "
" + comment1 = fast_create(Comment, :paragraph_uuid => 0, :source_id => article.id) assert article.save end diff --git a/plugins/comment_paragraph/test/unit/comment_paragraph_plugin_test.rb b/plugins/comment_paragraph/test/unit/comment_paragraph_plugin_test.rb index 1866fb6..091840e 100644 --- a/plugins/comment_paragraph/test/unit/comment_paragraph_plugin_test.rb +++ b/plugins/comment_paragraph/test/unit/comment_paragraph_plugin_test.rb @@ -29,9 +29,9 @@ class CommentParagraphPluginTest < ActiveSupport::TestCase should 'not add comment_paragraph_selected_area if comment_paragraph_selected_area is blank' do comment = Comment.new comment.comment_paragraph_selected_area = "" - comment.paragraph_id = 2 + comment.paragraph_uuid = 2 cpp = CommentParagraphPlugin.new - prok = cpp.comment_form_extra_contents({:comment=>comment, :paragraph_id=>4}) + prok = cpp.comment_form_extra_contents({:comment=>comment, :paragraph_uuid=>4}) assert_nil /comment_paragraph_selected_area/.match(prok.call.inspect) end diff --git a/plugins/comment_paragraph/test/unit/comment_test.rb b/plugins/comment_paragraph/test/unit/comment_test.rb index 9ba97f3..c9d83f2 100644 --- a/plugins/comment_paragraph/test/unit/comment_test.rb +++ b/plugins/comment_paragraph/test/unit/comment_test.rb @@ -10,16 +10,16 @@ class CommentTest < ActiveSupport::TestCase attr_reader :article should 'return comments that belongs to a specified paragraph' do - comment1 = fast_create(Comment, :paragraph_id => 1, :source_id => article.id) - comment2 = fast_create(Comment, :paragraph_id => nil, :source_id => article.id) - comment3 = fast_create(Comment, :paragraph_id => 2, :source_id => article.id) + comment1 = fast_create(Comment, :paragraph_uuid => 1, :source_id => article.id) + comment2 = fast_create(Comment, :paragraph_uuid => nil, :source_id => article.id) + comment3 = fast_create(Comment, :paragraph_uuid => 2, :source_id => article.id) assert_equal [comment1], article.comments.in_paragraph(1) end should 'return comments that do not belongs to any paragraph' do - comment1 = fast_create(Comment, :paragraph_id => 1, :source_id => article.id) - comment2 = fast_create(Comment, :paragraph_id => nil, :source_id => article.id) - comment3 = fast_create(Comment, :paragraph_id => 2, :source_id => article.id) + comment1 = fast_create(Comment, :paragraph_uuid => 1, :source_id => article.id) + comment2 = fast_create(Comment, :paragraph_uuid => nil, :source_id => article.id) + comment3 = fast_create(Comment, :paragraph_uuid => 2, :source_id => article.id) assert_equal [comment2], article.comments.without_paragraph end diff --git a/plugins/comment_paragraph/views/comment/comment_extra.html.erb b/plugins/comment_paragraph/views/comment/comment_extra.html.erb index a775456..9935a78 100644 --- a/plugins/comment_paragraph/views/comment/comment_extra.html.erb +++ b/plugins/comment_paragraph/views/comment/comment_extra.html.erb @@ -1,3 +1,3 @@ - + diff --git a/plugins/comment_paragraph/views/comment_paragraph_plugin_profile/_comment_paragraph.html.erb b/plugins/comment_paragraph/views/comment_paragraph_plugin_profile/_comment_paragraph.html.erb index 943a8f8..b5a5347 100644 --- a/plugins/comment_paragraph/views/comment_paragraph_plugin_profile/_comment_paragraph.html.erb +++ b/plugins/comment_paragraph/views/comment_paragraph_plugin_profile/_comment_paragraph.html.erb @@ -1,13 +1,13 @@
-
+
<%= inner_html %>
-
- +
+ <%= count %>
@@ -15,28 +15,28 @@
<%= - url = { :profile => profile_identifier, :controller => 'comment_paragraph_plugin_profile', :action => 'view_comments', :paragraph_id => paragraph_id, :article_id => article_id} + url = { :profile => profile_identifier, :controller => 'comment_paragraph_plugin_profile', :action => 'view_comments', :paragraph_uuid => paragraph_uuid, :article_id => article_id} link_to_remote( '', { :url => url, :method => :post, - :condition => "!toggleParagraph(#{paragraph_id})", - :complete => "loadCompleted(#{paragraph_id})" + :condition => "!toggleParagraph(#{paragraph_uuid})", + :complete => "loadCompleted(#{paragraph_uuid})" }, { - :id => "link_to_ajax_comments_#{paragraph_id}", + :id => "link_to_ajax_comments_#{paragraph_uuid}", :'data-url' => url_for(url) } )%> -