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

Migrate to pagy completely for notes' pagination #8429

Merged
merged 3 commits into from
Oct 2, 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
9 changes: 4 additions & 5 deletions app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def tools

def places
@title = 'Places'
@notes = Node.joins('LEFT OUTER JOIN node_revisions ON node_revisions.nid = node.nid
@pagy, @notes = pagy(Node.joins('LEFT OUTER JOIN node_revisions ON node_revisions.nid = node.nid
LEFT OUTER JOIN community_tags ON community_tags.nid = node.nid
LEFT OUTER JOIN term_data ON term_data.tid = community_tags.tid')
.select('*, max(node_revisions.timestamp)')
Expand All @@ -23,8 +23,7 @@ def places
.references(:term_data)
.where('term_data.name = ?', 'chapter')
.group('node.nid')
.order(Arel.sql('max(node_revisions.timestamp) DESC, node.nid'))
.paginate(page: params[:page], per_page: 24)
.order(Arel.sql('max(node_revisions.timestamp) DESC, node.nid')), items: 24)

# Arel.sql is used to remove a Deprecation warning while updating to rails 5.2.

Expand Down Expand Up @@ -274,9 +273,9 @@ def delete
def author
@user = User.find_by(name: params[:id])
@title = @user.name
@notes = Node.paginate(page: params[:page], per_page: 24)
@pagy, @notes = pagy(Node
.order('nid DESC')
.where(type: 'note', status: 1, uid: @user.uid)
.where(type: 'note', status: 1, uid: @user.uid), items: 24)
render template: 'notes/index'
end

Expand Down
6 changes: 5 additions & 1 deletion app/views/notes/_coauthored_notes.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,8 @@
<% end %>
</div>
</div>
<%= will_paginate notes, renderer: WillPaginate::ActionView::BootstrapLinkRenderer unless @unpaginated %>
<% if @pagy %>
<%== pagy_bootstrap_nav @pagy %>
<% else %>
<%= will_paginate notes, renderer: WillPaginate::ActionView::BootstrapLinkRenderer unless @unpaginated %>
<% end %>
6 changes: 5 additions & 1 deletion app/views/notes/_draft_notes.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,8 @@
<% end %>
</div>
</div>
<%= will_paginate notes, renderer: WillPaginate::ActionView::BootstrapLinkRenderer unless @unpaginated %>
<% if @pagy %>
<%== pagy_bootstrap_nav @pagy %>
<% else %>
<%= will_paginate notes, renderer: WillPaginate::ActionView::BootstrapLinkRenderer unless @unpaginated %>
<% end %>