From cd121760224fe69989ec1e603202334b3bbe688c Mon Sep 17 00:00:00 2001 From: Aditya Vats Date: Sat, 3 Oct 2020 01:24:08 +0530 Subject: [PATCH] Migrate to pagy completely for notes' pagination (#8429) * Add .deepsource.toml * Delete .deepsource.toml * migrate to pagy for notes Co-authored-by: DeepSource Bot --- app/controllers/notes_controller.rb | 9 ++++----- app/views/notes/_coauthored_notes.html.erb | 6 +++++- app/views/notes/_draft_notes.html.erb | 6 +++++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 3070a8bec8..331d461128 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -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)') @@ -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. @@ -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 diff --git a/app/views/notes/_coauthored_notes.html.erb b/app/views/notes/_coauthored_notes.html.erb index e250d61232..bf203921a9 100644 --- a/app/views/notes/_coauthored_notes.html.erb +++ b/app/views/notes/_coauthored_notes.html.erb @@ -67,4 +67,8 @@ <% end %> -<%= 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 %> diff --git a/app/views/notes/_draft_notes.html.erb b/app/views/notes/_draft_notes.html.erb index 75bd84d0f4..f591a9ebeb 100644 --- a/app/views/notes/_draft_notes.html.erb +++ b/app/views/notes/_draft_notes.html.erb @@ -67,4 +67,8 @@ <% end %> -<%= 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 %>