Update sort.

This commit is contained in:
BoHung Chiu 2022-07-26 18:59:27 +08:00
parent b0f0f74430
commit a4235298c1
4 changed files with 9 additions and 7 deletions

View File

@ -10,7 +10,7 @@ class Admin::SelectedCoursesController < OrbitMemberController
before_action :allow_admin_only, :only => [:index, :setting]
def index
@selected_courses = SelectedCourse.order_by(:created_at=>'desc').page(params[:page]).per(10)
@selected_courses = SelectedCourse.sort_year.page(params[:page]).per(10)
end
def show_assignments
@course_assignments = CourseAssignment.where(:course_id=>params[:id]).enabled_for_student.page(params[:page]).per(10)

View File

@ -1,6 +1,6 @@
class PersonalSelectedCoursesController < ApplicationController
def index
selected_courses = SelectedCourse.where(:is_hidden=>false).order_by(:year=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
selected_courses = SelectedCourse.sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
selected_courses_list = selected_courses.collect do |selected_course|
member = selected_course.member_profile
path = OrbitHelper.url_to_plugin_show(member.to_param, 'member') rescue '#'

View File

@ -30,7 +30,9 @@ class SelectedCourse
accepts_nested_attributes_for :selected_course_evaluation_files, :allow_destroy => true
belongs_to :member_profile
scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year=>'desc') }
index({year: -1, _id: -1}, { unique: false, background: false })
scope :sort_year, ->{ order_by(:year=>'desc', :id => 'desc') }
scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year=>'desc', :id => 'desc') }
before_save do |record|
course = record.course
if record.new_record?
@ -125,7 +127,7 @@ class SelectedCourse
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 = []
fields_to_show.collect do |t|
@ -147,7 +149,7 @@ class SelectedCourse
{
"pd_datas" => pd_data,
"type-sort" => (p.course_category.sort_position.to_i rescue 1000),
"sort-index" => index
"sort-index" => idx
}
end

View File

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