зеркало из https://github.com/github/octobox.git
Swap kaminari paginator for pagy (#1741)
* Swap kaminari paginator for pagy * Swap kaminari paginator for pagy
This commit is contained in:
Родитель
28d4c37b80
Коммит
5f03663f58
2
Gemfile
2
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'
|
||||
|
|
15
Gemfile.lock
15
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
|
||||
|
|
|
@ -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? }
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
module ApplicationHelper
|
||||
include Pagy::Frontend
|
||||
ALERT_TYPES = {
|
||||
success: 'alert-success',
|
||||
error: 'alert-danger',
|
||||
|
|
|
@ -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|
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
<% if current_page.first? %>
|
||||
<li class="page-item disabled">
|
||||
<span class="page-link"><%= raw(t 'views.pagination.first') %></span>
|
||||
</li>
|
||||
<% else %>
|
||||
<li class="page-item">
|
||||
<%= link_to raw(t 'views.pagination.first'), url, :remote => remote, :class=>"page-link" %>
|
||||
</li>
|
||||
<% end %>
|
|
@ -1,3 +0,0 @@
|
|||
<li class='page-item disabled'>
|
||||
<span class="page-link"><%= raw(t 'views.pagination.truncate') %></span>
|
||||
</li>
|
|
@ -1,3 +0,0 @@
|
|||
<li class="page-item">
|
||||
<%= link_to_unless current_page.last?, raw(t 'views.pagination.last'), url, {:remote => remote, :class=>"page-link" } %>
|
||||
</li>
|
|
@ -1,9 +0,0 @@
|
|||
<% if current_page.last? %>
|
||||
<li class="page-item disabled">
|
||||
<span class="page-link"><%= raw(t 'views.pagination.next') %></span>
|
||||
</li>
|
||||
<% else %>
|
||||
<li class="page-item">
|
||||
<%= link_to raw(t 'views.pagination.next'), url, :rel => 'next', :remote => remote, :class=>"page-link" %>
|
||||
</li>
|
||||
<% end %>
|
|
@ -1,9 +0,0 @@
|
|||
<% if page.current? %>
|
||||
<li class='page-item active'>
|
||||
<%= content_tag :a, page, remote: remote, rel: (page.next? ? 'next' : (page.prev? ? 'prev' : nil)), :class=>"page-link" %>
|
||||
</li>
|
||||
<% else %>
|
||||
<li class="page-item">
|
||||
<%= link_to page, url, remote: remote, rel: (page.next? ? 'next' : (page.prev? ? 'prev' : nil)), :class=>"page-link" %>
|
||||
</li>
|
||||
<% end %>
|
|
@ -1,13 +0,0 @@
|
|||
<%= paginator.render do -%>
|
||||
<ul class="pagination justify-content-center mb-0">
|
||||
<%= prev_page_tag %>
|
||||
<% each_page do |page| -%>
|
||||
<% if page.left_outer? || page.right_outer? || page.inside_window? -%>
|
||||
<%= page_tag page %>
|
||||
<% elsif !page.was_truncated? -%>
|
||||
<%= gap_tag %>
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
<%= next_page_tag %>
|
||||
</ul>
|
||||
<% end -%>
|
|
@ -1,9 +0,0 @@
|
|||
<% if current_page.first? %>
|
||||
<li class="page-item disabled">
|
||||
<span class="page-link"><%= raw(t 'views.pagination.previous') %></span>
|
||||
</li>
|
||||
<% else %>
|
||||
<li class="page-item">
|
||||
<%= link_to raw(t 'views.pagination.previous'), url, :rel => 'prev', :remote => remote, :class=>"page-link" %>
|
||||
</li>
|
||||
<% end %>
|
|
@ -90,13 +90,10 @@
|
|||
</div>
|
||||
<% end %>
|
||||
</table>
|
||||
<div class="card-footer d-block d-lg-none mb-0">
|
||||
<%= paginate @notifications, left: 1, right: 1, window: 0 %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="d-none d-md-flex justify-content-center">
|
||||
<%= paginate @notifications %>
|
||||
<div class="d-flex justify-content-center">
|
||||
<%== render 'pagination', pagy: @pagy %>
|
||||
</div>
|
||||
|
||||
<%= render 'layouts/footer' %>
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
<% if pagy.pages > 1 %>
|
||||
<% link = pagy_link_proc(pagy, 'class="page-link"') -%>
|
||||
<nav aria-label="pager" class="pagy-bootstrap-nav pagination" role="navigation">
|
||||
<ul class="pagination">
|
||||
<% if pagy.prev -%>
|
||||
<li class="page-item prev"><%== link.call(pagy.prev, 'Previous', 'aria-label="previous"') %></li>
|
||||
<% end -%>
|
||||
<% pagy.series.each do |item| -%>
|
||||
<% if item.is_a?(Integer) -%>
|
||||
<li class="page-item"><%== link.call(item) %></li>
|
||||
<% elsif item.is_a?(String) -%>
|
||||
<li class="page-item active"><%== link.call(item) %></li>
|
||||
<% elsif item == :gap -%>
|
||||
<li class="page-item disabled gap"><a href="#" class="page-link"><%== pagy_t('pagy.nav.gap') %></a></li>
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
<% if pagy.next -%>
|
||||
<li class="page-item next"><%== link.call(pagy.next, 'Next', 'aria-label="next"') %></li>
|
||||
<% end -%>
|
||||
</ul>
|
||||
</nav>
|
||||
<% end %>
|
|
@ -0,0 +1,4 @@
|
|||
require 'pagy/extras/headers'
|
||||
Pagy::VARS[:items] = 20
|
||||
require 'pagy/extras/overflow'
|
||||
Pagy::VARS[:overflow] = :last_page
|
|
@ -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'
|
||||
|
|
Загрузка…
Ссылка в новой задаче