From d1379bf8cd33c78a7bb3638927db28ce0e2c2c65 Mon Sep 17 00:00:00 2001 From: bohung Date: Tue, 26 Jul 2022 19:04:00 +0800 Subject: [PATCH] Update sort. --- app/controllers/admin/journal_papers_controller.rb | 4 ++-- app/controllers/personal_journals_controller.rb | 2 +- app/models/journal_paper.rb | 5 +++-- app/views/plugin/personal_journal/_profile.html.erb | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/journal_papers_controller.rb b/app/controllers/admin/journal_papers_controller.rb index ffe8624..ceff8d9 100644 --- a/app/controllers/admin/journal_papers_controller.rb +++ b/app/controllers/admin/journal_papers_controller.rb @@ -25,7 +25,7 @@ class Admin::JournalPapersController < OrbitMemberController redirect_to :action=> 'index' end def merge - @journals=JournalPaper.order_by(:year=>'desc').map{|value| value}.group_by{|v| [v[:paper_title],v[:journal_title]]} + @journals=JournalPaper.sort_year_date.map{|value| value}.group_by{|v| [v[:paper_title],v[:journal_title]]} @journals.each do |key,value| if value.length<=1 @journals.delete key @@ -47,7 +47,7 @@ class Admin::JournalPapersController < OrbitMemberController end end def index - @writing_journals = JournalPaper.order_by(:year=>'desc').page(params[:page]).per(10) + @writing_journals = JournalPaper.sort_year_date.page(params[:page]).per(10) end def new diff --git a/app/controllers/personal_journals_controller.rb b/app/controllers/personal_journals_controller.rb index 8904fd1..4aee316 100644 --- a/app/controllers/personal_journals_controller.rb +++ b/app/controllers/personal_journals_controller.rb @@ -3,7 +3,7 @@ class PersonalJournalsController < ApplicationController def index params = OrbitHelper.params page_data_count = OrbitHelper.page_data_count - journal_papers = JournalPaper.where(is_hidden: false).sort_for_frontend.page(OrbitHelper.params[:page_no]).per(page_data_count) + journal_papers = JournalPaper.sort_for_frontend.page(OrbitHelper.params[:page_no]).per(page_data_count) page = Page.where(page_id: params[:page_id]).first rescue nil if page.custom_string_field == 'table' fields_to_show = page.custom_array_field rescue [] diff --git a/app/models/journal_paper.rb b/app/models/journal_paper.rb index 7370447..6a43f3c 100644 --- a/app/models/journal_paper.rb +++ b/app/models/journal_paper.rb @@ -47,8 +47,9 @@ class JournalPaper before_validation :add_http # validates :paper_title, presence: true - - scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year => "desc", :publication_date => "desc") } + index({year: -1, :publication_date => -1, _id: -1}, { unique: false, background: false }) + scope :sort_year_date, ->{ order_by(:year => "desc", :publication_date => "desc", :id=>"desc") } + scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year => "desc", :publication_date => "desc", :id=>"desc") } def create_link title = [] diff --git a/app/views/plugin/personal_journal/_profile.html.erb b/app/views/plugin/personal_journal/_profile.html.erb index 395bce3..6eafbd7 100644 --- a/app/views/plugin/personal_journal/_profile.html.erb +++ b/app/views/plugin/personal_journal/_profile.html.erb @@ -6,9 +6,9 @@ <% end %> <% if has_access? - @writing_journals = JournalPaper.where(member_profile_id: @member.id).desc(:year).page(params[:page]).per(10) + @writing_journals = JournalPaper.where(member_profile_id: @member.id).sort_year_date.page(params[:page]).per(10) else - @writing_journals = JournalPaper.where(is_hidden: false, member_profile_id: @member.id).desc(:year).page(params[:page]).per(10) + @writing_journals = JournalPaper.where(is_hidden: false, member_profile_id: @member.id).sort_year_date.page(params[:page]).per(10) end %> <% if has_access? %>