Module: Redmine::Pagination::Helper

Includes:
I18n
Included in:
ApplicationHelper
Defined in:
lib/redmine/pagination.rb

Instance Method Summary collapse

Methods included from I18n

#current_language, #day_letter, #day_name, #find_language, #format_date, #format_hours, #format_time, included, #l, #l_hours, #l_hours_short, #l_or_humanize, #languages_options, #ll, #lu, #month_name, #set_language_if_valid, #valid_languages

Instance Method Details

Yields the given block with the text and parameters for each pagination link and returns a string that represents the links



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/redmine/pagination.rb', line 155

def pagination_links_each(paginator, count=nil, options={}, &block)
  options.assert_valid_keys :per_page_links

  per_page_links = options.delete(:per_page_links)
  per_page_links = false if count.nil?
  page_param = paginator.page_param

  html = '<ul class="pages">'

  if paginator.multiple_pages?
    # \xc2\xab(utf-8) = &#171;
    text = "\xc2\xab " + l(:label_previous)
    if paginator.previous_page
      html << ('li',
                          yield(text, {page_param => paginator.previous_page},
                                :accesskey => accesskey(:previous)),
                          :class => 'previous page')
    else
      html << ('li', ('span', text), :class => 'previous')
    end
  end

  previous = nil
  paginator.linked_pages.each do |page|
    if previous && previous != page - 1
      html << ('li', ('span', '&hellip;'.html_safe), :class => 'spacer')
    end
    if page == paginator.page
      html << ('li', ('span', page.to_s), :class => 'current')
    else
      html << ('li',
                          yield(page.to_s, {page_param => page}),
                          :class => 'page')
    end
    previous = page
  end

  if paginator.multiple_pages?
    # \xc2\xbb(utf-8) = &#187;
    text = l(:label_next) + " \xc2\xbb"
    if paginator.next_page
      html << ('li',
                          yield(text, {page_param => paginator.next_page},
                                :accesskey => accesskey(:next)),
                          :class => 'next page')
    else
      html << ('li', ('span', text), :class => 'next')
    end
  end
  html << '</ul>'

  info = ''.html_safe
  info << ('span', "(#{paginator.first_item}-#{paginator.last_item}/#{paginator.item_count})", :class => 'items') + ' '
  if per_page_links != false && links = per_page_links(paginator, &block)
    info << ('span', links.to_s, :class => 'per-page')
  end
  html << ('span', info)

  html.html_safe
end

Renders the pagination links for the given paginator.

Options:

:per_page_links    if set to false, the "Per page" links are not rendered


143
144
145
146
147
148
149
150
151
# File 'lib/redmine/pagination.rb', line 143

def pagination_links_full(*args)
  pagination_links_each(*args) do |text, parameters, options|
    if block_given?
      yield text, parameters, options
    else
      link_to text, {:params => request.query_parameters.merge(parameters)}, options
    end
  end
end

Renders the “Per page” links.



217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/redmine/pagination.rb', line 217

def per_page_links(paginator, &block)
  values = per_page_options(paginator.per_page, paginator.item_count)
  if values.any?
    links = values.collect do |n|
      if n == paginator.per_page
        ('span', n.to_s, :class => 'selected')
      else
        yield(n, :per_page => n, paginator.page_param => nil)
      end
    end
    l(:label_display_per_page, links.join(', ')).html_safe
  end
end

#per_page_options(selected = nil, item_count = nil) ⇒ Object



231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/redmine/pagination.rb', line 231

def per_page_options(selected=nil, item_count=nil)
  options = Setting.per_page_options_array
  if item_count && options.any?
    if item_count > options.first
      max = options.detect {|value| value >= item_count} || item_count
    else
      max = item_count
    end
    options = options.select {|value| value <= max || value == selected}
  end
  if options.empty? || (options.size == 1 && options.first == selected)
    []
  else
    options
  end
end