[Git][noosfero/noosfero][master] 11 commits: Makes comments load on scroll

Rodrigo Souto gitlab at mg.gitlab.com
Sat May 26 09:46:24 BRT 2018


Rodrigo Souto pushed to branch master at Noosfero / noosfero


Commits:
cbe70e3c by Matheus Richard at 2018-05-11T15:55:57Z
Makes comments load on scroll

- - - - -
192cb32b by Matheus Richard at 2018-05-11T15:56:12Z
Rewrites load more comments function in jquery

- - - - -
cafc5234 by Matheus Richard at 2018-05-11T16:32:52Z
Removes hardcoded profile

- - - - -
98e98635 by Matheus Richard at 2018-05-11T19:31:58Z
Removes view_more_comments partial

- - - - -
e32188a6 by Alax Alves at 2018-05-17T20:27:36Z
Removing unnecessary comment pagination test

- - - - -
275e02e9 by Matheus Richard at 2018-05-17T20:29:07Z
Merge branch 'load-comments-on-scroll' into 'load-comments-on-scroll'

Removing unnecessary test

See merge request MatheusRichard/noosfero!1
- - - - -
c42e56e9 by Matheus Richard at 2018-05-18T12:29:13Z
Merge branch 'master' of https://gitlab.com/noosfero/noosfero into load-comments-on-scroll

- - - - -
d1b4dd0f by Alax Alves at 2018-05-18T19:11:39Z
Merge branch 'master' of https://gitlab.com/noosfero/noosfero into load-comments-on-scroll

- - - - -
99cbdeaa by Matheus Richard at 2018-05-25T12:10:42Z
Merge branch 'master' of https://gitlab.com/noosfero/noosfero into load-comments-on-scroll

- - - - -
09be9f39 by Matheus Richard at 2018-05-25T22:47:38Z
Merge branch 'master' of https://gitlab.com/noosfero/noosfero into load-comments-on-scroll

- - - - -
6b48387c by Rodrigo Souto at 2018-05-26T12:46:19Z
Merge branch 'load-comments-on-scroll' into 'master'

#49 - Comments with infinite scrolling pagination

See merge request noosfero/noosfero!1464
- - - - -


6 changed files:

- app/controllers/public/content_viewer_controller.rb
- − app/views/comment/_view_more_comments.html.erb
- app/views/content_viewer/view_page.html.erb
- public/javascripts/application.js
- + public/javascripts/upload-file.js
- test/functional/content_viewer_controller_test.rb


Changes:

=====================================
app/controllers/public/content_viewer_controller.rb
=====================================
--- a/app/controllers/public/content_viewer_controller.rb
+++ b/app/controllers/public/content_viewer_controller.rb
@@ -97,9 +97,6 @@ class ContentViewerController < ApplicationController
                        partial: 'comment/comment', collection: @comments, as: :comment
 
       page.remove "view-more-comments"
-
-      page.insert_html :after, "article-comments-list",
-                       partial: 'comment/view_more_comments' if @curr_page < @total_pages
     end
   end
 


=====================================
app/views/comment/_view_more_comments.html.erb deleted
=====================================
--- a/app/views/comment/_view_more_comments.html.erb
+++ /dev/null
@@ -1 +0,0 @@
-<%= link_to_remote font_awesome(:down_arrow, _('View more')), url: url_for(action: 'view_more_comments', page: @page.id, id: @page.id, comment_page: @curr_page + 1), html: { id: "view-more-comments" } %>


=====================================
app/views/content_viewer/view_page.html.erb
=====================================
--- a/app/views/content_viewer/view_page.html.erb
+++ b/app/views/content_viewer/view_page.html.erb
@@ -72,14 +72,13 @@
       <% end %>
     </div>
 
-    <ul class="article-comments-list" id="article-comments-list">
+    <ul class="article-comments-list" id="article-comments-list" data-page="<%= @page.id %>" 
+        data-comment-page="<%= @curr_page %>" data-profile="<%= @profile.identifier %>"
+    >
       <% if @comments.present? %>
         <%= render :partial => 'comment/comment', :collection => @comments %>
       <% end %>
     </ul>
-    <% if @comments.present? && @curr_page < @total_pages %>
-      <%= render partial: 'comment/view_more_comments' %>
-    <% end %>
   </div><!-- end class="comments" -->
 <% end %>
 


=====================================
public/javascripts/application.js
=====================================
--- a/public/javascripts/application.js
+++ b/public/javascripts/application.js
@@ -44,6 +44,7 @@
 *= require categories_selector.js
 *= require comments.js
 *= require offline_page.js
+*= require upload-file.js
 *= require edit-in-place.js
 *= require invite_event.js
 *


=====================================
public/javascripts/upload-file.js
=====================================
--- /dev/null
+++ b/public/javascripts/upload-file.js
@@ -0,0 +1,25 @@
+function loadMoreComments() {
+  let commentList = $('#article-comments-list');
+  let pageId = commentList.data('page');
+  let profile = commentList.data('profile');
+  let nextCommentPage = commentList.data('comment-page') + 1;
+
+  $.get(`/${profile}/${pageId}/view_more_comments`, {
+    comment_page: nextCommentPage,
+    id: pageId, 
+    dataType: 'json'
+  })
+  .done(function() {
+    commentList.data('comment-page', nextCommentPage);
+    $(window).bind('scroll', bindScroll);
+  });
+}
+
+function bindScroll() {
+  let loadingPoint = $(document).height() - 300;
+  if ($(window).scrollTop() + $(window).height() > loadingPoint) {
+    $(window).unbind('scroll');
+    loadMoreComments();
+  }
+}
+$(window).scroll(bindScroll);


=====================================
test/functional/content_viewer_controller_test.rb
=====================================
--- a/test/functional/content_viewer_controller_test.rb
+++ b/test/functional/content_viewer_controller_test.rb
@@ -1432,20 +1432,6 @@ class ContentViewerControllerTest < ActionController::TestCase
     assert_not_includes assigns(:comments), c3
   end
 
-  should 'display pagination links of comments' do
-    article = fast_create(Article, :profile_id => profile.id)
-    for n in 1..15
-      article.comments.create!(:author => profile, :title => "some title #{n}", :body => 'some body #{n}')
-    end
-    assert_equal 15, article.comments.count
-
-    get 'view_page', :profile => profile.identifier, :page => article.path.split('/')
-
-    assert_tag :tag => 'a', :attributes => { :id => 'view-more-comments' },
-                                             :descendant => { :tag => 'i',
-                                                              :attributes => { :class => 'fa fa-chevron-down' }}
-  end
-
   should 'not escape acceptable HTML in list of blog posts' do
     login_as('testinguser')
     blog = Blog.create!(:name => 'A blog test', :profile => profile)



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/95613c69834b9a1a1ed3b8bad1c5028ae196039a...6b48387cdc3d4a645e1b4b212913ed974382d052

-- 
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/95613c69834b9a1a1ed3b8bad1c5028ae196039a...6b48387cdc3d4a645e1b4b212913ed974382d052
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20180526/1c0db4be/attachment-0001.html>


More information about the Noosfero-dev mailing list