Update sort.

This commit is contained in:
BoHung Chiu 2022-07-26 19:13:13 +08:00
parent 2a6f623f3c
commit b52281f30c
3 changed files with 9 additions and 6 deletions

View File

@ -1,7 +1,7 @@
class PersonalCertificatesController < ApplicationController class PersonalCertificatesController < ApplicationController
def index def index
params = OrbitHelper.params 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 [] 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?

View File

@ -2,14 +2,17 @@ class Certificate
include Mongoid::Document include Mongoid::Document
include Mongoid::Timestamps include Mongoid::Timestamps
include OrbitModel::Status include OrbitModel::Status
include MemberHelper include MemberHelper
include Slug include Slug
field :issued_by field :issued_by
field :title, as: :slug_title, type: String, localize: true field :title, as: :slug_title, type: String, localize: true
belongs_to :member_profile 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) def self.get_plugin_datas_to_member(datas)
page = Page.where(:module => "personal_certificate").first rescue nil page = Page.where(:module => "personal_certificate").first rescue nil

View File

@ -7,9 +7,9 @@
<% <%
if has_access? 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 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 end
%> %>