diff --git a/plugins/context_content/controllers/profile/context_content_plugin_profile_controller.rb b/plugins/context_content/controllers/profile/context_content_plugin_profile_controller.rb new file mode 100644 index 0000000..f0cd8ec --- /dev/null +++ b/plugins/context_content/controllers/profile/context_content_plugin_profile_controller.rb @@ -0,0 +1,15 @@ +class ContextContentPluginProfileController < ProfileController + append_view_path File.join(File.dirname(__FILE__) + '/../../views') + + def view_content + block = Block.find(params[:id]) + p = params[:page].to_i + contents = block.contents(profile.articles.find(params[:article_id]), p) + + render :update do |page| + page.replace_html "context_content_#{block.id}", :file => "blocks/context_content", :locals => {:block => block, :contents => contents} + page.replace_html "context_content_more_#{block.id}", :partial => 'blocks/more', :locals => {:block => block, :contents => contents, :article_id => params[:article_id] } + end + end + +end diff --git a/plugins/context_content/lib/context_content_block.rb b/plugins/context_content/lib/context_content_block.rb index fe46e3e..9c80279 100644 --- a/plugins/context_content/lib/context_content_block.rb +++ b/plugins/context_content/lib/context_content_block.rb @@ -37,28 +37,36 @@ class ContextContentBlock < Block end end - def contents(page) + def contents(page, p=1) + return @children unless @children.blank? if page - children = page.children.with_types(types).limit(limit) - (children.blank? && show_parent_content) ? contents(page.parent) : children + @children = page.children.with_types(types).paginate(:per_page => limit, :page => p) + (@children.blank? && show_parent_content) ? contents(page.parent) : @children else nil end end -# FIXME -# def footer -# lambda do -# link_to(_('View all'), '') -# end -# end + def footer + block = self + lambda do + if @page + contents = block.contents(@page) + content_tag('div', + render(:partial => 'blocks/more', :locals => {:block => block, :contents => contents, :article_id => @page.id}), :id => "context_content_more_#{block.id}", :class => "more_button") + else + '' + end + end + end def content(args={}) block = self lambda do contents = block.contents(@page) if !contents.blank? - render :file => 'blocks/context_content', :locals => {:block => block, :contents => contents} + block_title(block.title) + content_tag('div', + render(:file => 'blocks/context_content', :locals => {:block => block, :contents => contents}), :class => 'contents', :id => "context_content_#{block.id}") else '' end diff --git a/plugins/context_content/test/unit/context_content_block_test.rb b/plugins/context_content/test/unit/context_content_block_test.rb index c4e55c6..0ae677b 100644 --- a/plugins/context_content/test/unit/context_content_block_test.rb +++ b/plugins/context_content/test/unit/context_content_block_test.rb @@ -27,6 +27,8 @@ class ContextContentBlockTest < ActiveSupport::TestCase should 'render context content block view' do @page = fast_create(Folder) article = fast_create(TinyMceArticle, :parent_id => @page.id) + expects(:block_title).with(@block.title).returns('').once + expects(:content_tag).returns('').once expects(:render).with(:file => 'blocks/context_content', :locals => {:block => @block, :contents => [article]}) instance_eval(&@block.content) end @@ -43,7 +45,7 @@ class ContextContentBlockTest < ActiveSupport::TestCase article1 = fast_create(TinyMceArticle, :parent_id => folder.id) article2 = fast_create(TinyMceArticle, :parent_id => folder.id) article3 = fast_create(TinyMceArticle, :parent_id => folder.id) - assert_equivalent [article1, article2], @block.contents(folder) + assert_equal 2, @block.contents(folder).length end should 'return parent children if page has no children' do @@ -94,4 +96,24 @@ class ContextContentBlockTest < ActiveSupport::TestCase instance_eval(&@block.content_image(content)) end + should 'do not display pagination links if page is nil' do + @page = nil + assert_equal '', instance_eval(&@block.footer) + end + + should 'do not display pagination links if it has until one page' do + assert_equal '', instance_eval(&@block.footer) + end + + should 'display pagination links if it has more than one page' do + @block.limit = 2 + @page = fast_create(Folder) + article1 = fast_create(TinyMceArticle, :parent_id => @page.id) + article2 = fast_create(TinyMceArticle, :parent_id => @page.id) + article3 = fast_create(TinyMceArticle, :parent_id => @page.id) + expects(:content_tag).once + expects(:render).with(:partial => 'blocks/more', :locals => {:block => @block, :contents => [article1, article2], :article_id => @page.id}).once + instance_eval(&@block.footer) + end + end diff --git a/plugins/context_content/views/blocks/_more.rhtml b/plugins/context_content/views/blocks/_more.rhtml new file mode 100644 index 0000000..21abedf --- /dev/null +++ b/plugins/context_content/views/blocks/_more.rhtml @@ -0,0 +1,4 @@ +<% if contents.total_pages > 1 %> + <%= link_to_remote(nil, :url => {:id => block.id, :controller => 'context_content_plugin_profile', :action => 'view_content', :page => contents.previous_page, :article_id => article_id }, :html => {:class => "button icon-button icon-left #{contents.previous_page ? '':'disabled'}"}, :condition => "#{!contents.previous_page.nil?}", :success => "jQuery('#context_content_#{block.id}').effect('slide', {direction: 'left'});" )%> + <%= link_to_remote(nil, :url => {:id => block.id, :controller => 'context_content_plugin_profile', :action => 'view_content', :page => contents.next_page, :article_id => article_id }, :html => {:class => "button icon-button icon-right #{contents.next_page ? '':'disabled'}"}, :condition => "#{!contents.next_page.nil?}", :success => "jQuery('#context_content_#{block.id}').effect('slide', {direction: 'right'});" )%> +<% end %> diff --git a/plugins/context_content/views/blocks/context_content.rhtml b/plugins/context_content/views/blocks/context_content.rhtml index 19b2e0f..60c7c9b 100644 --- a/plugins/context_content/views/blocks/context_content.rhtml +++ b/plugins/context_content/views/blocks/context_content.rhtml @@ -1,6 +1,3 @@ -<%= block_title(block.title) %> - -
<% contents.each do |content| %> @@ -13,4 +10,3 @@ <% end %> -
-- libgit2 0.21.2