Class: Redmine::Pagination::Paginator
- Inherits:
-
Object
- Object
- Redmine::Pagination::Paginator
- Defined in:
- lib/redmine/pagination.rb
Instance Attribute Summary collapse
-
#item_count ⇒ Object
readonly
Returns the value of attribute item_count.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#page_param ⇒ Object
readonly
Returns the value of attribute page_param.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
Instance Method Summary collapse
- #current ⇒ Object
- #first_item ⇒ Object
- #first_page ⇒ Object
-
#initialize(*args) ⇒ Paginator
constructor
A new instance of Paginator.
- #items_per_page ⇒ Object
- #last_item ⇒ Object
- #last_page ⇒ Object
- #linked_pages ⇒ Object
- #multiple_pages? ⇒ Boolean
- #next_page ⇒ Object
- #offset ⇒ Object
- #previous_page ⇒ Object
Constructor Details
#initialize(*args) ⇒ Paginator
Returns a new instance of Paginator
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/redmine/pagination.rb', line 25 def initialize(*args) if args.first.is_a?(ActionController::Base) args.shift ActiveSupport::Deprecation.warn "Paginator no longer takes a controller instance as the first argument. Remove it from #new arguments." end item_count, per_page, page, page_param = *args @item_count = item_count @per_page = per_page page = (page || 1).to_i if page < 1 page = 1 end @page = page @page_param = page_param || :page end |
Instance Attribute Details
#item_count ⇒ Object (readonly)
Returns the value of attribute item_count
23 24 25 |
# File 'lib/redmine/pagination.rb', line 23 def item_count @item_count end |
#page ⇒ Object (readonly)
Returns the value of attribute page
23 24 25 |
# File 'lib/redmine/pagination.rb', line 23 def page @page end |
#page_param ⇒ Object (readonly)
Returns the value of attribute page_param
23 24 25 |
# File 'lib/redmine/pagination.rb', line 23 def page_param @page_param end |
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page
23 24 25 |
# File 'lib/redmine/pagination.rb', line 23 def per_page @per_page end |
Instance Method Details
#current ⇒ Object
102 103 104 105 |
# File 'lib/redmine/pagination.rb', line 102 def current ActiveSupport::Deprecation.warn "Paginator#current will be removed. Use .offset instead of .current.offset." self end |
#first_item ⇒ Object
74 75 76 |
# File 'lib/redmine/pagination.rb', line 74 def first_item item_count == 0 ? 0 : (offset + 1) end |
#first_page ⇒ Object
46 47 48 49 50 |
# File 'lib/redmine/pagination.rb', line 46 def first_page if item_count > 0 1 end end |
#items_per_page ⇒ Object
97 98 99 100 |
# File 'lib/redmine/pagination.rb', line 97 def items_per_page ActiveSupport::Deprecation.warn "Paginator#items_per_page will be removed. Use #per_page instead." per_page end |
#last_item ⇒ Object
78 79 80 81 |
# File 'lib/redmine/pagination.rb', line 78 def last_item l = first_item + per_page - 1 l > item_count ? item_count : l end |
#last_page ⇒ Object
64 65 66 67 68 |
# File 'lib/redmine/pagination.rb', line 64 def last_page if item_count > 0 (item_count - 1) / per_page + 1 end end |
#linked_pages ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/redmine/pagination.rb', line 83 def linked_pages pages = [] if item_count > 0 pages += [first_page, page, last_page] pages += ((page-2)..(page+2)).to_a.select {|p| p > first_page && p < last_page} end pages = pages.compact.uniq.sort if pages.size > 1 pages else [] end end |
#multiple_pages? ⇒ Boolean
70 71 72 |
# File 'lib/redmine/pagination.rb', line 70 def multiple_pages? per_page < item_count end |
#next_page ⇒ Object
58 59 60 61 62 |
# File 'lib/redmine/pagination.rb', line 58 def next_page if last_item < item_count page + 1 end end |
#offset ⇒ Object
42 43 44 |
# File 'lib/redmine/pagination.rb', line 42 def offset (page - 1) * per_page end |
#previous_page ⇒ Object
52 53 54 55 56 |
# File 'lib/redmine/pagination.rb', line 52 def previous_page if page > 1 page - 1 end end |