Update sort.

This commit is contained in:
BoHung Chiu 2022-07-26 19:02:43 +08:00
parent a92b6993c9
commit 26e9ef8d43
4 changed files with 8 additions and 6 deletions

View File

@ -26,7 +26,7 @@ class Admin::PatentsController < OrbitMemberController
redirect_to :action=> 'index'
end
def merge
@patents=Patent.order_by(:year=>'desc').map{|value| value}.group_by{|v| [v[:patent_title],v[:patent_no]]}
@patents=Patent.sort_year_date.map{|value| value}.group_by{|v| [v[:patent_title],v[:patent_no]]}
@patents.each do |key,value|
if value.length<=1
@patents.delete key
@ -49,7 +49,7 @@ class Admin::PatentsController < OrbitMemberController
end
def index
@patents = Patent.order_by(:year=>'desc').page(params[:page]).per(10)
@patents = Patent.sort_year_date.page(params[:page]).per(10)
end
def new

View File

@ -3,7 +3,7 @@ class PersonalPatentsController < ApplicationController
def index
params = OrbitHelper.params
page_data_count = OrbitHelper.page_data_count
patents = Patent.where(is_hidden: false).sort_for_frontend.page(OrbitHelper.params[:page_no]).per(page_data_count)
patents = Patent.sort_for_frontend.page(OrbitHelper.params[:page_no]).per(page_data_count)
fields_to_show = Page.where(page_id: params[:page_id]).first.custom_array_field rescue []
if fields_to_show.blank?
fields_to_show = %w[

View File

@ -34,7 +34,9 @@ class Patent
before_validation :add_http
scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year => "desc", :application_date => "desc", :publish_date => "desc") }
index({year: -1, application_date: -1, publish_date: -1, _id: -1}, { unique: false, background: false })
scope :sort_year_date, ->{ order_by(:year => "desc", :application_date => "desc", :publish_date => "desc", :id => "desc") }
scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year => "desc", :application_date => "desc", :publish_date => "desc", :id => "desc") }
def member_profile()
(super || MemberProfile.find(self.member_profile_id)) rescue nil

View File

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