Permalink
Browse files

[#509] Pagination broken for custom blocks

* Ensure solution works for pagination of custom blocks, portlets as well as core classes.
* Refactor how path building works
* Improved Scenario to ensure next link works
* Refactored path building to use core CMS path helpers (DRY)
  • Loading branch information...
1 parent 6b3c365 commit 6734cc9bd724847afb00dcc56174d059b5008746 @peakpg peakpg committed May 10, 2012
@@ -9,9 +9,9 @@ def cms_handler_path(*args)
end
def searchable_sections(selected = nil)
- root = Section.root.first
+ root = Section.root.first
options = [['All sections', 'all'], [root.name, root.id]]
- root.master_section_list.each { |s| options << [s.full_path, s.id] }
+ root.master_section_list.each { |s| options << [s.full_path, s.id] }
options_for_select(options, selected.to_i)
end
@@ -24,7 +24,7 @@ def page_versions(page)
text = select_tag(:version,
options_for_select(page.versions.all(:order => "version desc").map { |r|
["v#{r.version}: #{r.version_comment} by #{r.updated_by.login} at #{time_on_date(r.updated_at)}", r.version]
- }, page.version),
+ }, page.version),
:onchange => 'this.form.submit(); return false')
text << javascript_tag("$('version').selectedIndex = 0") if page.live?
text
@@ -54,7 +54,7 @@ def format_date(time)
#
# @param [String] selector The CSS selector for the checkboxes that should be mass checked/unchecked.
def check_uncheck_tag(selector)
- check_id = to_id(selector, "check")
+ check_id = to_id(selector, "check")
uncheck_id = to_id(selector, "uncheck")
content_for :html_head do
html = <<HTML
@@ -71,7 +71,7 @@ def check_uncheck_tag(selector)
javascript_tag html
end
- "#{link_to "Check All", '#', :id=>check_id}, #{link_to "Uncheck All", '#', :id=>uncheck_id}".html_safe
+ "#{link_to "Check All", '#', :id => check_id}, #{link_to "Uncheck All", '#', :id => uncheck_id}".html_safe
end
# @deprecated Use check_uncheck_tag instead. Retained for backwards compatibility w/ CMS implementations.
@@ -87,7 +87,7 @@ def link_to_check_all(selector, name="Check All")
HTML
javascript_tag html
end
- link_to name, '#', :id=>id
+ link_to name, '#', :id => id
end
# @deprecated Use check_uncheck_tag instead. Retained for backwards compatibility w/ CMS implementations.
@@ -103,7 +103,7 @@ def link_to_uncheck_all(selector, name="Uncheck All")
HTML
javascript_tag html
end
- link_to name, '#', :id=>id
+ link_to name, '#', :id => id
end
def span_tag(content)
@@ -117,7 +117,7 @@ def lt_button_wrapper(content)
<div class="lt_button_content">
<span>#{ content }</span>
</div>
- #{image_tag "cms/lt_button_r.gif", :style=>"margin-right: 10px;"}
+ #{image_tag "cms/lt_button_r.gif", :style => "margin-right: 10px;"}
</div>
LBW
button.html_safe
@@ -138,21 +138,26 @@ def group_filter
# Fetches a list of categories for a cms_drop_down. Will prompt users to create Categories/Categories types if the proper ones don't exist.
def categories_for(category_type_name, order="name")
cat_type = CategoryType.named(category_type_name).first
- categories = cat_type ? cat_type.category_list(order) : [Category.new(:name=>"-- You must first create a 'Category Type' named '#{category_type_name}'")]
- categories.empty? ? [Category.new(:name=>"-- You must first create a Category with a Category Type of '#{category_type_name}'.")]: categories
+ categories = cat_type ? cat_type.category_list(order) : [Category.new(:name => "-- You must first create a 'Category Type' named '#{category_type_name}'")]
+ categories.empty? ? [Category.new(:name => "-- You must first create a Category with a Category Type of '#{category_type_name}'.")] : categories
end
- def render_pagination(collection, collection_name, options={})
+ # Generates the HTML to render a paging control, if there is more than one page to be shown.
+ #
+ # @param [Array] collection List of content to be shown
+ # @param [Cms::ContentType] content_type The content type of the collection (used to generate links to Previous/Next)
+ # @param [Hash] options
+ def render_pagination(collection, content_type, options={})
if collection.blank?
content_tag(:div, "No Content", :class => "pagination")
else
render :partial => "cms/shared/pagination", :locals => {
- :collection => collection,
- :first_page_path => polymorphic_path(build_path_for(collection_name), {:page => 1}.merge(options)),
- :previous_page_path => polymorphic_path(build_path_for(collection_name), {:page => collection.previous_page ? collection.previous_page : 1}.merge(options)),
- :current_page_path => polymorphic_path(build_path_for(collection_name), options),
- :next_page_path => polymorphic_path(build_path_for(collection_name), {:page => collection.next_page ? collection.next_page : collection.current_page}.merge(options)),
- :last_page_path => polymorphic_path(build_path_for(collection_name), {:page => collection.total_pages}.merge(options))
+ :collection => collection,
+ :first_page_path => cms_connectable_path(content_type, {:page => 1}.merge(options)),
+ :previous_page_path => cms_connectable_path(content_type, {:page => collection.previous_page ? collection.previous_page : 1}.merge(options)),
+ :current_page_path => cms_connectable_path(content_type, options),
+ :next_page_path => cms_connectable_path(content_type, {:page => collection.next_page ? collection.next_page : collection.current_page}.merge(options)),
+ :last_page_path => cms_connectable_path(content_type, {:page => collection.total_pages}.merge(options))
}
end
end
@@ -221,7 +226,7 @@ def edit_button(options={})
#
# @param [Path] The path or URL to link_to. Takes same types at url_for or link_to.
def add_button(path, options={})
- classes = "button"
+ classes = "button"
span_options = {:class => classes}
link_to span_tag("&nbsp;Add&nbsp;".html_safe), path, span_options
end
@@ -47,6 +47,10 @@ def cms_new_url_for(resource, options={})
send("new_#{resource_collection_name(resource).underscore.gsub('/', '_')}_url", options)
end
+ # @param [Class, String] connectable The model class (i.e. HtmlBlock) or plural collection name (html_blocks) to link to
+ # @param [Hash] options Passed to polymorphic_path
+ #
+ # @return [String] path suitable to give to link_to
def cms_connectable_path(connectable, options={})
if Portlet === connectable
cms.portlet_path(connectable)
@@ -98,11 +102,9 @@ def path_elements_for(resource)
private
+
def build_path_for(model_or_class_or_content_type)
- path = []
- path << engine_for(model_or_class_or_content_type)
- path.concat path_elements_for(model_or_class_or_content_type)
- path
+ Cms::EngineAwarePathBuilder.new(model_or_class_or_content_type).build(self)
end
# Returns the name of the collection that this resource belongs to
@@ -82,5 +82,5 @@
<% if params[:search] && @blocks.size == 0 %>
<div class="pagination">No results found for '<%= params[:search][:term] %>'</div>
<% elsif @blocks.total_pages > 1 %>
- <%= render_pagination @blocks, content_type.content_block_type, :order => params[:order], :search => params[:search] %>
+ <%= render_pagination @blocks, content_type, :order => params[:order], :search => params[:search] %>
<% end %>
@@ -50,6 +50,6 @@
<% if @views.size == 0 && params[:key_word]%>
<div class="pagination">No results found for '<%= params[:key_word] %>'</div>
<% elsif @views.total_pages > 1 %>
- <%= render_pagination @views, dynamic_view_type.resource_name %>
+ <%= render_pagination @views, dynamic_view_type %>
<% end %>
@@ -35,5 +35,5 @@
<div class="br"></div>
</div>
<% if @messages.total_pages > 1 %>
- <%= render_pagination @messages, :email_messages %>
+ <%= render_pagination @messages, Cms::EmailMessage %>
<% end %>
@@ -54,5 +54,5 @@
<div class="br"></div>
</div>
<% if @groups.total_pages > 1 %>
- <%= render_pagination @groups, :groups %>
+ <%= render_pagination @groups, Cms::Group %>
<% end %>
@@ -49,5 +49,5 @@
</div>
</div>
<% if @taggings.total_pages > 1 %>
- <%= render_pagination @taggings, :tag, {:id => @content_block} %>
+ <%= render_pagination @taggings, Cms::Tag, {:id => @content_block} %>
<% end %>
@@ -57,6 +57,6 @@
<% if @users.size == 0 && params[:key_word]%>
<div class="pagination">No results found for '<%= params[:key_word] %>'</div>
<% elsif @users.total_pages > 1 %>
- <%= render_pagination @users, :users %>
+ <%= render_pagination @users, Cms::User %>
<% end %>
@@ -60,6 +60,8 @@ Feature: Manage Content Blocks
Given there are multiple pages of products in the Content Library
When I request /cms/products
Then I should see the paging controls
+ And I click on "next_page_link"
+ Then I should see the second page of content
@@ -43,5 +43,11 @@ Feature: Manage Html Blocks
Then the response should be 200
And the page header should be "View Text"
And I should see "Used on: 1 page"
-
+
+ Scenario: Multiple Pages
+ Given there are multiple pages of html blocks in the Content Library
+ When I request /cms/html_blocks
+ Then I should see the paging controls
+ And I click on "next_page_link"
+ Then I should see the second page of content
@@ -0,0 +1,15 @@
+Feature: Email Messages
+ CMS Admins should be able to see sent email messages in the UI
+
+ Background:
+ Given I am logged in as a Content Editor
+
+
+ Scenario: Multiple Pages
+ Given there are 20 send email messages
+ When I am at /cms/email_messages
+ Then I should see "Displaying 1 - 15 of 20"
+ When I click on "next_page_link"
+ Then I should see "Displaying 16 - 20 of 20"
+
+
@@ -29,4 +29,11 @@ Feature: Manage Groups
And I press "Save"
Then I should see "Authenticated Users"
Then I click on "Authenticated Users"
- And the new group should have neither edit nor publish permissions
+ And the new group should have neither edit nor publish permissions
+
+ Scenario: Multiple Pages of Groups
+ Given there are 20 groups
+ When I am at /cms/groups
+ Then I should see "Displaying 1 - 15 of 20"
+ When I click on "next_page_link"
+ Then I should see "Displaying 16 - 20 of 20"
@@ -29,6 +29,13 @@ Feature: Manage Users
| testuser | different |
Then I should see a page titled "Home"
+ Scenario: Multiple Pages of Users
+ Given there are 20 users
+ When I am at /cms/users
+ Then I should see "Displaying 1 - 10 of 20"
+ When I click on "next_page_link"
+ Then I should see "Displaying 11 - 20 of 20"
+
@@ -97,3 +97,10 @@ Feature: Portlets
Then the response should be 200
And the page header should be "View Portlet 'Hello World'"
And I should see "Used on: 1 page"
+
+ Scenario: Multiple Pages
+ Given there are multiple pages of portlets in the Content Library
+ When I request /cms/portlets
+ Then I should see the paging controls
+ And I click on "next_page_link"
+ Then I should see the second page of content
@@ -14,7 +14,7 @@ def register_content_type(type)
Given /^the following products exist:$/ do |table|
# table is a | 1 | iPhone | 400 |
table.hashes.each do |row|
- Product.create!(:id=>row['id'], :name=>row['name'], :price=>row['price'])
+ Product.create!(:id => row['id'], :name => row['name'], :price => row['price'])
end
end
When /^I delete "([^"]*)"$/ do |product_name|
@@ -38,15 +38,34 @@ def register_content_type(type)
click_button "Save And Publish"
end
+Given /^there are multiple pages of portlets in the Content Library$/ do
+ per_page = Cms::Behaviors::Pagination::DEFAULT_PER_PAGE
+ (per_page * 2).times do
+ create(:portlet)
+ end
+end
+
+Given /^there are multiple pages of html blocks in the Content Library$/ do
+ per_page = Cms::Behaviors::Pagination::DEFAULT_PER_PAGE
+ two_pages_of_blocks = (per_page * 2) - Cms::HtmlBlock.count
+ two_pages_of_blocks.times do
+ create(:html_block)
+ end
+end
+
Given /^there are multiple pages of products in the Content Library$/ do
per_page = Cms::Behaviors::Pagination::DEFAULT_PER_PAGE
(per_page * 2).times do |i|
- Product.create(:name=>"Product #{i}")
+ Product.create(:name => "Product #{i}")
end
end
Then /^I should see the paging controls$/ do
assert_equal 200, page.status_code
- assert page.has_content?("Next")
- assert page.has_content?("Previous")
-end
+ assert page.has_content?("Displaying 1 - 15 of 30")
+end
+
+Then /^I should see the second page of content$/ do
+ assert_equal 200, page.status_code
+ assert page.has_content?("Displaying 16 - 30 of 30")
+end
@@ -18,4 +18,4 @@
When /^I login as:$/ do |table|
user = table.hashes.first
login_as(user['login'], user['password'])
-end
+end
@@ -10,4 +10,24 @@
assert_equal 0, group.permissions.count
assert !group.has_permission?(:edit_content)
assert !group.has_permission?(:publish_content)
+end
+
+Given /^there are (\d+) groups$/ do |i|
+ total = i.to_i - Cms::Group.count
+ total.times do
+ create(:cms_user_group)
+ end
+end
+
+Given /^there are (\d+) users$/ do |i|
+ total = i.to_i - Cms::User.count
+ total.times do
+ create(:user)
+ end
+end
+
+Given /^there are (\d+) send email messages$/ do |i|
+ i.to_i.times do
+ Cms::EmailMessage.create!(:recipients => "example@browsermedia.com")
+ end
end
Oops, something went wrong. Retry.

0 comments on commit 6734cc9

Please sign in to comment.