From b52281f30c72ae5e369c8c35cd201a44d6fe3e27 Mon Sep 17 00:00:00 2001 From: bohung Date: Tue, 26 Jul 2022 19:13:13 +0800 Subject: [PATCH] Update sort. --- app/controllers/personal_certificates_controller.rb | 2 +- app/models/certificate.rb | 9 ++++++--- app/views/plugin/personal_certificate/_profile.html.erb | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/controllers/personal_certificates_controller.rb b/app/controllers/personal_certificates_controller.rb index b6931f2..3e7cf3c 100644 --- a/app/controllers/personal_certificates_controller.rb +++ b/app/controllers/personal_certificates_controller.rb @@ -1,7 +1,7 @@ class PersonalCertificatesController < ApplicationController def index params = OrbitHelper.params - certificates = Certificate.where(:is_hidden=>false).sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) + certificates = Certificate.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? diff --git a/app/models/certificate.rb b/app/models/certificate.rb index 352a9df..aa5cd58 100644 --- a/app/models/certificate.rb +++ b/app/models/certificate.rb @@ -2,14 +2,17 @@ class Certificate include Mongoid::Document include Mongoid::Timestamps include OrbitModel::Status - include MemberHelper - include Slug + include MemberHelper + include Slug field :issued_by field :title, as: :slug_title, type: String, localize: true belongs_to :member_profile - scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:title =>'asc') } + + index({title: 1, _id: -1}, { unique: false, background: false }) + scope :sort_title, ->{ order_by(:title => "asc", :id=>"desc") } + scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:title =>'asc',:id =>'desc') } def self.get_plugin_datas_to_member(datas) page = Page.where(:module => "personal_certificate").first rescue nil diff --git a/app/views/plugin/personal_certificate/_profile.html.erb b/app/views/plugin/personal_certificate/_profile.html.erb index 5c78354..206df85 100644 --- a/app/views/plugin/personal_certificate/_profile.html.erb +++ b/app/views/plugin/personal_certificate/_profile.html.erb @@ -7,9 +7,9 @@ <% if has_access? - @certificates = Certificate.where(member_profile_id: @member.id).desc(:year).page(params[:page]).per(10) + @certificates = Certificate.where(member_profile_id: @member.id).sort_title.page(params[:page]).per(10) else - @certificates = Certificate.where(is_hidden: false, member_profile_id: @member.id).desc(:year).page(params[:page]).per(10) + @certificates = Certificate.where(is_hidden: false, member_profile_id: @member.id).sort_title.page(params[:page]).per(10) end %>