diff --git a/Gemfile b/Gemfile index 976fc1a1a5..3b47f3c4d1 100644 --- a/Gemfile +++ b/Gemfile @@ -64,6 +64,7 @@ gem 'unicode-emoji' gem 'whenever', require: false gem 'will_paginate', '>= 3.0.6' gem 'will_paginate-bootstrap4' +gem 'pagy', '>=3.8.3' gem 'jquery-atwho-rails' gem 'lemmatizer', '~> 0.2.2' # To implement incoming mail processing microframework diff --git a/Gemfile.lock b/Gemfile.lock index b9649ca012..c8d523af57 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -103,6 +103,7 @@ GEM crack (0.4.3) safe_yaml (~> 1.0.0) crass (1.0.6) + critical-path-css-rails (3.1.0) declarative (0.0.20) declarative-option (0.1.0) diff-lcs (1.3) @@ -265,6 +266,7 @@ GEM listen (3.2.1) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) + loadcss-rails (2.0.1) loofah (2.6.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -343,6 +345,7 @@ GEM openssl (2.2.0) options (2.3.2) os (1.1.0) + pagy (3.8.3) paperclip (6.1.0) activemodel (>= 4.2.0) activesupport (>= 4.2.0) @@ -595,6 +598,7 @@ DEPENDENCIES codecov coffee-rails (~> 5.0.0) composite_primary_keys + critical-path-css-rails (~> 3.1.0) execjs figaro font-awesome-rails @@ -626,6 +630,7 @@ DEPENDENCIES less-rails (~> 5.0) letter_opener listen (~> 3.2.1) + loadcss-rails (~> 2.0.1) mailman minitest-reporters (~> 1.4.2) mocha (~> 1.11) @@ -638,6 +643,7 @@ DEPENDENCIES omniauth-google-oauth2 omniauth-twitter openssl (~> 2.2.0) + pagy (>= 3.8.3) paperclip (~> 6.1.0) passenger phantomjs diff --git a/app/controllers/tag_controller.rb b/app/controllers/tag_controller.rb index 1d0f10f2ef..88588705b3 100644 --- a/app/controllers/tag_controller.rb +++ b/app/controllers/tag_controller.rb @@ -1,6 +1,7 @@ class TagController < ApplicationController respond_to :html, :xml, :json, :ics before_action :require_user, only: %i(create delete add_parent) + include Pagy::Backend def index @toggle = params[:sort] || "uses" @@ -117,9 +118,6 @@ def show nodes = Node.for_tagname_and_type(params[:id], node_type, question: (@node_type == 'questions')) end - nodes = nodes.paginate(page: params[:page], per_page: 24).order(order_by) - @paginated = true - if @start && @end nodes = nodes.where(created: @start.to_i..@end.to_i) else @@ -129,6 +127,9 @@ def show end end + @pagy, nodes = pagy(nodes.order(order_by), items: 24) + @paginated = true + @qids = Node.questions.where(status: 1) .collect(&:nid) if @qids.empty? @@ -140,7 +141,7 @@ def show end @answered_questions = [] - @questions&.each { |question| @answered_questions << question if question.answers.any?(&:accepted) } + @questions&.each { |question| @answered_questions << question if question.answers.any?(&:accepted) } # TODO: remove this upon refactor to remove answers code @wikis = nodes if @node_type == 'wiki' @wikis ||= [] @nodes = nodes if @node_type == 'maps' diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 607f0990ae..c07b4ea564 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,4 +1,6 @@ module ApplicationHelper + include Pagy::Frontend + # returns true if user is logged in and has any of the roles given, as ['admin','moderator'] def logged_in_as(roles) return false unless current_user diff --git a/app/views/notes/_notes.html.erb b/app/views/notes/_notes.html.erb index 339963276d..6f3c1a4599 100644 --- a/app/views/notes/_notes.html.erb +++ b/app/views/notes/_notes.html.erb @@ -14,5 +14,8 @@ <% end %> -<%= will_paginate notes, renderer: WillPaginate::ActionView::BootstrapLinkRenderer unless @unpaginated || (unpaginated ||= false) %> - +<% if @pagy %> + <%== pagy_bootstrap_nav @pagy %> +<% else %> + <%= will_paginate notes, renderer: WillPaginate::ActionView::BootstrapLinkRenderer unless @unpaginated || (unpaginated ||= false) %> +<% end %> diff --git a/app/views/questions/_new_question.html.erb b/app/views/questions/_new_question.html.erb index a4b3672be4..174d594308 100644 --- a/app/views/questions/_new_question.html.erb +++ b/app/views/questions/_new_question.html.erb @@ -105,7 +105,14 @@ -