diff --git a/app/controllers/admin/selected_courses_controller.rb b/app/controllers/admin/selected_courses_controller.rb index f94024d..c70f5eb 100644 --- a/app/controllers/admin/selected_courses_controller.rb +++ b/app/controllers/admin/selected_courses_controller.rb @@ -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) diff --git a/app/controllers/personal_selected_courses_controller.rb b/app/controllers/personal_selected_courses_controller.rb index 0fb2cfa..d7641c8 100644 --- a/app/controllers/personal_selected_courses_controller.rb +++ b/app/controllers/personal_selected_courses_controller.rb @@ -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 '#' diff --git a/app/models/selected_course.rb b/app/models/selected_course.rb index 3112780..c433f68 100644 --- a/app/models/selected_course.rb +++ b/app/models/selected_course.rb @@ -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 diff --git a/app/views/plugin/personal_selected_course/_profile.html.erb b/app/views/plugin/personal_selected_course/_profile.html.erb index bdcc4cf..ca5e260 100644 --- a/app/views/plugin/personal_selected_course/_profile.html.erb +++ b/app/views/plugin/personal_selected_course/_profile.html.erb @@ -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 %>