Commit dffb8d28ed5919128ade70f7aa24dc07b8135cb5

Authored by Marcin Ciunelis
1 parent 5ab65717
Exists in master and in 1 other branch production

using kaminari for paging trough notices

@@ -20,6 +20,7 @@ gem 'hoptoad_notifier', "~> 2.4" @@ -20,6 +20,7 @@ gem 'hoptoad_notifier', "~> 2.4"
20 gem 'actionmailer_inline_css', "~> 1.3.0" 20 gem 'actionmailer_inline_css', "~> 1.3.0"
21 gem 'rpm_contrib' 21 gem 'rpm_contrib'
22 gem 'newrelic_rpm' 22 gem 'newrelic_rpm'
  23 +gem 'kaminari'
23 24
24 platform :ruby do 25 platform :ruby do
25 gem 'bson_ext', '~> 1.4.0' 26 gem 'bson_ext', '~> 1.4.0'
@@ -80,6 +80,8 @@ GEM @@ -80,6 +80,8 @@ GEM
80 inherited_resources (1.3.0) 80 inherited_resources (1.3.0)
81 has_scope (~> 0.5.0) 81 has_scope (~> 0.5.0)
82 responders (~> 0.6.0) 82 responders (~> 0.6.0)
  83 + kaminari (0.12.4)
  84 + rails (>= 3.0.0)
83 libxml-ruby (2.2.2) 85 libxml-ruby (2.2.2)
84 lighthouse-api (2.0) 86 lighthouse-api (2.0)
85 activeresource (>= 3.0.0) 87 activeresource (>= 3.0.0)
@@ -226,6 +228,7 @@ DEPENDENCIES @@ -226,6 +228,7 @@ DEPENDENCIES
226 hoptoad_notifier (~> 2.4) 228 hoptoad_notifier (~> 2.4)
227 htmlentities (~> 4.3.0) 229 htmlentities (~> 4.3.0)
228 inherited_resources 230 inherited_resources
  231 + kaminari
229 lighthouse-api 232 lighthouse-api
230 mongoid (= 2.1.2) 233 mongoid (= 2.1.2)
231 mongoid_rails_migrations 234 mongoid_rails_migrations
app/controllers/errs_controller.rb
@@ -31,7 +31,7 @@ class ErrsController < ApplicationController @@ -31,7 +31,7 @@ class ErrsController < ApplicationController
31 def show 31 def show
32 page = (params[:notice] || @problem.notices_count) 32 page = (params[:notice] || @problem.notices_count)
33 page = 1 if page.to_i.zero? 33 page = 1 if page.to_i.zero?
34 - @notices = @problem.notices.paginate(:page => page, :per_page => 1) 34 + @notices = @problem.notices.page(page.to_i).per(1)
35 @notice = @notices.first 35 @notice = @notices.first
36 @comment = Comment.new 36 @comment = Comment.new
37 if request.headers['X-PJAX'] 37 if request.headers['X-PJAX']
app/views/errs/show.html.haml
@@ -43,9 +43,7 @@ @@ -43,9 +43,7 @@
43 43
44 %h4= @notice.try(:message) 44 %h4= @notice.try(:message)
45 45
46 -= will_paginate @notices, :param_name => :notice, :page_links => false, :class => 'notice-pagination'  
47 -viewing occurrence #{@notices.current_page} of #{@notices.total_pages}  
48 -.notice-pagination-loader= image_tag 'loader.gif' 46 += paginate @notices, :param_name => :notice, :theme => :notices
49 47
50 .tab-bar 48 .tab-bar
51 %ul 49 %ul
app/views/kaminari/notices/_first_page.html.haml 0 → 100644
@@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
  1 +-# Link to the "First" page
  2 +-# available local variables
  3 +-# url: url to the first page
  4 +-# current_page: a page object for the currently displayed page
  5 +-# num_pages: total number of pages
  6 +-# per_page: number of items to fetch per page
  7 +-# remote: data-remote
  8 +%span.first
  9 + = link_to_unless current_page.first?, raw(t 'views.pagination.first'), url, :remote => remote
app/views/kaminari/notices/_gap.html.haml 0 → 100644
@@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
  1 +-# Non-link tag that stands for skipped pages...
  2 +-# available local variables
  3 +-# current_page: a page object for the currently displayed page
  4 +-# num_pages: total number of pages
  5 +-# per_page: number of items to fetch per page
  6 +-# remote: data-remote
  7 +%span.page.gap
  8 + = raw(t 'views.pagination.truncate')
app/views/kaminari/notices/_last_page.html.haml 0 → 100644
@@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
  1 +-# Link to the "Last" page
  2 +-# available local variables
  3 +-# url: url to the last page
  4 +-# current_page: a page object for the currently displayed page
  5 +-# num_pages: total number of pages
  6 +-# per_page: number of items to fetch per page
  7 +-# remote: data-remote
  8 +%span.last
  9 + = link_to_unless current_page.last?, raw(t 'views.pagination.last'), url, {:remote => remote}
app/views/kaminari/notices/_next_page.html.haml 0 → 100644
@@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
  1 +~ link_to_unless current_page.last?, raw('Next →'), url, :class => "next_page", :rel => "next", :remote => remote do |name|
  2 + ~ content_tag :span, name, :class => 'next_page disabled'
app/views/kaminari/notices/_page.html.haml 0 → 100644
@@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
  1 +-# Link showing page number
  2 +-# available local variables
  3 +-# page: a page object for "this" page
  4 +-# url: url to this page
  5 +-# current_page: a page object for the currently displayed page
  6 +-# num_pages: total number of pages
  7 +-# per_page: number of items to fetch per page
  8 +-# remote: data-remote
  9 +%span{:class => "page#{' current' if page.current?}"}
  10 + = link_to_unless page.current?, page, url, {:remote => remote, :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil}
app/views/kaminari/notices/_paginator.html.haml 0 → 100644
@@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
  1 +-# The container tag
  2 +-# available local variables
  3 +-# current_page: a page object for the currently displayed page
  4 +-# num_pages: total number of pages
  5 +-# per_page: number of items to fetch per page
  6 +-# remote: data-remote
  7 +-# paginator: the paginator that renders the pagination tags inside
  8 += paginator.render do
  9 + .notice-pagination<
  10 + = prev_page_tag
  11 + = next_page_tag
  12 +.notice-pagination-loader= image_tag 'loader.gif'
  13 +viewing occurrence #{current_page} of #{num_pages}
app/views/kaminari/notices/_prev_page.html.haml 0 → 100644
@@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
  1 +~ link_to_unless current_page.first?, raw('← Previous'), url, :class => "previous_page", :rel => "prev", :remote => remote do |name|
  2 + ~ content_tag :span, name, :class => 'previous_page disabled'
spec/views/errs/show.html.haml_spec.rb
@@ -8,7 +8,7 @@ describe &quot;errs/show.html.haml&quot; do @@ -8,7 +8,7 @@ describe &quot;errs/show.html.haml&quot; do
8 assign :problem, problem 8 assign :problem, problem
9 assign :comment, comment 9 assign :comment, comment
10 assign :app, problem.app 10 assign :app, problem.app
11 - assign :notices, err.notices.paginate(:page => 1, :per_page => 1) 11 + assign :notices, err.notices.page(1).per(1)
12 assign :notice, err.notices.first 12 assign :notice, err.notices.first
13 controller.stub(:current_user) { Factory(:user) } 13 controller.stub(:current_user) { Factory(:user) }
14 end 14 end