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, included, #l, #l_hours, #l_or_humanize, #languages_options, #ll, #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


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
# File 'lib/redmine/pagination.rb', line 168

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 = ''
  if paginator.previous_page
    # \xc2\xab(utf-8) = «
    text = "\xc2\xab " + l(:label_previous)
    html << yield(text, {page_param => paginator.previous_page}, :class => 'previous') + ' '
  end

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

  if paginator.next_page
    # \xc2\xbb(utf-8) = &#187;
    text = l(:label_next) + " \xc2\xbb"
    html << yield(text, {page_param => paginator.next_page}, :class => 'next') + ' '
  end

  html << ('span', "(#{paginator.first_item}-#{paginator.last_item}/#{paginator.item_count})", :class => 'items') + ' '

  if per_page_links != false && links = per_page_links(paginator, &block)
    html << ('span', links.to_s, :class => 'per-page')
  end

  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

156
157
158
159
160
161
162
163
164
# File 'lib/redmine/pagination.rb', line 156

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.


212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/redmine/pagination.rb', line 212

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)
      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


226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/redmine/pagination.rb', line 226

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