Skip to content

Commit

Permalink
Added support for paginating find, will_paginate rewrite, and home br…
Browse files Browse the repository at this point in the history
…ewed mysql pagination in case you don't have any
  • Loading branch information
Jason Knight committed May 15, 2008
1 parent 22c9278 commit 7172c77
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 9 deletions.
6 changes: 6 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
10 changes: 6 additions & 4 deletions init.rb
Original file line number Diff line number Diff line change
@@ -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')]
18 changes: 17 additions & 1 deletion lib/logged_exceptions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down
26 changes: 22 additions & 4 deletions lib/logged_exceptions_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 : <strong>#{pagination}</strong>"
end
elsif $PAGINATION_TYPE == 'paginating_find' then
pagination = paginating_links collection
ret = ":: Pages : <strong>#{pagination}</strong>"
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 = "<a href=\"?page=#{prev_page}\"> Previous page</a>"
end
next_link = "<a href=\"?page=#{next_page}\">Next page</a>"
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
Expand Down

0 comments on commit 7172c77

Please sign in to comment.