Update sort.

This commit is contained in:
BoHung Chiu 2022-07-26 19:07:22 +08:00
parent 8888c3e98c
commit 8a8de1f5b6
4 changed files with 10 additions and 8 deletions

View File

@ -10,7 +10,7 @@ class Admin::HonorsController < OrbitMemberController
before_action :allow_admin_only, :only => [:index, :setting] before_action :allow_admin_only, :only => [:index, :setting]
def index def index
@honors = Honor.order_by(:year=>'desc').page(params[:page]).per(10) @honors = Honor.sort_year_date.page(params[:page]).per(10)
end end
def new def new

View File

@ -5,9 +5,9 @@ class PersonalHonorsController < ApplicationController
honors = nil honors = nil
if filter_value.nil? || filter_value == t("personal_honor.honor_types_all") || filter_value.empty? if filter_value.nil? || filter_value == t("personal_honor.honor_types_all") || filter_value.empty?
honors = Honor.where(:award_name.ne => nil).or(:award_name.ne => "").sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) honors = Honor.where(:award_name.nin => [nil, ""]).sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
else else
honor_type_id = HonorType.or({ 'title.en' => filter_value }, { 'title.zh_tw' => filter_value }).first.id honor_type_id = HonorType.any_of({ 'title.en' => filter_value }, { 'title.zh_tw' => filter_value }).first.id
honors = Honor.where(honor_type_id: honor_type_id).sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) honors = Honor.where(honor_type_id: honor_type_id).sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
end end

View File

@ -24,7 +24,9 @@ class Honor
before_validation :add_http before_validation :add_http
scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year => "desc",:award_date => "desc") } index({year: -1, :award_date => -1, _id: -1}, { unique: false, background: false })
scope :sort_year_date, ->{ order_by(:year => "desc",:award_date => "desc", :id => "desc") }
scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year => "desc",:award_date => "desc", :id => "desc") }
def slug_title def slug_title
self.award_name+' '+self.awarding_unit rescue "" self.award_name+' '+self.awarding_unit rescue ""
@ -71,7 +73,7 @@ class Honor
fields_to_show = fields_to_show - fields_to_remove 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 = [] pd_data = []
fields_to_show.collect do |t| fields_to_show.collect do |t|
if t == "award_name" if t == "award_name"
@ -89,7 +91,7 @@ class Honor
{ {
"pd_datas" => pd_data, "pd_datas" => pd_data,
"type-sort" => (p.honor_type.sort_position.to_i rescue 1000), "type-sort" => (p.honor_type.sort_position.to_i rescue 1000),
"sort-index" => index "sort-index" => idx
} }
end end

View File

@ -7,9 +7,9 @@
<% <%
if has_access? if has_access?
@honors = Honor.where(member_profile_id: @member.id).desc(:year).page(params[:page]).per(10) @honors = Honor.where(member_profile_id: @member.id).sort_year_date.page(params[:page]).per(10)
else else
@honors = Honor.where(is_hidden: false, member_profile_id: @member.id).desc(:year).page(params[:page]).per(10) @honors = Honor.where(is_hidden: false, member_profile_id: @member.id).sort_year_date.page(params[:page]).per(10)
end end
%> %>