diff --git a/controllers/public/proposals_discussion_plugin_public_controller.rb b/controllers/public/proposals_discussion_plugin_public_controller.rb new file mode 100644 index 0000000..8e64ae1 --- /dev/null +++ b/controllers/public/proposals_discussion_plugin_public_controller.rb @@ -0,0 +1,35 @@ +class ProposalsDiscussionPluginPublicController < ApplicationController + + needs_profile + + before_filter :set_rand_cookie + + def load_proposals + holder = profile.articles.find(params[:holder_id]) + page = (params[:page] || 1).to_i + + set_seed + proposals = holder.proposals.includes(:parent, :profile).reorder('random()') + proposals = proposals.page(page).per_page(5) + + unless proposals.empty? + render :partial => 'content_viewer/proposals_list_content', :locals => {:proposals => proposals, :holder => holder, :next_page => page+1} + else + render :text => '' + end + end + + private + + def set_seed + #XXX postgresql specific + seed_val = profile.connection.quote(cookies[:_noosfero_proposals_discussion_rand_seed]) + profile.connection.execute("select setseed(#{seed_val})") + end + + def set_rand_cookie + return if cookies[:_noosfero_proposals_discussion_rand_seed].present? + cookies[:_noosfero_proposals_discussion_rand_seed] = {value: rand, expires: Time.now + 900} + end + +end diff --git a/public/jquery.jscroll.min.js b/public/jquery.jscroll.min.js new file mode 100644 index 0000000..f39469a --- /dev/null +++ b/public/jquery.jscroll.min.js @@ -0,0 +1,15 @@ +/*! + * jScroll - jQuery Plugin for Infinite Scrolling / Auto-Paging - v2.2.4 + * http://jscroll.com/ + * + * Copyright 2011-2013, Philip Klauzinski + * http://klauzinski.com/ + * Dual licensed under the MIT and GPL Version 2 licenses. + * http://jscroll.com/#license + * http://www.opensource.org/licenses/mit-license.php + * http://www.gnu.org/licenses/gpl-2.0.html + * + * @author Philip Klauzinski + * @requires jQuery v1.4.3+ + */ +(function(b){b.jscroll={defaults:{debug:false,autoTrigger:true,autoTriggerUntil:false,loadingHtml:"Loading...",padding:0,nextSelector:"a:last",contentSelector:"",pagingSelector:"",callback:false}};var a=function(e,g){var o=e.data("jscroll"),n=(typeof g==="function")?{callback:g}:g,p=b.extend({},b.jscroll.defaults,n,o||{}),c=(e.css("overflow-y")==="visible"),l=e.find(p.nextSelector).first(),v=b(window),h=b("body"),q=c?v:e,m=b.trim(l.attr("href")+" "+p.contentSelector);e.data("jscroll",b.extend({},o,{initialized:true,waiting:false,nextHref:m}));r();k();t();function k(){var x=b(p.loadingHtml).filter("img").attr("src");if(x){var w=new Image();w.src=x}}function r(){if(!e.find(".jscroll-inner").length){e.contents().wrapAll('
')}}function d(w){if(p.pagingSelector){var x=w.closest(p.pagingSelector).hide()}else{var x=w.parent().not(".jscroll-inner,.jscroll-added").addClass("jscroll-next-parent").hide();if(!x.length){w.wrap('
').parent().hide()}}}function j(){return q.unbind(".jscroll").removeData("jscroll").find(".jscroll-inner").children().unwrap().filter(".jscroll-added").children().unwrap()}function i(){r();var D=e.find("div.jscroll-inner").first(),B=e.data("jscroll"),C=parseInt(e.css("borderTopWidth")),y=isNaN(C)?0:C,x=parseInt(e.css("paddingTop"))+y,A=c?q.scrollTop():e.offset().top,z=D.length?D.offset().top:0,w=Math.ceil(A-z+q.height()+x);if(!B.waiting&&w+p.padding>=D.outerHeight()){f("info","jScroll:",D.outerHeight()-w,"from bottom. Loading next request...");return u()}}function s(w){w=w||e.data("jscroll");if(!w||!w.nextHref){f("warn","jScroll: nextSelector not found - destroying");j();return false}else{t();return true}}function t(){var w=e.find(p.nextSelector).first();if(p.autoTrigger&&(p.autoTriggerUntil===false||p.autoTriggerUntil>0)){d(w);if(h.height()<=v.height()){i()}q.unbind(".jscroll").bind("scroll.jscroll",function(){return i()});if(p.autoTriggerUntil>0){p.autoTriggerUntil--}}else{q.unbind(".jscroll");w.bind("click.jscroll",function(){d(w);u();return false})}}function u(){var x=e.find("div.jscroll-inner").first(),w=e.data("jscroll");w.waiting=true;x.append('
').children(".jscroll-added").last().html('
'+p.loadingHtml+"
");return e.animate({scrollTop:x.outerHeight()},0,function(){x.find("div.jscroll-added").last().load(w.nextHref,function(A,z,B){if(z==="error"){return j()}var y=b(this).find(p.nextSelector).first();w.waiting=false;w.nextHref=y.attr("href")?b.trim(y.attr("href")+" "+p.contentSelector):false;b(".jscroll-next-parent",e).remove();s();if(p.callback){p.callback.call(this)}f("dir",w)})})}function f(w){if(p.debug&&typeof console==="object"&&(typeof w==="object"||typeof console[w]==="function")){if(typeof w==="object"){var y=[];for(var x in w){if(typeof console[x]==="function"){y=(w[x].length)?w[x]:[w[x]];console[x].apply(console,y)}else{console.log.apply(console,y)}}}else{console[w].apply(console,Array.prototype.slice.call(arguments,1))}}}b.extend(e.jscroll,{destroy:j});return e};b.fn.jscroll=function(c){return this.each(function(){var f=b(this),e=f.data("jscroll");if(e&&e.initialized){return}var d=new a(f,c)})}})(jQuery); \ No newline at end of file diff --git a/views/content_viewer/_proposals_list.html.erb b/views/content_viewer/_proposals_list.html.erb index 57f5cd0..fc3aabe 100644 --- a/views/content_viewer/_proposals_list.html.erb +++ b/views/content_viewer/_proposals_list.html.erb @@ -1,4 +1,17 @@ + + +
- <%= render :partial => 'content_viewer/proposal_card', :collection => holder.proposals.includes(:parent, :profile) %> -
+
+ Loading<%= _("Loading...") %> + <%= link_to '', url_for({:controller => 'proposals_discussion_plugin_public', :action => 'load_proposals', :holder_id => holder.id, :profile => profile.identifier }) %> +
diff --git a/views/content_viewer/_proposals_list_content.html.erb b/views/content_viewer/_proposals_list_content.html.erb new file mode 100644 index 0000000..f772562 --- /dev/null +++ b/views/content_viewer/_proposals_list_content.html.erb @@ -0,0 +1,5 @@ +<%= render :partial => 'content_viewer/proposal_card', :collection => proposals %> + +
+ <%= link_to _('More'), url_for({:controller => 'proposals_discussion_plugin_public', :action => 'load_proposals', :holder_id => holder.id, :profile => profile.identifier, :page => next_page }) %> +
diff --git a/views/content_viewer/topic.html.erb b/views/content_viewer/topic.html.erb index a326e6d..06198bc 100644 --- a/views/content_viewer/topic.html.erb +++ b/views/content_viewer/topic.html.erb @@ -25,8 +25,3 @@
<%= render :partial => 'content_viewer/proposals_list', :locals => {:holder => @page} %> - -
- <%= render :partial => 'content_viewer/proposal_card', :collection => @page.proposals.includes(:parent, :profile) %> -
-
-- libgit2 0.21.2