diff --git a/app/controllers/admin/courses_controller.rb b/app/controllers/admin/courses_controller.rb index 750ea67..5b5f645 100644 --- a/app/controllers/admin/courses_controller.rb +++ b/app/controllers/admin/courses_controller.rb @@ -1,21 +1,21 @@ class Admin::CoursesController < OrbitMemberController - include Admin::CoursesHelper + include Admin::CoursesHelper layout "member_plugin" - before_action :set_course, only: [:show, :edit , :update, :destroy] - before_action :set_course_assignment, only: [ :edit_assignment , :update_assignment, :destroy_assignment] - before_action :set_plugin - before_action :get_settings,:only => [:new, :edit, :setting] + before_action :set_course, only: [:show, :edit , :update, :destroy] + before_action :set_course_assignment, only: [ :edit_assignment , :update_assignment, :destroy_assignment] + before_action :set_plugin + before_action :get_settings,:only => [:new, :edit, :setting] - before_action :need_access_right - before_action :allow_admin_only, :only => [:index, :setting] + before_action :need_access_right + before_action :allow_admin_only, :only => [:index, :setting] def index - @courses = Course.order_by(:created_at=>'desc').page(params[:page]).per(10) + @courses = Course.sort_year.page(params[:page]).per(10) end def new @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil - @course = Course.new + @course = Course.new end def create diff --git a/app/controllers/personal_courses_controller.rb b/app/controllers/personal_courses_controller.rb index bf7f6ae..8ed9b10 100644 --- a/app/controllers/personal_courses_controller.rb +++ b/app/controllers/personal_courses_controller.rb @@ -1,6 +1,6 @@ class PersonalCoursesController < ApplicationController def index - courses = Course.where(:is_hidden=>false).order_by(:year=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) + courses = Course.sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) courses_list = courses.collect do |course| member = course.member_profile path = OrbitHelper.url_to_plugin_show(member.to_param, 'member') rescue '#' diff --git a/app/models/course.rb b/app/models/course.rb index 7399de7..70b8b9c 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -33,7 +33,9 @@ class Course accepts_nested_attributes_for :course_supplement_files, :allow_destroy => true accepts_nested_attributes_for :course_evaluation_files, :allow_destroy => true - 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| selected_course = SelectedCourse rescue nil if selected_course @@ -89,7 +91,7 @@ class Course 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| @@ -107,7 +109,7 @@ class Course { "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_course/_profile.html.erb b/app/views/plugin/personal_course/_profile.html.erb index 7bcc54f..db0f08e 100644 --- a/app/views/plugin/personal_course/_profile.html.erb +++ b/app/views/plugin/personal_course/_profile.html.erb @@ -7,9 +7,9 @@ <% if has_access? - @courses = Course.where(member_profile_id: @member.id).desc(:year).page(params[:page]).per(10) + @courses = Course.where(member_profile_id: @member.id).sort_year.page(params[:page]).per(10) else - @courses = Course.where(is_hidden: false, member_profile_id: @member.id).desc(:year).page(params[:page]).per(10) + @courses = Course.where(is_hidden: false, member_profile_id: @member.id).sort_year.page(params[:page]).per(10) end %>