Skip to content

Commit

Permalink
add pagy for all wiki routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tlazypanda committed Sep 24, 2020
1 parent e4a0bbf commit a43f823
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
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'
take_screenshot
end

Expand Down

0 comments on commit a43f823

Please sign in to comment.