Skip to content

Commit

Permalink
modify the plugin to use (and require) will_paginate
Browse files Browse the repository at this point in the history
  • Loading branch information
defunkt committed Jan 13, 2008
1 parent 712d5ef commit dc22383
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
3 changes: 2 additions & 1 deletion init.rb
@@ -1 +1,2 @@
LoggedExceptionsController.view_paths = [File.join(directory, 'views')]
WillPaginate.enable
LoggedExceptionsController.view_paths = [File.join(directory, 'views')]
6 changes: 3 additions & 3 deletions lib/logged_exceptions_controller.rb
Expand Up @@ -31,8 +31,8 @@ def query
conditions << 'controller_name = ? AND action_name = ?'
parameters += params[:controller_actions_filter].split('/').collect(&:downcase)
end
@exception_pages, @exceptions = paginate :logged_exceptions, :order => 'created_at desc', :per_page => 30,
:conditions => conditions.empty? ? nil : parameters.unshift(conditions * ' and ')
@exceptions = LoggedException.paginate :order => 'created_at desc', :per_page => 30,
:conditions => conditions.empty? ? nil : parameters.unshift(conditions * ' and '), :page => params[:page]

respond_to do |format|
format.html { redirect_to :action => 'index' unless action_name == 'index' }
Expand Down Expand Up @@ -68,4 +68,4 @@ def get_auth_data
auth_data = request.env[auth_key].to_s.split unless auth_key.blank?
return auth_data && auth_data[0] == 'Basic' ? Base64.decode64(auth_data[1]).split(':')[0..1] : [nil, nil]
end
end
end
27 changes: 18 additions & 9 deletions lib/logged_exceptions_helper.rb
Expand Up @@ -3,13 +3,22 @@ def filtered?
[:query, :date_ranges_filter, :exception_names_filter, :controller_actions_filter].any? { |p| params[p] }
end

def pagination_remote_links(paginator, options={}, html_options={})
name = options[:name] || ActionController::Pagination::DEFAULT_OPTIONS[:name]
params = (options[:params] || ActionController::Pagination::DEFAULT_OPTIONS[:params]).clone

pagination_links_each(paginator, options) do |n|
params[name] = n
link_to_function n.to_s, "ExceptionLogger.setPage(#{n})"
end
def pagination_remote_links(collection)
will_paginate collection,
:renderer => 'LoggedExceptionsHelper::PaginationRenderer',
:prev_label => '',
:next_label => '',
:container => false
end
end

class PaginationRenderer < WillPaginate::LinkRenderer
def page_link_or_span(page, span_class = 'current', text = nil)
text ||= page.to_s
if page and page != current_page
@template.link_to_function text, "ExceptionLogger.setPage(#{page})"
else
@template.content_tag :span, text, :class => span_class
end
end
end
end
10 changes: 5 additions & 5 deletions views/logged_exceptions/_exceptions.rhtml
@@ -1,8 +1,8 @@
<div id="exceptions">
<div class="pages">
<%= link_to_remote 'Delete Visible', :url => { :action => 'destroy_all' }, :with => "ExceptionLogger.deleteAll()" %>
<% if @exception_pages.page_count > 1 %>
:: Pages: <strong><%= pagination_remote_links @exception_pages, :params => { :action => :index } %></strong>
<% if @exceptions.page_count > 1 %>
:: Pages: <strong><%= pagination_remote_links @exceptions %></strong>
<% end %>
</div>

Expand Down Expand Up @@ -48,11 +48,11 @@ if Date.today == exc.created_at.to_date

</table>

<% if @exception_pages.page_count > 1 %>
<% if @exceptions.page_count > 1 %>
<div class="pages pages-bottom">
Pages: <strong><%= pagination_remote_links @exception_pages, :params => { :action => :index } %></strong>
Pages: <strong><%= pagination_remote_links @exceptions %></strong>
</div>
<% end %>


</div> <!-- #exceptions -->
</div> <!-- #exceptions -->

0 comments on commit dc22383

Please sign in to comment.