diff --git a/app/controllers/admin/diplomas_controller.rb b/app/controllers/admin/diplomas_controller.rb index 53466f5..102061c 100644 --- a/app/controllers/admin/diplomas_controller.rb +++ b/app/controllers/admin/diplomas_controller.rb @@ -10,7 +10,7 @@ class Admin::DiplomasController < OrbitMemberController before_action :allow_admin_only, :only => [:index, :setting] 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 def new diff --git a/app/controllers/personal_diplomas_controller.rb b/app/controllers/personal_diplomas_controller.rb index 7302953..28c6213 100644 --- a/app/controllers/personal_diplomas_controller.rb +++ b/app/controllers/personal_diplomas_controller.rb @@ -1,6 +1,6 @@ class PersonalDiplomasController < ApplicationController 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 [] if fields_to_show.blank? fields_to_show = [ diff --git a/app/models/diploma.rb b/app/models/diploma.rb index f7d132e..ce28891 100644 --- a/app/models/diploma.rb +++ b/app/models/diploma.rb @@ -25,7 +25,9 @@ class Diploma 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 if !self.start_date.nil? or !self.end_date.nil? diff --git a/app/views/plugin/personal_diploma/_profile.html.erb b/app/views/plugin/personal_diploma/_profile.html.erb index 9f92fee..6e18e3a 100644 --- a/app/views/plugin/personal_diploma/_profile.html.erb +++ b/app/views/plugin/personal_diploma/_profile.html.erb @@ -7,9 +7,9 @@ <% 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 - @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 %>