Update sort.

This commit is contained in:
BoHung Chiu 2022-07-26 19:11:11 +08:00
parent 1136e0ff7c
commit 8fa0413daa
4 changed files with 17 additions and 15 deletions

View File

@ -1,21 +1,21 @@
class Admin::CoursesController < OrbitMemberController class Admin::CoursesController < OrbitMemberController
include Admin::CoursesHelper include Admin::CoursesHelper
layout "member_plugin" layout "member_plugin"
before_action :set_course, only: [:show, :edit , :update, :destroy] before_action :set_course, only: [:show, :edit , :update, :destroy]
before_action :set_course_assignment, only: [ :edit_assignment , :update_assignment, :destroy_assignment] before_action :set_course_assignment, only: [ :edit_assignment , :update_assignment, :destroy_assignment]
before_action :set_plugin before_action :set_plugin
before_action :get_settings,:only => [:new, :edit, :setting] before_action :get_settings,:only => [:new, :edit, :setting]
before_action :need_access_right before_action :need_access_right
before_action :allow_admin_only, :only => [:index, :setting] before_action :allow_admin_only, :only => [:index, :setting]
def index def index
@courses = Course.order_by(:created_at=>'desc').page(params[:page]).per(10) @courses = Course.sort_year.page(params[:page]).per(10)
end end
def new def new
@member = MemberProfile.find_by(:uid=>params['uid']) rescue nil @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil
@course = Course.new @course = Course.new
end end
def create def create

View File

@ -1,6 +1,6 @@
class PersonalCoursesController < ApplicationController class PersonalCoursesController < ApplicationController
def index 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| courses_list = courses.collect do |course|
member = course.member_profile member = course.member_profile
path = OrbitHelper.url_to_plugin_show(member.to_param, 'member') rescue '#' path = OrbitHelper.url_to_plugin_show(member.to_param, 'member') rescue '#'

View File

@ -33,7 +33,9 @@ class Course
accepts_nested_attributes_for :course_supplement_files, :allow_destroy => true accepts_nested_attributes_for :course_supplement_files, :allow_destroy => true
accepts_nested_attributes_for :course_evaluation_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| before_save do |record|
selected_course = SelectedCourse rescue nil selected_course = SelectedCourse rescue nil
if selected_course if selected_course
@ -89,7 +91,7 @@ class Course
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|
@ -107,7 +109,7 @@ class Course
{ {
"pd_datas" => pd_data, "pd_datas" => pd_data,
"type-sort" => (p.course_category.sort_position.to_i rescue 1000), "type-sort" => (p.course_category.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?
@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 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 end
%> %>