Skip to content

Commit

Permalink
Merge remote branch 'mwindwer/kaminari'
Browse files Browse the repository at this point in the history
Conflicts:
	Gemfile
	activeadmin.gemspec
  • Loading branch information
gregbell committed Jun 1, 2011
2 parents 44dbeeb + a5c11f3 commit c45bd41
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 20 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ end
gem "meta_search", '>= 0.9.2'
gem 'devise', '>= 1.1.2'
gem 'formtastic', '>= 1.1.0'
gem 'will_paginate', '>= 3.0.pre2'
gem 'inherited_resources'
gem 'kaminari', '>= 0.12.4'
gem 'sass', '>= 3.1.0'
gem 'fastercsv'

Expand All @@ -49,3 +49,4 @@ group :test do
gem 'shoulda', '2.11.2', :require => nil
gem 'launchy'
end

2 changes: 1 addition & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ Formtastic::
A DSL for semantically building amazing forms.
Devise::
User authentication is done using Devise
WillPaginate::
Kaminari::
Pagination for rails apps
Iconic Icons::
Excellent SVG icon set designed by P.J. Onori: http://somerandomdude.com/projects/iconic
Expand Down
11 changes: 5 additions & 6 deletions activeadmin.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |s|

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Greg Bell"]
s.date = %q{2011-05-31}
s.date = %q{2011-06-01}
s.description = %q{The administration framework for Ruby on Rails.}
s.email = %q{gregdbell@gmail.com}
s.extra_rdoc_files = [
Expand Down Expand Up @@ -263,7 +263,7 @@ Gem::Specification.new do |s|
]
s.homepage = %q{http://github.com/gregbell/active_admin}
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.7}
s.rubygems_version = %q{1.7.2}
s.summary = %q{The administration framework for Ruby on Rails.}
s.test_files = [
"spec/integration/belongs_to_spec.rb",
Expand Down Expand Up @@ -317,16 +317,15 @@ Gem::Specification.new do |s|
]

if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<rails>, [">= 3.0.0"])
s.add_runtime_dependency(%q<meta_search>, [">= 0.9.2"])
s.add_runtime_dependency(%q<devise>, [">= 1.1.2"])
s.add_runtime_dependency(%q<formtastic>, [">= 1.1.0"])
s.add_runtime_dependency(%q<will_paginate>, [">= 3.0.pre2"])
s.add_runtime_dependency(%q<inherited_resources>, [">= 0"])
s.add_runtime_dependency(%q<kaminari>, [">= 0.12.4"])
s.add_runtime_dependency(%q<sass>, [">= 3.1.0"])
s.add_runtime_dependency(%q<fastercsv>, [">= 0"])
s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
Expand All @@ -338,8 +337,8 @@ Gem::Specification.new do |s|
s.add_dependency(%q<meta_search>, [">= 0.9.2"])
s.add_dependency(%q<devise>, [">= 1.1.2"])
s.add_dependency(%q<formtastic>, [">= 1.1.0"])
s.add_dependency(%q<will_paginate>, [">= 3.0.pre2"])
s.add_dependency(%q<inherited_resources>, [">= 0"])
s.add_dependency(%q<kaminari>, [">= 0.12.4"])
s.add_dependency(%q<sass>, [">= 3.1.0"])
s.add_dependency(%q<fastercsv>, [">= 0"])
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
Expand All @@ -352,8 +351,8 @@ Gem::Specification.new do |s|
s.add_dependency(%q<meta_search>, [">= 0.9.2"])
s.add_dependency(%q<devise>, [">= 1.1.2"])
s.add_dependency(%q<formtastic>, [">= 1.1.0"])
s.add_dependency(%q<will_paginate>, [">= 3.0.pre2"])
s.add_dependency(%q<inherited_resources>, [">= 0"])
s.add_dependency(%q<kaminari>, [">= 0.12.4"])
s.add_dependency(%q<sass>, [">= 3.1.0"])
s.add_dependency(%q<fastercsv>, [">= 0"])
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
Expand Down
7 changes: 4 additions & 3 deletions lib/active_admin.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'meta_search'
require 'devise'
require 'will_paginate'
require 'kaminari'
require 'sass'
require 'active_admin/arbre'

Expand Down Expand Up @@ -38,7 +38,7 @@ module Configuration

