diff --git a/Gemfile b/Gemfile index aacc982..c050aba 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index 61f2f33..7468329 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/app/views/kaminari/_first_page.html.erb b/app/views/kaminari/_first_page.html.erb new file mode 100644 index 0000000..be84d7b --- /dev/null +++ b/app/views/kaminari/_first_page.html.erb @@ -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 +-%> +
  • + <%= link_to t('views.pagination.first').html_safe, url, remote: remote, class: "page-link" %> +
  • diff --git a/app/views/kaminari/_gap.html.erb b/app/views/kaminari/_gap.html.erb new file mode 100644 index 0000000..cd730b7 --- /dev/null +++ b/app/views/kaminari/_gap.html.erb @@ -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 +-%> +
  • + <%= t('views.pagination.truncate').html_safe %> +
  • diff --git a/app/views/kaminari/_last_page.html.erb b/app/views/kaminari/_last_page.html.erb new file mode 100644 index 0000000..4ef40e0 --- /dev/null +++ b/app/views/kaminari/_last_page.html.erb @@ -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 +-%> +
  • + <%= link_to t('views.pagination.last').html_safe, url, remote: remote, class: "page-link" %> +
  • diff --git a/app/views/kaminari/_next_page.html.erb b/app/views/kaminari/_next_page.html.erb new file mode 100644 index 0000000..c967dd8 --- /dev/null +++ b/app/views/kaminari/_next_page.html.erb @@ -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 +-%> +
  • + <%= link_to t('views.pagination.next').html_safe, url, rel: 'next', remote: remote, class: "page-link" %> +
  • diff --git a/app/views/kaminari/_page.html.erb b/app/views/kaminari/_page.html.erb new file mode 100644 index 0000000..efcbe03 --- /dev/null +++ b/app/views/kaminari/_page.html.erb @@ -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 +-%> +
  • + <%= link_to page, url, remote: remote, rel: page.rel, class: "page-link" %> + <% if page.current? %> + (current) + <% end %> +
  • diff --git a/app/views/kaminari/_paginator.html.erb b/app/views/kaminari/_paginator.html.erb new file mode 100644 index 0000000..7a26612 --- /dev/null +++ b/app/views/kaminari/_paginator.html.erb @@ -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 -%> + +<% end -%> diff --git a/app/views/kaminari/_prev_page.html.erb b/app/views/kaminari/_prev_page.html.erb new file mode 100644 index 0000000..d272a5a --- /dev/null +++ b/app/views/kaminari/_prev_page.html.erb @@ -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 +-%> +
  • + <%= link_to t('views.pagination.previous').html_safe, url, rel: 'prev', remote: remote, class: "page-link" %> +
  • diff --git a/config/initializers/kaminari_config.rb b/config/initializers/kaminari_config.rb new file mode 100644 index 0000000..aed7d31 --- /dev/null +++ b/config/initializers/kaminari_config.rb @@ -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 diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 2477a7f..c2a85e4 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -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 1 %{entry_name}" + other: "Affiche les %{count} %{entry_name}" + more_pages: + display_entries: "Affiche %{entry_name} %{first} - %{last} de %{total} au total" + views: + pagination: + first: "« Début" + last: "Fin »" + previous: "‹ Préc" + next: "Suiv ›" + truncate: "…" time: am: am