Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pagy for all wiki routes #8428

Merged
merged 1 commit into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include ActionView::Helpers::DateHelper # required for time_ago_in_words()
include Pagy::Backend
class ApplicationController < ActionController::Base
protect_from_forgery unless: -> { is_dataurl_post }
layout 'application'
Expand Down
16 changes: 7 additions & 9 deletions app/controllers/wiki_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def revisions
@node = Node.find_wiki(params[:id])
if @node
@revisions = @node.revisions
@revisions = @revisions.where(status: 1).page(params[:page]).per_page(20) unless current_user&.can_moderate?
@pagy_revisions, @revisions = pagy(@revisions.where(status: 1), items: 20) unless current_user&.can_moderate?
@title = I18n.t('wiki_controller.revisions_for', title: @node.title).html_safe
@tags = @node.tags
@paginated = true unless current_user&.can_moderate?
Expand Down Expand Up @@ -333,25 +333,23 @@ def index
order_string = 'cached_likes DESC'
end

@wikis = Node.includes(:revision)
@pagy, @wikis = pagy(Node.includes(:revision)
.references(:node_revisions)
.group('node_revisions.nid, node_revisions.vid')
.order(order_string)
.where("node_revisions.status = 1 AND node.status = 1 AND (type = 'page' OR type = 'tool' OR type = 'place')")
.page(params[:page])
.where("node_revisions.status = 1 AND node.status = 1 AND (type = 'page' OR type = 'tool' OR type = 'place')"))

@paginated = true
end

def stale
@title = I18n.t('wiki_controller.wiki')

@wikis = Node.includes(:revision)
@pagy, @wikis = pagy(Node.includes(:revision)
.references(:node_revisions)
.group('node_revisions.nid, node_revisions.vid')
.order('node_revisions.timestamp ASC')
.where("node_revisions.status = 1 AND node.status = 1 AND (type = 'page' OR type = 'tool' OR type = 'place')")
.page(params[:page])
.where("node_revisions.status = 1 AND node.status = 1 AND (type = 'page' OR type = 'tool' OR type = 'place')"))

@paginated = true
render template: 'wiki/index'
Expand Down Expand Up @@ -492,9 +490,9 @@ def update_node_attributes
def author
@user = User.find_by(name: params[:id])
@title = @user.name
@wikis = Node.paginate(page: params[:page], per_page: 24)
@pagy, @wikis = pagy(Node
.order('nid DESC')
.where("uid = ? AND type = 'page' OR type = 'place' OR type = 'tool' AND status = 1", @user.uid)
.where("uid = ? AND type = 'page' OR type = 'place' OR type = 'tool' AND status = 1", @user.uid), items: 24)
render template: 'wiki/index'
end
end
4 changes: 4 additions & 0 deletions app/views/wiki/revisions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@
</table>

<hr />
<% if @pagy_revisions %>
<%= raw pagy_bootstrap_nav(@pagy_revisions) if @paginated %>
<% else %>
<%= will_paginate @revisions, renderer: WillPaginate::ActionView::BootstrapLinkRenderer if @paginated %>
<% end %>
</div>
<div class="col-lg-7">
<div class="btn-group float-right">
Expand Down
2 changes: 1 addition & 1 deletion test/system/screenshots_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class ScreenshotsTest < ApplicationSystemTestCase

test 'wiki revisions' do
visit "/wiki/revisions/#{nodes(:about).slug}"
click_on '1'
click_on '2'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooh nice catch...

take_screenshot
end

Expand Down