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_time, #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

Since:

  • 2.3.0



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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/redmine/pagination.rb', line 172

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

Since:

  • 2.3.0



160
161
162
163
164
165
166
167
168
# File 'lib/redmine/pagination.rb', line 160

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.merge(parameters), options
    end
  end
end

Renders the “Per page” links.

Since:

  • 2.3.0



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

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

Since:

  • 2.3.0



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/redmine/pagination.rb', line 248

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