Update sort.
This commit is contained in:
parent
b0f0f74430
commit
a4235298c1
|
@ -10,7 +10,7 @@ class Admin::SelectedCoursesController < OrbitMemberController
|
||||||
before_action :allow_admin_only, :only => [:index, :setting]
|
before_action :allow_admin_only, :only => [:index, :setting]
|
||||||
|
|
||||||
def index
|
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
|
end
|
||||||
def show_assignments
|
def show_assignments
|
||||||
@course_assignments = CourseAssignment.where(:course_id=>params[:id]).enabled_for_student.page(params[:page]).per(10)
|
@course_assignments = CourseAssignment.where(:course_id=>params[:id]).enabled_for_student.page(params[:page]).per(10)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class PersonalSelectedCoursesController < ApplicationController
|
class PersonalSelectedCoursesController < ApplicationController
|
||||||
def index
|
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|
|
selected_courses_list = selected_courses.collect do |selected_course|
|
||||||
member = selected_course.member_profile
|
member = selected_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 '#'
|
||||||
|
|
|
@ -30,7 +30,9 @@ class SelectedCourse
|
||||||
accepts_nested_attributes_for :selected_course_evaluation_files, :allow_destroy => true
|
accepts_nested_attributes_for :selected_course_evaluation_files, :allow_destroy => true
|
||||||
|
|
||||||
belongs_to :member_profile
|
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|
|
before_save do |record|
|
||||||
course = record.course
|
course = record.course
|
||||||
if record.new_record?
|
if record.new_record?
|
||||||
|
@ -125,7 +127,7 @@ class SelectedCourse
|
||||||
|
|
||||||
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|
|
||||||
|
@ -147,7 +149,7 @@ class SelectedCourse
|
||||||
{
|
{
|
||||||
"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
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
|
|
||||||
<%
|
<%
|
||||||
if has_access?
|
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
|
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
|
end
|
||||||
%>
|
%>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue