padrino/padrino-framework — pull request #941 by wokibe (2012-10-16 20:38:50+00:00)
Title: Pagination and column sort support for "admin_page"

The attached code allows pagination and column sort support for admin_pages.

The only step a user needs to do to activate this features in this code is to install the corrected plugin "will_paginate" (padrino-recipes pull_request issue #34). Otherwise the admin_pages will behave as before.

The user can select which column should be sorted by a click on the header of the table. A second click will toggle the direction of the sort.

There is a single number field form below the page selection to change the actual page size.

The code supports datamapper, sequel and activerecord, and works with haml, erb and slim.

DataMapper and ActiveRecord models support a per_page attribute, which allow a model specific per_page default or save the changed per_page value through a session. With Sequel a model has to be extended like:

class MyModel << Sequel::Model
class << self
attr_accessor :per_page
end
end

The implementation is done with two methods "sort_page" and "sort_link" in admin/helpers/pagination_helpers.rb, which are called from the "index" code in the controllers and from the "index" page in the views.

Please let me know what you think about this solution.

To supply the missing tests I would need some mentoring, as I could not figure out, how to do that with the required plugin.

Best regards
Wokibe