Update sort.

This commit is contained in:
BoHung Chiu 2022-07-26 19:09:38 +08:00
parent ecf1dee968
commit ee55f63fa8
4 changed files with 7 additions and 5 deletions

View File

@ -10,7 +10,7 @@ class Admin::DiplomasController < OrbitMemberController
before_action :allow_admin_only, :only => [:index, :setting] before_action :allow_admin_only, :only => [:index, :setting]
def index def index
@diplomas = Diploma.order_by(:end_date=>'desc',:start_date=>'desc').page(params[:page]).per(10) @diplomas = Diploma.sort_date.page(params[:page]).per(10)
end end
def new def new

View File

@ -1,6 +1,6 @@
class PersonalDiplomasController < ApplicationController class PersonalDiplomasController < ApplicationController
def index def index
diplomas = Diploma.where(:is_hidden=>false).order_by(:end_date=>'desc', :start_date=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) diplomas = Diploma.sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
fields_to_show = Page.where(:page_id => params[:page_id]).first.custom_array_field rescue [] fields_to_show = Page.where(:page_id => params[:page_id]).first.custom_array_field rescue []
if fields_to_show.blank? if fields_to_show.blank?
fields_to_show = [ fields_to_show = [

View File

@ -25,7 +25,9 @@ class Diploma
before_validation :add_http before_validation :add_http
scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:end_date => "desc", :start_date => "desc") } index({end_date: -1, start_date: -1, _id: -1}, { unique: false, background: false })
scope :sort_date, ->{ order_by(:end_date => "desc", :start_date => "desc", :id => "desc") }
scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:end_date => "desc", :start_date => "desc", :id => "desc") }
def duration def duration
if !self.start_date.nil? or !self.end_date.nil? if !self.start_date.nil? or !self.end_date.nil?

View File

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