From 012e1c096235ec77ab7e9ba74ea0ef8ce30d9bf0 Mon Sep 17 00:00:00 2001 From: Jeffrey Warren Date: Tue, 22 Sep 2020 16:21:20 -0400 Subject: [PATCH] rework order_by for tag page wiki pagination (#8422) * rework order_by for https://github.com/publiclab/plots2/issues/7334 * adjust sort dropdown text * rubocop/codeclimate formatting --- app/controllers/tag_controller.rb | 21 ++++++++++----------- app/views/tag/show/_sort.html.erb | 16 +++++++++++++--- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/app/controllers/tag_controller.rb b/app/controllers/tag_controller.rb index e85d535938..154f4f05d1 100644 --- a/app/controllers/tag_controller.rb +++ b/app/controllers/tag_controller.rb @@ -83,22 +83,11 @@ def show @node = @wiki # expose the wiki node in the @node variable so we get open graph meta tags in the layout default_type = params[:id].match?('question:') ? 'questions' : 'note' - if params[:order].nil? - params[:order] = 'last_updated' # default ordering set - end @node_type = params[:node_type] || default_type @start = Time.parse(params[:start]) if params[:start] @end = Time.parse(params[:end]) if params[:end] - order_by = if params[:order] == 'views' - 'node.views DESC' - elsif params[:order] == 'likes' - 'node.cached_likes DESC' - elsif params[:order] == 'last_updated' - 'node_revisions.timestamp DESC' - end - node_type = if %w(questions note).include?(@node_type) 'note' elsif @node_type == 'wiki' @@ -127,6 +116,16 @@ def show end end + order_by = if params[:order] == 'views' + 'node.views DESC' + elsif params[:order] == 'likes' + 'node.cached_likes DESC' + elsif @node_type == 'wiki' # wiki sorting by timestamp isn't working; https://github.com/publiclab/plots2/issues/7334#issuecomment-696938352 + 'node.nid DESC' + else # params[:order] == 'last_updated' + 'node_revisions.timestamp DESC' + end + @pagy, nodes = pagy(nodes.order(order_by), items: 24) @paginated = true diff --git a/app/views/tag/show/_sort.html.erb b/app/views/tag/show/_sort.html.erb index f0203adc0a..3675c1adce 100644 --- a/app/views/tag/show/_sort.html.erb +++ b/app/views/tag/show/_sort.html.erb @@ -2,9 +2,19 @@