Skip to content

Commit

Permalink
using kaminari for paging trough notices
Browse files Browse the repository at this point in the history
  • Loading branch information
martinciu committed Oct 19, 2011
1 parent 5ab6571 commit dffb8d2
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 5 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -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'
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/errs_controller.rb
Expand Up @@ -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']
Expand Down
4 changes: 1 addition & 3 deletions app/views/errs/show.html.haml
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions app/views/kaminari/notices/_first_page.html.haml
@@ -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
8 changes: 8 additions & 0 deletions app/views/kaminari/notices/_gap.html.haml
@@ -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')
9 changes: 9 additions & 0 deletions app/views/kaminari/notices/_last_page.html.haml
@@ -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}
2 changes: 2 additions & 0 deletions app/views/kaminari/notices/_next_page.html.haml
@@ -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'
10 changes: 10 additions & 0 deletions app/views/kaminari/notices/_page.html.haml
@@ -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}
13 changes: 13 additions & 0 deletions app/views/kaminari/notices/_paginator.html.haml
@@ -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}
2 changes: 2 additions & 0 deletions app/views/kaminari/notices/_prev_page.html.haml
@@ -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'
2 changes: 1 addition & 1 deletion spec/views/errs/show.html.haml_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit dffb8d2

Please sign in to comment.