diff --git a/Gemfile b/Gemfile
index e2573027..e12245ff 100644
--- a/Gemfile
+++ b/Gemfile
@@ -5,7 +5,7 @@ gem 'rails', '~> 5.2'
gem 'bootstrap'
gem 'attr_encrypted'
gem 'jquery-rails'
-gem 'kaminari'
+gem 'pagy'
gem 'local_time'
gem 'octicons_helper'
gem 'octokit'
diff --git a/Gemfile.lock b/Gemfile.lock
index abba97e5..b6ae5592 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -152,18 +152,6 @@ GEM
thor (>= 0.14, < 2.0)
json (2.2.0)
jwt (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)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
@@ -226,6 +214,7 @@ GEM
omniauth-oauth2 (1.6.0)
oauth2 (~> 1.1)
omniauth (~> 1.9)
+ pagy (2.1.5)
parallel (1.17.0)
parser (2.6.2.1)
ast (~> 2.4.0)
@@ -430,7 +419,6 @@ DEPENDENCIES
jbuilder
jquery-rails
jwt
- kaminari
listen
local_time
lograge
@@ -441,6 +429,7 @@ DEPENDENCIES
octokit
oj
omniauth-github
+ pagy
percy-capybara
pg (= 1.1.4)
pg_search
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 0481b122..61f53dfd 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
class ApplicationController < ActionController::Base
+ include Pagy::Backend
API_HEADER = 'X-Octobox-API'
protect_from_forgery with: :exception, unless: -> { octobox_api_request? }
diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb
index 502f03f4..1e9f9ee8 100644
--- a/app/controllers/notifications_controller.rb
+++ b/app/controllers/notifications_controller.rb
@@ -124,7 +124,6 @@ class NotificationsController < ApplicationController
end
def comment
-
subject = current_user.notifications.find(params[:id]).subject
if current_user.can_comment?(subject)
@@ -136,7 +135,7 @@ class NotificationsController < ApplicationController
end
else
flash[:error] = 'Could not post your comment'
- redirect_back fallback_location: notification_path
+ redirect_back fallback_location: notification_path
end
end
@@ -318,8 +317,8 @@ class NotificationsController < ApplicationController
check_out_of_bounds(scope)
@unread_count = user_unread_count
- @notifications = scope.page(page).per(per_page)
- @total = @notifications.total_count
+ @pagy, @notifications = pagy(scope, items: per_page, size: [1,2,2,1])
+ @total = @pagy.count
@cur_selected = [per_page, @total].min
return scope
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 9337cdf1..d2b6038d 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1,4 +1,5 @@
module ApplicationHelper
+ include Pagy::Frontend
ALERT_TYPES = {
success: 'alert-success',
error: 'alert-danger',
diff --git a/app/models/notification.rb b/app/models/notification.rb
index e758c7b4..4a386bfb 100644
--- a/app/models/notification.rb
+++ b/app/models/notification.rb
@@ -37,8 +37,6 @@ class Notification < ApplicationRecord
after_update :push_if_changed
- paginates_per 20
-
class << self
def attributes_from_api_response(api_response)
attrs = DownloadService::API_ATTRIBUTE_MAP.map do |attr, path|
diff --git a/app/views/kaminari/_first_page.html.erb b/app/views/kaminari/_first_page.html.erb
deleted file mode 100644
index f841d7db..00000000
--- a/app/views/kaminari/_first_page.html.erb
+++ /dev/null
@@ -1,9 +0,0 @@
-<% if current_page.first? %>
-
- <%= raw(t 'views.pagination.first') %>
-
-<% else %>
-
- <%= link_to raw(t 'views.pagination.first'), url, :remote => remote, :class=>"page-link" %>
-
-<% end %>
diff --git a/app/views/kaminari/_gap.html.erb b/app/views/kaminari/_gap.html.erb
deleted file mode 100644
index 04e1572a..00000000
--- a/app/views/kaminari/_gap.html.erb
+++ /dev/null
@@ -1,3 +0,0 @@
-
- <%= raw(t 'views.pagination.truncate') %>
-
diff --git a/app/views/kaminari/_last_page.html.erb b/app/views/kaminari/_last_page.html.erb
deleted file mode 100644
index 0e3801e2..00000000
--- a/app/views/kaminari/_last_page.html.erb
+++ /dev/null
@@ -1,3 +0,0 @@
-
- <%= link_to_unless current_page.last?, raw(t 'views.pagination.last'), url, {:remote => remote, :class=>"page-link" } %>
-
diff --git a/app/views/kaminari/_next_page.html.erb b/app/views/kaminari/_next_page.html.erb
deleted file mode 100644
index 1ee8557f..00000000
--- a/app/views/kaminari/_next_page.html.erb
+++ /dev/null
@@ -1,9 +0,0 @@
-<% if current_page.last? %>
-
- <%= raw(t 'views.pagination.next') %>
-
-<% else %>
-
- <%= link_to raw(t 'views.pagination.next'), url, :rel => 'next', :remote => remote, :class=>"page-link" %>
-
-<% end %>
diff --git a/app/views/kaminari/_page.html.erb b/app/views/kaminari/_page.html.erb
deleted file mode 100644
index c933b636..00000000
--- a/app/views/kaminari/_page.html.erb
+++ /dev/null
@@ -1,9 +0,0 @@
-<% if page.current? %>
-
- <%= content_tag :a, page, remote: remote, rel: (page.next? ? 'next' : (page.prev? ? 'prev' : nil)), :class=>"page-link" %>
-
-<% else %>
-
- <%= link_to page, url, remote: remote, rel: (page.next? ? 'next' : (page.prev? ? 'prev' : nil)), :class=>"page-link" %>
-
-<% end %>
diff --git a/app/views/kaminari/_paginator.html.erb b/app/views/kaminari/_paginator.html.erb
deleted file mode 100644
index 2bb98808..00000000
--- a/app/views/kaminari/_paginator.html.erb
+++ /dev/null
@@ -1,13 +0,0 @@
-<%= paginator.render do -%>
-
-<% end -%>
diff --git a/app/views/kaminari/_prev_page.html.erb b/app/views/kaminari/_prev_page.html.erb
deleted file mode 100644
index 15135507..00000000
--- a/app/views/kaminari/_prev_page.html.erb
+++ /dev/null
@@ -1,9 +0,0 @@
-<% if current_page.first? %>
-
- <%= raw(t 'views.pagination.previous') %>
-
-<% else %>
-
- <%= link_to raw(t 'views.pagination.previous'), url, :rel => 'prev', :remote => remote, :class=>"page-link" %>
-
-<% end %>
diff --git a/app/views/notifications/_list.html.erb b/app/views/notifications/_list.html.erb
index c263c008..916a6f26 100644
--- a/app/views/notifications/_list.html.erb
+++ b/app/views/notifications/_list.html.erb
@@ -90,13 +90,10 @@
<% end %>
-
-
- <%= paginate @notifications %>
+
+ <%== render 'pagination', pagy: @pagy %>
<%= render 'layouts/footer' %>
diff --git a/app/views/notifications/_pagination.html.erb b/app/views/notifications/_pagination.html.erb
new file mode 100644
index 00000000..0c4d915b
--- /dev/null
+++ b/app/views/notifications/_pagination.html.erb
@@ -0,0 +1,22 @@
+<% if pagy.pages > 1 %>
+ <% link = pagy_link_proc(pagy, 'class="page-link"') -%>
+
+<% end %>
diff --git a/config/initializers/pagy.rb b/config/initializers/pagy.rb
new file mode 100644
index 00000000..74e05edd
--- /dev/null
+++ b/config/initializers/pagy.rb
@@ -0,0 +1,4 @@
+require 'pagy/extras/headers'
+Pagy::VARS[:items] = 20
+require 'pagy/extras/overflow'
+Pagy::VARS[:overflow] = :last_page
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 1273fa4f..61bda079 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -20,10 +20,6 @@
# available at http://guides.rubyonrails.org/i18n.html.
en:
- views:
- pagination:
- previous: 'Previous'
- next: 'Next'
exceptions:
octokit:
unauthorized: 'Your GitHub token seems to be invalid'