diff --git a/README b/README
index a6ea1b4..2cb8f62 100644
--- a/README
+++ b/README
@@ -23,6 +23,11 @@ Now add a new route to your routes.rb:
After that, visit /logged_exceptions in your application to manage the exceptions.
+Once you have done that, open up the vendor/plugins/init.rb file and choose your pagination,
+supported options are will_paginate, paginating_find, and simple mysql based pagination (Uses LIMIT)
+The current default is none. To use the other options you need to uncomment the $PAGINATION_TYPE line
+and the require for that pagination, you should comment out what you won't use etc...
+
It's understandable that you may want to require authentication. Add this to your config/environments/production.rb:
# config/environments/production.rb
@@ -72,3 +77,4 @@ CREDITS
Jamis Buck - original exception_notification plugin
Rick Olson - model/controller code
Josh Goebel - design
+Jason Knight - Pagination support, built on/inspired by Ryanb's willpaginate support.
diff --git a/init.rb b/init.rb
index 081602d..bd07317 100644
--- a/init.rb
+++ b/init.rb
@@ -1,5 +1,7 @@
-if Kernel.const_defined? 'WillPaginate'
- require 'will_paginate'
- WillPaginate.enable
-end
+ $PAGINATION_TYPE = 'none'
+ #require 'will_paginate'
+ #$PAGINATION_TYPE = 'will_paginate'
+ #WillPaginate.enable
+ #require 'paginating_find'
+ #$PAGINATION_TYPE = 'paginating_find'
LoggedExceptionsController.view_paths = [File.join(directory, 'views')]
diff --git a/lib/logged_exceptions_controller.rb b/lib/logged_exceptions_controller.rb
index 6acd89d..adb9532 100644
--- a/lib/logged_exceptions_controller.rb
+++ b/lib/logged_exceptions_controller.rb
@@ -31,8 +31,24 @@ def query
conditions << 'controller_name = ? AND action_name = ?'
parameters += params[:controller_actions_filter].split('/').collect(&:downcase)
end
- @exceptions = LoggedException.paginate :order => 'created_at desc', :per_page => 30,
+ if $PAGINATION_TYPE == 'will_paginate' then
+ @exceptions = LoggedException.paginate :order => 'created_at desc', :per_page => 30,
:conditions => conditions.empty? ? nil : parameters.unshift(conditions * ' and '), :page => params[:page]
+ elsif $PAGINATION_TYPE == 'paginating_find' then
+ params[:limit] ||= 25
+ params[:page] ||= 1
+ @exceptions = LoggedException.find (:all,:order => 'created_at desc',:page => {:size => params[:limit], :current => params[:page]},
+ :conditions => conditions.empty? ? nil : parameters.unshift(conditions * ' and '))
+ else
+ #we have no pagination so do basic sql pagination
+ params[:limit] ||= 25
+ params[:page] ||= 0
+ page = params[:page]
+ if params[:page].to_i >= 1 then
+ page = params[:page].to_i * params[:limit].to_i
+ end
+ @exceptions = LoggedException.find(:all, :limit => "#{page},#{params[:limit]}", :conditions => conditions.empty? ? nil : parameters.unshift(conditions * ' and '))
+ end
respond_to do |format|
format.html { redirect_to :action => 'index' unless action_name == 'index' }
diff --git a/lib/logged_exceptions_helper.rb b/lib/logged_exceptions_helper.rb
index 0ab3eab..686cc5f 100644
--- a/lib/logged_exceptions_helper.rb
+++ b/lib/logged_exceptions_helper.rb
@@ -4,15 +4,33 @@ def filtered?
end
def pagination_remote_links(collection)
- if Kernel.const_defined? 'WillPaginate'
- will_paginate collection,
+ ret = ''
+ if $PAGINATION_TYPE == 'will_paginate'
+ pagination = will_paginate (collection,
:renderer => 'LoggedExceptionsHelper::PaginationRenderer',
:prev_label => '',
:next_label => '',
- :container => false
+ :container => false)
+ if collection.total_pages > 1 then
+ ret = ":: Pages : #{pagination}"
+ end
+ elsif $PAGINATION_TYPE == 'paginating_find' then
+ pagination = paginating_links collection
+ ret = ":: Pages : #{pagination}"
+ else
+ next_page = params[:page].to_i + 1
+ prev_page = 0
+ prev_link = ''
+ if params[:page].to_i > 0 then
+ prev_page = params[:page].to_i - 1
+ prev_link = " Previous page"
+ end
+ next_link = "Next page"
+ ret = "Pagination not available#{prev_link} - #{next_link}"
end
end
- if Kernel.const_defined? 'WillPaginate'
+
+ if $PAGINATION_TYPE == 'will_paginate'
class PaginationRenderer < WillPaginate::LinkRenderer
def page_link_or_span(page, span_class = 'current', text = nil)
text ||= page.to_s