Update sort.

This commit is contained in:
BoHung Chiu 2022-07-26 19:14:15 +08:00
parent 9da8f60a6a
commit 658addea48
5 changed files with 9 additions and 8 deletions

View File

@ -10,7 +10,7 @@ class Admin::ActivitiesController < OrbitMemberController
before_action :allow_admin_only, :only => [:index, :setting]
def index
@activities = Activity.order_by(:year => 'desc').page(params[:page]).per(10)
@activities = Activity.sort_year_date.page(params[:page]).per(10)
#respond_to do |format|
#format.html
#format.xml { render :xml => @activities }

View File

@ -1,7 +1,6 @@
class PersonalActivitiesController < ApplicationController
def index
activities = Activity.where(:is_hidden => false)
.order_by(:year=>'desc')
activities = Activity.sort_for_frontend
.page(OrbitHelper.params[:page_no])
.per(OrbitHelper.page_data_count)

View File

@ -28,7 +28,9 @@ class Activity
accepts_nested_attributes_for :activity_files, :allow_destroy => true
before_validation :add_http
scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year => "desc", :publish_date => "desc") }
index({year: -1, :activity_start_date => -1, _id: -1}, { unique: false, background: false })
scope :sort_year_date, ->{ order_by(:year => "desc", :activity_start_date => "desc", :id=>"desc") }
scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year => "desc", :activity_start_date => "desc", :id=>"desc") }
def get_plugin_data(fields_to_show)
plugin_datas = []

View File

@ -8,9 +8,9 @@
<%
#@activities = Activity.where(member_profile_id: current_user.member_profile.id).desc(:year).page(params[:page]).per(10)
if has_access?
@activities = Activity.where(member_profile_id: @member.id).desc(:year).page(params[:page]).per(10)
@activities = Activity.where(member_profile_id: @member.id).sort_year_date.page(params[:page]).per(10)
else
@activities = Activity.where(is_hidden: false, member_profile_id: @member.id).desc(:year).page(params[:page]).per(10)
@activities = Activity.where(is_hidden: false, member_profile_id: @member.id).sort_year_date.page(params[:page]).per(10)
end
%>

View File

@ -43,8 +43,8 @@ $( ".selectbox" ).ready(function() {
<td><a href="{{link_to_show}}">{{activity_name}}</a></td>
<td>{{activity_organizer}}</td>
<td>{{activity_area}}</td>
<td>{{activity_start_date}}</td>
<td>{{activity_end_date}}</td>
<td date-format="%Y-%m-%d">{{activity_start_date}}</td>
<td date-format="%Y-%m-%d">{{activity_end_date}}</td>
<td>{{note}}</td>
</tr>
</tbody>