Update sort.

This commit is contained in:
BoHung Chiu 2022-07-26 19:00:48 +08:00
parent 7d3ebbf54b
commit c1c1af1b74
4 changed files with 9 additions and 7 deletions

View File

@ -10,7 +10,7 @@ class Admin::ResearchsController < OrbitMemberController
before_action :allow_admin_only, :only => [:index, :setting]
def index
@researchs = Research.order_by(:year=>'desc').page(params[:page]).per(10)
@researchs = Research.sort_year_date.page(params[:page]).per(10)
end
def new

View File

@ -1,6 +1,6 @@
class PersonalResearchesController < ApplicationController
def index
researchs = Research.where(:is_hidden=>false).order_by(:year=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
researchs = Research.sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
research_list = researchs.collect do |research|
member = research.member_profile
path = OrbitHelper.url_to_plugin_show(member.to_param, 'member') rescue '#'

View File

@ -30,7 +30,9 @@ class Research
before_validation :add_http
scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year => "desc", :publish_date => "desc") }
index({year: -1, publish_date: -1, _id: -1}, { unique: false, background: false })
scope :sort_year_date, ->{ order_by(:year => "desc", :publish_date => "desc", :id => "desc") }
scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year => "desc", :publish_date => "desc", :id => "desc") }
def get_plugin_data(fields_to_show)
plugin_datas = []
@ -69,7 +71,7 @@ class Research
fields_to_show = fields_to_show - fields_to_remove
plugin_datas = datas.sort_for_frontend.collect.with_index do |p, index|
plugin_datas = datas.sort_for_frontend.collect.with_index do |p, idx|
pd_data = []
fields_to_show.collect do |t|
@ -85,7 +87,7 @@ class Research
{
"pd_datas" => pd_data,
"type-sort" => (p.research_category.sort_position.to_i rescue -1),
"sort-index" => index
"sort-index" => idx
}
end

View File

@ -7,9 +7,9 @@
<%
if has_access?
@researchs = Research.where(member_profile_id: @member.id).desc(:year).page(params[:page]).per(10)
@researchs = Research.where(member_profile_id: @member.id).sort_year_date.page(params[:page]).per(10)
else
@researchs = Research.where(is_hidden: false, member_profile_id: @member.id).desc(:year).page(params[:page]).per(10)
@researchs = Research.where(is_hidden: false, member_profile_id: @member.id).sort_year_date.page(params[:page]).per(10)
end
%>