Update sort.

This commit is contained in:
BoHung Chiu 2022-07-26 19:08:29 +08:00
parent 9301c212d0
commit 6440b2c314
4 changed files with 9 additions and 7 deletions

View File

@ -11,7 +11,7 @@ class Admin::ExperiencesController < OrbitMemberController
before_action :allow_admin_only, :only => [:index, :setting]
def index
@experiences = Experience.desc(:end_date).page(params[:page]).per(10)
@experiences = Experience.sort_date.page(params[:page]).per(10)
end
def new

View File

@ -1,6 +1,6 @@
class PersonalExperiencesController < ApplicationController
def index
experiences = Experience.where(:is_hidden=>false).order_by(:end_date=>'desc',:start_date=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
experiences = Experience.sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
experience_list = experiences.collect do |experience|
{
"member" => (experience.member_profile.name rescue ""),

View File

@ -25,7 +25,9 @@ class Experience
before_validation :add_http
scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:start_date => "desc")}
index({start_date: -1, :end_date => -1, _id: -1}, { unique: false, background: false })
scope :sort_date, ->{ order_by(:start_date => "desc", :end_date => "desc", :id => "desc") }
scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:start_date => "desc", :end_date => "desc", :id => "desc")}
def duration
if !self.start_date.nil? or !self.end_date.nil?
@ -68,7 +70,7 @@ class Experience
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|
@ -95,7 +97,7 @@ class Experience
"honor_type"=>"",
"pd_datas" => pd_data,
"type-sort" => (p.experience_type.sort_position.to_i rescue 1000),
"sort-index" => index
"sort-index" => idx
}
end

View File

@ -7,9 +7,9 @@
<%
if has_access?
@experiences = Experience.where(member_profile_id: @member.id).order_by(:start_date => "desc", :end_date => "desc").page(params[:page]).per(10)
@experiences = Experience.where(member_profile_id: @member.id).sort_date.page(params[:page]).per(10)
else
@experiences = Experience.where(is_hidden: false, member_profile_id: @member.id).order_by(:start_date => "desc", :end_date => "desc").page(params[:page]).per(10)
@experiences = Experience.where(is_hidden: false, member_profile_id: @member.id).sort_date.page(params[:page]).per(10)
end
%>