# The default namespace to put controllers and routes inside. Set this
# in config/initializers/active_admin.rb using:
#
#
# config.default_namespace = :super_admin
#
@@default_namespace = :admin
Expand Down Expand Up @@ -116,7 +116,7 @@ def setup
ActionController::Base.append_view_path ActiveAdmin.views_path

# Don't eagerload our configs, we'll deal with them ourselves
Rails.application.config.eager_load_paths = Rails.application.config.eager_load_paths.reject do |path|
Rails.application.config.eager_load_paths = Rails.application.config.eager_load_paths.reject do |path|
load_paths.include?(path)
end

Expand Down Expand Up @@ -314,3 +314,4 @@ def dashboard_section(name, options = {}, &block)
end

require 'active_admin/comments'

6 changes: 6 additions & 0 deletions lib/active_admin/comments/comment.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
require 'kaminari/models/active_record_extension'

module ActiveAdmin

# manually initialize kaminari for this model
::ActiveRecord::Base.send :include, Kaminari::ActiveRecordExtension

class Comment < ActiveRecord::Base
self.table_name = "active_admin_comments"

Expand All @@ -13,3 +18,4 @@ class Comment < ActiveRecord::Base
end

end

5 changes: 3 additions & 2 deletions lib/active_admin/resource_controller/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def active_admin_collection
# This method should return an ActiveRecord::Relation object so that
# the searching and filtering can be applied on top
#
# Note, unless you are doing something special, you should use the
# Note, unless you are doing something special, you should use the
# scope_to method from the Scoping module instead of overriding this
# method.
def scoped_collection
Expand Down Expand Up @@ -126,7 +126,7 @@ def setup_pagination_for_csv
end

def paginate(chain)
chain.paginate(:page => params[:page], :per_page => @per_page || ActiveAdmin.default_per_page)
chain.page(params[:page]).per(@per_page || ActiveAdmin.default_per_page)
end
end

Expand All @@ -141,3 +141,4 @@ def paginate(chain)
end
end
end

37 changes: 30 additions & 7 deletions lib/active_admin/views/components/paginated_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Views
#
# paginated_collection collection, :entry_name => "Post" do
# div do
# h2 "Inside the
# h2 "Inside the
# end
# end
#
Expand All @@ -26,14 +26,14 @@ class PaginatedCollection < ActiveAdmin::Component

# Builds a new paginated collection component
#
# @param [Array] collection A "paginated" collection from will_paginate
# @param [Array] collection A "paginated" collection from kaminari
# @param [Hash] options These options will be passed on to the page_entries_info
# method supplied in will_paginate.
# method.
# Useful keys:
# :entry_name - The name to dislpay for this resource collection
# :entry_name - The name to display for this resource collection
def build(collection, options = {})
@collection = collection
div(page_entries_info(@collection, options), :class => "pagination_information")
div(page_entries_info(options).html_safe, :class => "pagination_information")
@contents = div(:class => "paginated_collection_contents")
build_pagination_with_formats
@built = true
Expand All @@ -58,17 +58,40 @@ def build_pagination_with_formats
end

def build_pagination
text_node will_paginate(collection, :previous_label => "Previous", :next_label => "Next")
text_node paginate(collection)
end

# TODO: Refactor to new HTML DSL
def build_download_format_links(formats = [:csv, :xml, :json])
links = formats.collect do |format|
link_to format.to_s.upcase, { :format => format}.merge(request.query_parameters.except(:commit, :format))
link_to format.to_s.upcase, { :format => format}.merge(request.query_parameters.except(:commit, :format))
end
text_node ["Download:", links].flatten.join("&nbsp;").html_safe
end

# modified from will_paginate
def page_entries_info(options = {})
entry_name = options[:entry_name] ||
(collection.empty?? 'entry' : collection.first.class.name.underscore.sub('_', ' '))

if collection.num_pages < 2
case collection.size
when 0; "No #{entry_name.pluralize} found"
when 1; "Displaying <b>1</b> #{entry_name}"
else; "Displaying <b>all #{collection.size}</b> #{entry_name.pluralize}"
end
else
offset = collection.current_page * ActiveAdmin.default_per_page
total = collection.total_count
%{Displaying #{entry_name.pluralize} <b>%d&nbsp;-&nbsp;%d</b> of <b>%d</b> in total} % [
offset - ActiveAdmin.default_per_page + 1,
offset > total ? total : offset,
total
]
end
end

end
end
end

0 comments on commit c45bd41

Please sign in to comment.