[GEM] +kaminari for pagination.

This commit is contained in:
Colin Darie 2018-07-03 19:45:24 +02:00
parent c619d39bde
commit 3ef8e6322a
No known key found for this signature in database
GPG Key ID: 4FB865FDBCA4BCC4
11 changed files with 137 additions and 0 deletions

View File

@ -42,6 +42,7 @@ gem 'whenever', require: false
gem 'octicons'
gem 'kaminari'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false

View File

@ -138,6 +138,18 @@ GEM
activesupport (>= 4.2.0)
multi_json (>= 1.2)
json (2.1.0)
kaminari (1.1.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.1.1)
kaminari-activerecord (= 1.1.1)
kaminari-core (= 1.1.1)
kaminari-actionview (1.1.1)
actionview
kaminari-core (= 1.1.1)
kaminari-activerecord (1.1.1)
activerecord
kaminari-core (= 1.1.1)
kaminari-core (1.1.1)
launchy (2.4.3)
addressable (~> 2.3)
letter_opener (1.6.0)
@ -339,6 +351,7 @@ DEPENDENCIES
guard
guard-minitest
jbuilder (~> 2.5)
kaminari
launchy
letter_opener_web
listen (>= 3.0.5, < 3.2)

View File

@ -0,0 +1,11 @@
<%# Link to the "First" page
- available local variables
url: url to the first 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-item <%= 'active' if current_page.first? %>">
<%= link_to t('views.pagination.first').html_safe, url, remote: remote, class: "page-link" %>
</li>

View File

@ -0,0 +1,10 @@
<%# Non-link tag that stands for skipped pages...
- 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
-%>
<li class="page-item">
<span class="page-link"><%= t('views.pagination.truncate').html_safe %></span>
</li>

View File

@ -0,0 +1,11 @@
<%# Link to the "Last" page
- available local variables
url: url to the last 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-item <%= 'active' if current_page.last? %>">
<%= link_to t('views.pagination.last').html_safe, url, remote: remote, class: "page-link" %>
</li>

View File

@ -0,0 +1,11 @@
<%# 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 class="page-item <%= 'active' if current_page.last? %>">
<%= link_to t('views.pagination.next').html_safe, url, rel: 'next', remote: remote, class: "page-link" %>
</li>

View File

@ -0,0 +1,15 @@
<%# 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-item <%= ' active' if page.current? %>">
<%= link_to page, url, remote: remote, rel: page.rel, class: "page-link" %>
<% if page.current? %>
<span class="sr-only">(current)</span>
<% end %>
</li>

View File

@ -0,0 +1,27 @@
<%# 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 -%>
<nav role="navigation" aria-label="pager">
<ul class="pagination justify-content-center">
<%= first_page_tag unless current_page.first? %>
<%= prev_page_tag unless current_page.first? %>
<% each_page do |page| -%>
<% if page.display_tag? -%>
<%= page_tag page %>
<% elsif !page.was_truncated? -%>
<%= gap_tag %>
<% end -%>
<% end -%>
<% unless current_page.out_of_range? %>
<%= next_page_tag unless current_page.last? %>
<%= last_page_tag unless current_page.last? %>
<% end %>
</ul>
</nav>
<% end -%>

View File

@ -0,0 +1,11 @@
<%# 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 class="page-item <%= 'active' if current_page.first? %>">
<%= link_to t('views.pagination.previous').html_safe, url, rel: 'prev', remote: remote, class: "page-link" %>
</li>

View File

@ -0,0 +1,12 @@
# frozen_string_literal: true
Kaminari.configure do |config|
config.default_per_page = 20
config.max_per_page = 200
# config.window = 4
# config.outer_window = 0
# config.left = 0
# config.right = 0
# config.page_method_name = :page
# config.param_name = :page
# config.params_on_first_page = false
end

View File

@ -23,6 +23,21 @@ fr:
check:
create: "Créer"
update: "Valider"
page_entries_info:
one_page:
display_entries:
zero: "Pas de %{entry_name} trouvé."
one: "Affiche <b>1</b> %{entry_name}"
other: "Affiche <b>les %{count}</b> %{entry_name}"
more_pages:
display_entries: "Affiche %{entry_name} <b>%{first}&nbsp;-&nbsp;%{last}</b> de <b>%{total}</b> au total"
views:
pagination:
first: "&laquo; Début"
last: "Fin &raquo;"
previous: "&lsaquo; Préc"
next: "Suiv &rsaquo;"
truncate: "&hellip;"
time:
am: am