Skip to content

Commit

Permalink
Migrate to pagy completely for notes' pagination (publiclab#8429)
Browse files Browse the repository at this point in the history
* Add .deepsource.toml

* Delete .deepsource.toml

* migrate to pagy for notes

Co-authored-by: DeepSource Bot <bot@deepsource.io>
  • Loading branch information
2 people authored and billymoroney1 committed Dec 28, 2021
1 parent 53a3b9d commit c79ef92
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
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 %>

0 comments on commit c79ef92

Please sign in to comment.