Commit a07289bd0c498ee05ec7ea0497570a7dc3076941
Exists in
staging
and in
42 other branches
Merge commit 'refs/merge-requests/418' of git://gitorious.org/noosfero/noosfero …
…into merge-requests/418
Showing
11 changed files
with
149 additions
and
70 deletions
Show diff stats
app/controllers/public/profile_controller.rb
@@ -210,6 +210,46 @@ class ProfileController < PublicController | @@ -210,6 +210,46 @@ class ProfileController < PublicController | ||
210 | render :partial => 'profile_network_activities', :locals => {:network_activities => @activities} | 210 | render :partial => 'profile_network_activities', :locals => {:network_activities => @activities} |
211 | end | 211 | end |
212 | 212 | ||
213 | + def more_comments | ||
214 | + activity = ActionTracker::Record.find(:first, :conditions => {:id => params[:activity], :user_id => @profile}) | ||
215 | + comments_count = activity.comments.count | ||
216 | + comment_page = (params[:comment_page] || 1).to_i | ||
217 | + comments_per_page = 5 | ||
218 | + no_more_pages = comments_count <= comment_page * comments_per_page | ||
219 | + | ||
220 | + render :update do |page| | ||
221 | + page.insert_html :bottom, 'profile-wall-activities-comments-'+params[:activity], | ||
222 | + :partial => 'comment', :collection => activity.comments.paginate(:per_page => comments_per_page, :page => comment_page) | ||
223 | + | ||
224 | + if no_more_pages | ||
225 | + page.remove 'profile-wall-activities-comments-more-'+params[:activity] | ||
226 | + else | ||
227 | + page.replace_html 'profile-wall-activities-comments-more-'+params[:activity], | ||
228 | + :partial => 'more_comments', :locals => {:activity => activity, :comment_page => comment_page} | ||
229 | + end | ||
230 | + end | ||
231 | + end | ||
232 | + | ||
233 | + def more_replies | ||
234 | + activity = Scrap.find(:first, :conditions => {:id => params[:activity], :receiver_id => @profile, :scrap_id => nil}) | ||
235 | + comments_count = activity.replies.count | ||
236 | + comment_page = (params[:comment_page] || 1).to_i | ||
237 | + comments_per_page = 5 | ||
238 | + no_more_pages = comments_count <= comment_page * comments_per_page | ||
239 | + | ||
240 | + render :update do |page| | ||
241 | + page.insert_html :bottom, 'profile-wall-activities-comments-'+params[:activity], | ||
242 | + :partial => 'profile_scrap', :collection => activity.replies.paginate(:per_page => comments_per_page, :page => comment_page), :as => :scrap | ||
243 | + | ||
244 | + if no_more_pages | ||
245 | + page.remove 'profile-wall-activities-comments-more-'+params[:activity] | ||
246 | + else | ||
247 | + page.replace_html 'profile-wall-activities-comments-more-'+params[:activity], | ||
248 | + :partial => 'more_replies', :locals => {:activity => activity, :comment_page => comment_page} | ||
249 | + end | ||
250 | + end | ||
251 | + end | ||
252 | + | ||
213 | def remove_scrap | 253 | def remove_scrap |
214 | begin | 254 | begin |
215 | scrap = current_user.person.scraps(params[:scrap_id]) | 255 | scrap = current_user.person.scraps(params[:scrap_id]) |
@@ -343,6 +383,7 @@ class ProfileController < PublicController | @@ -343,6 +383,7 @@ class ProfileController < PublicController | ||
343 | end | 383 | end |
344 | end | 384 | end |
345 | 385 | ||
386 | + | ||
346 | protected | 387 | protected |
347 | 388 | ||
348 | def check_access_to_profile | 389 | def check_access_to_profile |
@@ -393,4 +434,5 @@ class ProfileController < PublicController | @@ -393,4 +434,5 @@ class ProfileController < PublicController | ||
393 | def relations_to_include | 434 | def relations_to_include |
394 | [:image, :domains, :preferred_domain, :environment] | 435 | [:image, :domains, :preferred_domain, :environment] |
395 | end | 436 | end |
437 | + | ||
396 | end | 438 | end |
app/views/profile/_profile_activities_list.rhtml
@@ -4,7 +4,7 @@ | @@ -4,7 +4,7 @@ | ||
4 | <% if activity.kind_of?(ActionTracker::Record) %> | 4 | <% if activity.kind_of?(ActionTracker::Record) %> |
5 | <%= render :partial => 'profile_activity', :locals => { :activity => activity, :tab_action => 'wall' } if activity.visible? %> | 5 | <%= render :partial => 'profile_activity', :locals => { :activity => activity, :tab_action => 'wall' } if activity.visible? %> |
6 | <% else %> | 6 | <% else %> |
7 | - <%= render :partial => 'profile_scrap', :locals => {:scrap => activity } %> | 7 | + <%= render :partial => 'profile_scraps', :locals => { :activity => activity, :scrap => activity } %> |
8 | <% end %> | 8 | <% end %> |
9 | <% end %> | 9 | <% end %> |
10 | <% end %> | 10 | <% end %> |
app/views/profile/_profile_comments.rhtml
1 | <hr /> | 1 | <hr /> |
2 | 2 | ||
3 | -<% if activity.comments_count > 2 %> | 3 | +<ul id="profile-wall-activities-comments-<%= activity.id %>" class="profile-wall-activities-comments" > |
4 | +</ul> | ||
5 | +<% if activity.comments_count > 0 %> | ||
6 | +<div id="profile-wall-activities-comments-more-<%= activity.id %>" class="profile-wall-activities-comments" > | ||
4 | <div class='view-all-comments icon-chat'> | 7 | <div class='view-all-comments icon-chat'> |
5 | - <%= link_to(_("View all %s comments") % activity.comments_count, '#') %> | 8 | + <%= link_to_remote(_("View all %s comments") % activity.comments_count, :url => { :profile => profile.identifier, :controller => 'profile', :action => 'more_comments', :activity => activity, :comment_page => (1)}) %> |
6 | </div> | 9 | </div> |
10 | +</div> | ||
7 | <% end %> | 11 | <% end %> |
8 | - | ||
9 | -<ul class="profile-wall-activities-comments" style="<%= 'display:none;' if (activity.comments_count > 2) %>" > | ||
10 | - <%= render :partial => 'comment', :collection => activity.comments_as_thread %> | ||
11 | -</ul> | ||
12 | - | ||
13 | <%= render :partial => 'profile_comment_form', :locals => { :activity => activity, :tab_action => tab_action } %> | 12 | <%= render :partial => 'profile_comment_form', :locals => { :activity => activity, :tab_action => tab_action } %> |
app/views/profile/_profile_scrap.rhtml
@@ -16,13 +16,7 @@ | @@ -16,13 +16,7 @@ | ||
16 | </div> | 16 | </div> |
17 | </div> | 17 | </div> |
18 | 18 | ||
19 | - <% if scrap.replies.count > 2 %> | ||
20 | - <div class='view-all-comments icon-chat'> | ||
21 | - <%= link_to(_("View all %s comments") % scrap.replies.count, '#') %> | ||
22 | - </div> | ||
23 | - <% end %> | ||
24 | - | ||
25 | - <ul class="profile-wall-activities-comments scrap-replies" style="width: auto; <%= 'display:none;' if (scrap.replies.count > 2) %>" > | 19 | + <ul class="profile-wall-activities-comments scrap-replies" style="width: auto;" > |
26 | <% scrap.replies.map do |reply| %> | 20 | <% scrap.replies.map do |reply| %> |
27 | <%= render :partial => 'profile_scrap', :locals => {:scrap => reply} %> | 21 | <%= render :partial => 'profile_scrap', :locals => {:scrap => reply} %> |
28 | <% end %> | 22 | <% end %> |
app/views/profile/_profile_scraps.rhtml
1 | -NÃO DEVE APARECER | 1 | +<li class='profile-activity-item' id='profile-activity-item-<%= scrap.id %>'> |
2 | + <div class='profile-activity-image'> | ||
3 | + <%= link_to(profile_image(scrap.sender, :minor), scrap.sender.url) %> | ||
4 | + </div> | ||
5 | + <div class='profile-activity-description'> | ||
6 | + <p class='profile-activity-sender'><%= link_to scrap.sender.name, scrap.sender.url %></p> | ||
7 | + <p class='profile-activity-text'><%= txt2html scrap.content %></p> | ||
8 | + <p class='profile-activity-time'><%= time_ago_as_sentence(scrap.created_at) %></p> | ||
9 | + <div class='profile-wall-actions'> | ||
10 | + <% if logged_in? && current_person.follows?(scrap.sender) %> | ||
11 | + <span class='profile-activity-send-reply'> | ||
12 | + <%= link_to_function s_('profile|Comment'), "hide_and_show(['#profile-wall-message-response-#{scrap.id}'],['#profile-wall-reply-#{scrap.id}', '#profile-wall-reply-form-#{scrap.id}']);$('reply_content_#{scrap.id}').value='';$('reply_content_#{scrap.id}').focus();return false", :class => "profile-send-reply" %> | ||
13 | + </span> | ||
14 | + <% end %> | ||
15 | + <%= link_to_function(_('Remove'), 'remove_item_wall(this, %s, %s, %s); return false ;' % ["'.profile-activity-item'", url_for(:profile => params[:profile], :action => :remove_scrap, :scrap_id => scrap.id, :view => params[:view]).to_json, _('Are you sure you want to remove this scrap and all its replies?').to_json]) if logged_in? && user.can_control_scrap?(scrap) %> | ||
16 | + </div> | ||
17 | + </div> | ||
18 | + | ||
19 | + | ||
20 | + <ul id="profile-wall-activities-comments-<%= activity.id %>" class="profile-wall-activities-comments scrap-replies" style="width: auto;" > | ||
21 | + </ul> | ||
22 | + | ||
23 | + <% if scrap.replies.count > 0 %> | ||
24 | + <div id="profile-wall-activities-comments-more-<%= activity.id %>" class="profile-wall-activities-comments"> | ||
25 | + <div class='view-all-comments icon-chat'> | ||
26 | + <%= link_to_remote(_("View all %s comments") % scrap.replies.count, :url => { :profile => profile.identifier, :controller => 'profile', :action => 'more_replies', :activity => activity, :comment_page => (1)}) %> | ||
27 | + </div> | ||
28 | + </div> | ||
29 | + <% end %> | ||
30 | + <%= render :partial => 'profile_scrap_reply_form', :locals => { :scrap => scrap } %> | ||
31 | + <hr /> | ||
32 | +</li> | ||
2 | \ No newline at end of file | 33 | \ No newline at end of file |
public/stylesheets/application.css
@@ -5705,6 +5705,10 @@ li.profile-activity-item.upload_image .activity-gallery-images-count-1 img { | @@ -5705,6 +5705,10 @@ li.profile-activity-item.upload_image .activity-gallery-images-count-1 img { | ||
5705 | padding-left: 20px; | 5705 | padding-left: 20px; |
5706 | } | 5706 | } |
5707 | 5707 | ||
5708 | +.view-more-comments, .view-more-replies { | ||
5709 | + text-align: center; | ||
5710 | +} | ||
5711 | + | ||
5708 | /* Profile activity relative dimensions */ | 5712 | /* Profile activity relative dimensions */ |
5709 | 5713 | ||
5710 | #leave_scrap { | 5714 | #leave_scrap { |
test/functional/profile_controller_test.rb
@@ -734,7 +734,7 @@ class ProfileControllerTest < ActionController::TestCase | @@ -734,7 +734,7 @@ class ProfileControllerTest < ActionController::TestCase | ||
734 | end | 734 | end |
735 | 735 | ||
736 | should 'see the activities_items paginated' do | 736 | should 'see the activities_items paginated' do |
737 | - p1= Person.first | 737 | + p1 = create_user('some').person |
738 | ActionTracker::Record.destroy_all | 738 | ActionTracker::Record.destroy_all |
739 | 40.times{Scrap.create!(defaults_for_scrap(:sender => p1, :receiver => p1))} | 739 | 40.times{Scrap.create!(defaults_for_scrap(:sender => p1, :receiver => p1))} |
740 | login_as(p1.identifier) | 740 | login_as(p1.identifier) |
@@ -1170,6 +1170,58 @@ class ProfileControllerTest < ActionController::TestCase | @@ -1170,6 +1170,58 @@ class ProfileControllerTest < ActionController::TestCase | ||
1170 | assert_redirected_to :controller => 'account', :action => 'login' | 1170 | assert_redirected_to :controller => 'account', :action => 'login' |
1171 | end | 1171 | end |
1172 | 1172 | ||
1173 | + should "not index display activities comments" do | ||
1174 | + login_as(profile.identifier) | ||
1175 | + article = TinyMceArticle.create!(:profile => profile, :name => 'An Article about Free Software') | ||
1176 | + ActionTracker::Record.destroy_all | ||
1177 | + activity = ActionTracker::Record.create!(:user_id => profile.id, :user_type => 'Profile', :verb => 'create_article', :target_id => article.id, :target_type => 'Article', :params => {'name' => article.name, 'url' => article.url, 'lead' => article.lead, 'first_image' => article.first_image}) | ||
1178 | + 20.times {comment = fast_create(Comment, :source_id => article, :title => 'a comment', :body => 'lalala', :created_at => Time.now)} | ||
1179 | + article.reload | ||
1180 | + get :index, :profile => profile.identifier | ||
1181 | + assert_tag 'ul', :attributes => {:class => 'profile-wall-activities-comments'}, :children => {:count => 0 } | ||
1182 | + end | ||
1183 | + | ||
1184 | + should "view more comments paginated" do | ||
1185 | + login_as(profile.identifier) | ||
1186 | + article = TinyMceArticle.create!(:profile => profile, :name => 'An Article about Free Software') | ||
1187 | + ActionTracker::Record.destroy_all | ||
1188 | + activity = ActionTracker::Record.create!(:user_id => profile.id, :user_type => 'Profile', :verb => 'create_article', :target_id => article.id, :target_type => 'Article', :params => {'name' => article.name, 'url' => article.url, 'lead' => article.lead, 'first_image' => article.first_image}) | ||
1189 | + 20.times {comment = fast_create(Comment, :source_id => article, :title => 'a comment', :body => 'lalala', :created_at => Time.now)} | ||
1190 | + article.reload | ||
1191 | + assert_equal 20, article.comments.count | ||
1192 | + get :more_comments, :activity => activity.id, :comment_page => 2 | ||
1193 | + assert_response :success | ||
1194 | + assert_template '_comment' | ||
1195 | + assert_select_rjs :insert_html do | ||
1196 | + assert_select 'li', 5 # 5 comments per page | ||
1197 | + end | ||
1198 | + end | ||
1199 | + | ||
1200 | + should "not index display scraps replies" do | ||
1201 | + login_as(profile.identifier) | ||
1202 | + Scrap.destroy_all | ||
1203 | + scrap = fast_create(Scrap, :sender_id => profile.id, :receiver_id => profile.id) | ||
1204 | + 20.times {fast_create(Scrap, :sender_id => profile.id, :receiver_id => profile.id, :scrap_id => scrap.id)} | ||
1205 | + profile.reload | ||
1206 | + get :index, :profile => profile.identifier | ||
1207 | + assert_tag 'ul', :attributes => {:class => 'profile-wall-activities-comments scrap-replies'}, :children => {:count => 0 } | ||
1208 | + end | ||
1209 | + | ||
1210 | + should "view more replies paginated" do | ||
1211 | + login_as(profile.identifier) | ||
1212 | + Scrap.destroy_all | ||
1213 | + scrap = fast_create(Scrap, :sender_id => profile.id, :receiver_id => profile.id) | ||
1214 | + 20.times {fast_create(Scrap, :sender_id => profile.id, :receiver_id => profile.id, :scrap_id => scrap.id)} | ||
1215 | + profile.reload | ||
1216 | + assert_equal 20, scrap.replies.count | ||
1217 | + get :more_replies, :activity => scrap.id, :comment_page => 2 | ||
1218 | + assert_response :success | ||
1219 | + assert_template '_profile_scrap' | ||
1220 | + assert_select_rjs :insert_html do | ||
1221 | + assert_select 'li', 5 # 5 replies per page | ||
1222 | + end | ||
1223 | + end | ||
1224 | + | ||
1173 | should 'render empty response for not logged in users in check_membership' do | 1225 | should 'render empty response for not logged in users in check_membership' do |
1174 | get :check_membership | 1226 | get :check_membership |
1175 | assert_equal '', @response.body | 1227 | assert_equal '', @response.body |
@@ -1331,30 +1383,6 @@ class ProfileControllerTest < ActionController::TestCase | @@ -1331,30 +1383,6 @@ class ProfileControllerTest < ActionController::TestCase | ||
1331 | assert_equal "Comment successfully added.", assigns(:message) | 1383 | assert_equal "Comment successfully added.", assigns(:message) |
1332 | end | 1384 | end |
1333 | 1385 | ||
1334 | - should 'display comment in wall if user was removed' do | ||
1335 | - UserStampSweeper.any_instance.stubs(:current_user).returns(profile) | ||
1336 | - article = TinyMceArticle.create!(:profile => profile, :name => 'An article about free software') | ||
1337 | - to_be_removed = create_user('removed_user').person | ||
1338 | - comment = Comment.create!(:author => to_be_removed, :title => 'Test Comment', :body => 'My author does not exist =(', :source_id => article.id, :source_type => 'Article') | ||
1339 | - to_be_removed.destroy | ||
1340 | - | ||
1341 | - login_as(profile.identifier) | ||
1342 | - get :index, :profile => profile.identifier | ||
1343 | - | ||
1344 | - assert_tag :tag => 'span', :content => '(removed user)', :attributes => {:class => 'comment-user-status comment-user-status-wall icon-user-removed'} | ||
1345 | - end | ||
1346 | - | ||
1347 | - should 'display comment in wall from non logged users' do | ||
1348 | - UserStampSweeper.any_instance.stubs(:current_user).returns(profile) | ||
1349 | - article = TinyMceArticle.create!(:profile => profile, :name => 'An article about free software') | ||
1350 | - comment = Comment.create!(:name => 'outside user', :email => 'outside@localhost.localdomain', :title => 'Test Comment', :body => 'My author does not exist =(', :source_id => article.id, :source_type => 'Article') | ||
1351 | - | ||
1352 | - login_as(profile.identifier) | ||
1353 | - get :index, :profile => profile.identifier | ||
1354 | - | ||
1355 | - assert_tag :tag => 'span', :content => '(unauthenticated user)', :attributes => {:class => 'comment-user-status comment-user-status-wall icon-user-unknown'} | ||
1356 | - end | ||
1357 | - | ||
1358 | should 'add locale on mailing' do | 1386 | should 'add locale on mailing' do |
1359 | community = fast_create(Community) | 1387 | community = fast_create(Community) |
1360 | create_user_with_permission('profile_moderator_user', 'send_mail_to_members', community) | 1388 | create_user_with_permission('profile_moderator_user', 'send_mail_to_members', community) |
test/unit/comment_test.rb
@@ -285,22 +285,6 @@ class CommentTest < ActiveSupport::TestCase | @@ -285,22 +285,6 @@ class CommentTest < ActiveSupport::TestCase | ||
285 | assert_equal [c1,c3], c.reload.children | 285 | assert_equal [c1,c3], c.reload.children |
286 | end | 286 | end |
287 | 287 | ||
288 | - should "return activities comments as a thread" do | ||
289 | - person = fast_create(Person) | ||
290 | - a = TextileArticle.create!(:profile => person, :name => 'My article', :body => 'Article body') | ||
291 | - c0 = Comment.create!(:source => a, :body => 'My comment', :author => person) | ||
292 | - c1 = Comment.create!(:reply_of_id => c0.id, :source => a, :body => 'bla', :author => person) | ||
293 | - c2 = Comment.create!(:reply_of_id => c1.id, :source => a, :body => 'bla', :author => person) | ||
294 | - c3 = Comment.create!(:reply_of_id => c0.id, :source => a, :body => 'bla', :author => person) | ||
295 | - c4 = Comment.create!(:source => a, :body => 'My comment', :author => person) | ||
296 | - result = a.activity.comments_as_thread | ||
297 | - assert_equal c0, result[0] | ||
298 | - assert_equal [c1, c3], result[0].replies | ||
299 | - assert_equal [c2], result[0].replies[0].replies | ||
300 | - assert_equal c4, result[1] | ||
301 | - assert result[1].replies.empty? | ||
302 | - end | ||
303 | - | ||
304 | should 'provide author url for authenticated user' do | 288 | should 'provide author url for authenticated user' do |
305 | author = Person.new | 289 | author = Person.new |
306 | author.expects(:url).returns('http://blabla.net/author') | 290 | author.expects(:url).returns('http://blabla.net/author') |
vendor/plugins/action_tracker_has_comments/init.rb
@@ -3,22 +3,13 @@ | @@ -3,22 +3,13 @@ | ||
3 | Rails.configuration.to_prepare do | 3 | Rails.configuration.to_prepare do |
4 | ActionTracker::Record.module_eval do | 4 | ActionTracker::Record.module_eval do |
5 | 5 | ||
6 | - has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :finder_sql => 'SELECT * FROM comments WHERE #{conditions_for_comments} ORDER BY created_at ASC', :counter_sql => 'SELECT * FROM comments WHERE #{conditions_for_comments}' | 6 | + has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, |
7 | + :finder_sql => 'SELECT * FROM comments WHERE #{conditions_for_comments} ORDER BY created_at ASC', | ||
8 | + :counter_sql => 'SELECT COUNT(*) FROM comments WHERE #{conditions_for_comments}' | ||
7 | 9 | ||
8 | def conditions_for_comments | 10 | def conditions_for_comments |
9 | type, id = (self.target_type == 'Article' ? ['Article', self.target_id] : [self.class.to_s, self.id]) | 11 | type, id = (self.target_type == 'Article' ? ['Article', self.target_id] : [self.class.to_s, self.id]) |
10 | - "source_type = '#{type}' AND source_id = '#{id}'" | ||
11 | - end | ||
12 | - | ||
13 | - def comments_as_thread | ||
14 | - result = {} | ||
15 | - root = [] | ||
16 | - self.comments.each do |c| | ||
17 | - c.replies = [] | ||
18 | - result[c.id] ||= c | ||
19 | - c.reply_of_id.nil? ? root << c : result[c.reply_of_id].replies << c | ||
20 | - end | ||
21 | - root | 12 | + "source_type = '#{type}' AND source_id = '#{id}' AND reply_of_id IS NULL" |
22 | end | 13 | end |
23 | 14 | ||
24 | end | 15 | end |