forked from saurabh/personal-book
Update sort.
This commit is contained in:
parent
7d65070611
commit
8f6a823516
|
@ -25,7 +25,7 @@ class Admin::BooksController < OrbitMemberController
|
||||||
redirect_to :action=> 'index'
|
redirect_to :action=> 'index'
|
||||||
end
|
end
|
||||||
def merge
|
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|
|
@books.each do |key,value|
|
||||||
if value.length<=1
|
if value.length<=1
|
||||||
@books.delete key
|
@books.delete key
|
||||||
|
@ -48,7 +48,7 @@ class Admin::BooksController < OrbitMemberController
|
||||||
end
|
end
|
||||||
|
|
||||||
def index
|
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|
|
respond_to do |format|
|
||||||
format.html # index.html.erb
|
format.html # index.html.erb
|
||||||
format.js { }
|
format.js { }
|
||||||
|
|
|
@ -3,7 +3,7 @@ class PersonalBooksController < ApplicationController
|
||||||
def index
|
def index
|
||||||
params = OrbitHelper.params
|
params = OrbitHelper.params
|
||||||
page_data_count = OrbitHelper.page_data_count
|
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
|
page = Page.where(page_id: params[:page_id]).first rescue nil
|
||||||
|
|
||||||
if page.custom_string_field == 'table'
|
if page.custom_string_field == 'table'
|
||||||
|
|
|
@ -39,7 +39,9 @@ class Book
|
||||||
|
|
||||||
before_validation :add_http
|
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
|
def book_paper_type
|
||||||
self.book_type.title rescue ""
|
self.book_type.title rescue ""
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
|
|
||||||
<%
|
<%
|
||||||
if has_access?
|
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
|
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
|
end
|
||||||
%>
|
%>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue