Update sort.

This commit is contained in:
BoHung Chiu 2022-07-26 19:13:36 +08:00
parent 7d65070611
commit 8f6a823516
4 changed files with 8 additions and 6 deletions

View File

@ -25,7 +25,7 @@ class Admin::BooksController < OrbitMemberController
redirect_to :action=> 'index'
end
def merge
@books=Book.order_by(:year=>'desc').map{|value| value}.group_by{|v| [v[:book_title],v[:isbn]]}
@books=Book.sort_year_date.map{|value| value}.group_by{|v| [v[:book_title],v[:isbn]]}
@books.each do |key,value|
if value.length<=1
@books.delete key
@ -48,7 +48,7 @@ class Admin::BooksController < OrbitMemberController
end
def index
@writing_books = Book.order_by(:year=>'desc').page(params[:page]).per(10)
@writing_books = Book.sort_year_date.page(params[:page]).per(10)
respond_to do |format|
format.html # index.html.erb
format.js { }

View File

@ -3,7 +3,7 @@ class PersonalBooksController < ApplicationController
def index
params = OrbitHelper.params
page_data_count = OrbitHelper.page_data_count
books = Book.where(is_hidden: false).sort_for_frontend.page(OrbitHelper.params[:page_no]).per(page_data_count)
books = Book.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'

View File

@ -39,7 +39,9 @@ class Book
before_validation :add_http
scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year => "desc", :publish_date => "desc", :publication_date => "desc") }
index({year: -1, :publish_date => -1, :publication_date => -1, _id: -1}, { unique: false, background: false })
scope :sort_year_date, ->{ order_by(:year => "desc", :publish_date => "desc", :publication_date => "desc", :id => "desc")) }
scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year => "desc", :publish_date => "desc", :publication_date => "desc", :id => "desc") }
def book_paper_type
self.book_type.title rescue ""
end

View File

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