diff --git a/app/controllers/admin/experiences_controller.rb b/app/controllers/admin/experiences_controller.rb index adb4a3e..04e94f2 100644 --- a/app/controllers/admin/experiences_controller.rb +++ b/app/controllers/admin/experiences_controller.rb @@ -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 diff --git a/app/controllers/personal_experiences_controller.rb b/app/controllers/personal_experiences_controller.rb index feab8c8..886a55e 100644 --- a/app/controllers/personal_experiences_controller.rb +++ b/app/controllers/personal_experiences_controller.rb @@ -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 ""), diff --git a/app/models/experience.rb b/app/models/experience.rb index 9bdc5ff..06c01ec 100644 --- a/app/models/experience.rb +++ b/app/models/experience.rb @@ -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 diff --git a/app/views/plugin/personal_experience/_profile.html.erb b/app/views/plugin/personal_experience/_profile.html.erb index dbf7067..2d063fd 100644 --- a/app/views/plugin/personal_experience/_profile.html.erb +++ b/app/views/plugin/personal_experience/_profile.html.erb @@ -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 %>