Skip to content

Commit

Permalink
theme for kaminari paginator
Browse files Browse the repository at this point in the history
will_paginate removed
  • Loading branch information
leikind committed Jul 27, 2012
1 parent 6ee9256 commit ebb6789
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ begin
gem.email = "yuri.leikind@gmail.com"
gem.homepage = "http://github.com/lekind/wice_grid"
gem.authors = ["Yuri Leikind"]
gem.add_development_dependency "will_paginate", ">= 3.0.3"
gem.add_development_dependency "kaminari", ">= 0.13.0"
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::GemcutterTasks.new
Expand Down
2 changes: 2 additions & 0 deletions app/views/kaminari/wice_grid/_gap.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
%li.disabled
%a{:href=> '#'} ...
9 changes: 9 additions & 0 deletions app/views/kaminari/wice_grid/_next_page.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-# Link to the "Next" page
-# available local variables
-# url: url to the next page
-# current_page: a page object for the currently displayed page
-# total_pages: total number of pages
-# per_page: number of items to fetch per page
-# remote: data-remote
%li
= link_to_unless current_page.last?, ::Wice::NlMessage['next_label'], url, :rel => 'next', :remote => remote
10 changes: 10 additions & 0 deletions app/views/kaminari/wice_grid/_page.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-# Link showing page number
-# available local variables
-# page: a page object for "this" page
-# url: url to this page
-# current_page: a page object for the currently displayed page
-# total_pages: total number of pages
-# per_page: number of items to fetch per page
-# remote: data-remote
%li{:class => page.current? ? 'active' : nil}
= link_to page, url, {:remote => remote, :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil}
17 changes: 17 additions & 0 deletions app/views/kaminari/wice_grid/_paginator.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-# The container tag
-# available local variables
-# current_page: a page object for the currently displayed page
-# total_pages: total number of pages
-# per_page: number of items to fetch per page
-# remote: data-remote
-# paginator: the paginator that renders the pagination tags inside
= paginator.render do
.pagination
%ul
= prev_page_tag unless current_page.first?
- each_page do |page|
- if page.left_outer? || page.right_outer? || page.inside_window?
= page_tag page
- elsif !page.was_truncated?
= gap_tag
= next_page_tag unless current_page.last?
9 changes: 9 additions & 0 deletions app/views/kaminari/wice_grid/_prev_page.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-# Link to the "Previous" page
-# available local variables
-# url: url to the previous page
-# current_page: a page object for the currently displayed page
-# total_pages: total number of pages
-# per_page: number of items to fetch per page
-# remote: data-remote
%li
= link_to_unless current_page.first?, ::Wice::NlMessage['previous_label'], url, :rel => 'prev', :remote => remote
19 changes: 14 additions & 5 deletions lib/helpers/wice_grid_view_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,12 @@ def pagination_panel_content(grid, extra_request_parameters, allow_showing_all_r
# :renderer => ::Wice::WillPaginatePaginator,
# :params => extra_request_parameters).to_s +

paginate(grid.resultset, :param_name => "#{grid.name}[page]") +
paginate(grid.resultset,
:theme => 'wice_grid',
:param_name => "#{grid.name}[page]",
:inner_window => 4,
:outer_window => 2
) +
(' <div class="pagination_status">' + html + '</div>').html_safe_if_necessary
end

Expand Down Expand Up @@ -624,25 +629,29 @@ def back_to_pagination_link(parameters, grid_name) #:nodoc:
end

def pagination_info(grid, allow_showing_all_records) #:nodoc:


collection = grid.resultset

collection_total_entries = collection.total_count
collection_total_entries_str = collection_total_entries.to_s


current_page = grid.ar_options[:page].to_i
per_page = grid.ar_options[:per_page].to_i

offset = per_page * (current_page - 1)
first = collection.offset_value + 1
last = collection.last_page? ? collection.total_count : collection.offset_value + collection.limit_value


parameters = grid.get_state_as_parameter_value_pairs

js = ''
html = if (collection.num_pages < 2 && collection.length == 0)
'0'
else
parameters << ["#{grid.name}[pp]", collection_total_entries_str]
parameters << ["#{grid.name}[pp]", collection_total_entries]

"#{offset + 1}-#{offset + collection.count} / #{collection_total_entries_str} " +
"#{first}-#{last} / #{collection_total_entries} " +
if (! allow_showing_all_records) || collection_total_entries <= collection.length
''
else
Expand Down
4 changes: 2 additions & 2 deletions lib/wice_grid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class WiceGridEngine < ::Rails::Engine
require 'wice_grid_serialized_query.rb'
end

require 'will_paginate_paginator.rb'

end

end
Expand Down Expand Up @@ -294,6 +292,7 @@ def read #:nodoc:
@relation.
includes(@ar_options[:include]).
joins( @ar_options[:joins]).
order( @ar_options[:order]).
where( @ar_options[:conditions])

else
Expand All @@ -303,6 +302,7 @@ def read #:nodoc:
per( @ar_options[:per_page]).
includes(@ar_options[:include]).
joins( @ar_options[:joins]).
order( @ar_options[:order]).
where( @ar_options[:conditions])

end
Expand Down
31 changes: 0 additions & 31 deletions lib/will_paginate_paginator.rb

This file was deleted.

6 changes: 3 additions & 3 deletions wice_grid.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ Gem::Specification.new do |s|
s.specification_version = 3

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_development_dependency(%q<will_paginate>, [">= 3.0.3"])
s.add_development_dependency(%q<kaminari>, [">= 0.13.0"])
else
s.add_dependency(%q<will_paginate>, [">= 3.0.3"])
s.add_dependency(%q<kaminari>, [">= 0.13.0"])
end
else
s.add_dependency(%q<will_paginate>, [">= 3.0.3"])
s.add_dependency(%q<kaminari>, [">= 0.13.0"])
end
end

0 comments on commit ebb6789

Please sign in to comment.