Permalink
Browse files

using kaminari for paging trough notices

  • Loading branch information...
1 parent 5ab6571 commit dffb8d28ed5919128ade70f7aa24dc07b8135cb5 @martinciu martinciu committed Oct 19, 2011
View
@@ -20,6 +20,7 @@ gem 'hoptoad_notifier', "~> 2.4"
gem 'actionmailer_inline_css', "~> 1.3.0"
gem 'rpm_contrib'
gem 'newrelic_rpm'
+gem 'kaminari'
platform :ruby do
gem 'bson_ext', '~> 1.4.0'
View
@@ -80,6 +80,8 @@ GEM
inherited_resources (1.3.0)
has_scope (~> 0.5.0)
responders (~> 0.6.0)
+ kaminari (0.12.4)
+ rails (>= 3.0.0)
libxml-ruby (2.2.2)
lighthouse-api (2.0)
activeresource (>= 3.0.0)
@@ -226,6 +228,7 @@ DEPENDENCIES
hoptoad_notifier (~> 2.4)
htmlentities (~> 4.3.0)
inherited_resources
+ kaminari
lighthouse-api
mongoid (= 2.1.2)
mongoid_rails_migrations
@@ -31,7 +31,7 @@ def all
def show
page = (params[:notice] || @problem.notices_count)
page = 1 if page.to_i.zero?
- @notices = @problem.notices.paginate(:page => page, :per_page => 1)
+ @notices = @problem.notices.page(page.to_i).per(1)
@notice = @notices.first
@comment = Comment.new
if request.headers['X-PJAX']
@@ -43,9 +43,7 @@
%h4= @notice.try(:message)
-= will_paginate @notices, :param_name => :notice, :page_links => false, :class => 'notice-pagination'
-viewing occurrence #{@notices.current_page} of #{@notices.total_pages}
-.notice-pagination-loader= image_tag 'loader.gif'
+= paginate @notices, :param_name => :notice, :theme => :notices
.tab-bar
%ul
@@ -0,0 +1,9 @@
+-# Link to the "First" page
+-# available local variables
+-# url: url to the first page
+-# current_page: a page object for the currently displayed page
+-# num_pages: total number of pages
+-# per_page: number of items to fetch per page
+-# remote: data-remote
+%span.first
+ = link_to_unless current_page.first?, raw(t 'views.pagination.first'), url, :remote => remote
@@ -0,0 +1,8 @@
+-# Non-link tag that stands for skipped pages...
+-# available local variables
+-# current_page: a page object for the currently displayed page
+-# num_pages: total number of pages
+-# per_page: number of items to fetch per page
+-# remote: data-remote
+%span.page.gap
+ = raw(t 'views.pagination.truncate')
@@ -0,0 +1,9 @@
+-# Link to the "Last" page
+-# available local variables
+-# url: url to the last page
+-# current_page: a page object for the currently displayed page
+-# num_pages: total number of pages
+-# per_page: number of items to fetch per page
+-# remote: data-remote
+%span.last
+ = link_to_unless current_page.last?, raw(t 'views.pagination.last'), url, {:remote => remote}
@@ -0,0 +1,2 @@
+~ link_to_unless current_page.last?, raw('Next →'), url, :class => "next_page", :rel => "next", :remote => remote do |name|
+ ~ content_tag :span, name, :class => 'next_page disabled'
@@ -0,0 +1,10 @@
+-# Link showing page number
+-# available local variables
+-# page: a page object for "this" page
+-# url: url to this page
+-# current_page: a page object for the currently displayed page
+-# num_pages: total number of pages
+-# per_page: number of items to fetch per page
+-# remote: data-remote
+%span{:class => "page#{' current' if page.current?}"}
+ = link_to_unless page.current?, page, url, {:remote => remote, :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil}
@@ -0,0 +1,13 @@
+-# The container tag
+-# available local variables
+-# current_page: a page object for the currently displayed page
+-# num_pages: total number of pages
+-# per_page: number of items to fetch per page
+-# remote: data-remote
+-# paginator: the paginator that renders the pagination tags inside
+= paginator.render do
+ .notice-pagination<
+ = prev_page_tag
+ = next_page_tag
+.notice-pagination-loader= image_tag 'loader.gif'
+viewing occurrence #{current_page} of #{num_pages}
@@ -0,0 +1,2 @@
+~ link_to_unless current_page.first?, raw('← Previous'), url, :class => "previous_page", :rel => "prev", :remote => remote do |name|
+ ~ content_tag :span, name, :class => 'previous_page disabled'
@@ -8,7 +8,7 @@
assign :problem, problem
assign :comment, comment
assign :app, problem.app
- assign :notices, err.notices.paginate(:page => 1, :per_page => 1)
+ assign :notices, err.notices.page(1).per(1)
assign :notice, err.notices.first
controller.stub(:current_user) { Factory(:user) }
end

0 comments on commit dffb8d2

Please sign in to comment.