在线课堂首页的优化、学生列表的优化

dev_forum
cxt 5 years ago
parent 394f4eb2fe
commit 4000eafe94

@ -53,7 +53,6 @@ class CoursesController < ApplicationController
# c.tea_id=u.id and u.id=ue.user_id and ue.school_id=s.id") # c.tea_id=u.id and u.id=ue.user_id and ue.school_id=s.id")
@courses = Course.where(is_delete: 0, is_hidden: 0) @courses = Course.where(is_delete: 0, is_hidden: 0)
.includes(:course_modules, :course_members, teacher: [user_extension: :school])
.order("courses.id = 1309 desc, courses.created_at desc") .order("courses.id = 1309 desc, courses.created_at desc")
# @courses = Course.where(is_delete: 0, is_hidden: 0).select("courses.id, courses.tea_id, courses.name, courses.exercises_count, courses.polls_count, # @courses = Course.where(is_delete: 0, is_hidden: 0).select("courses.id, courses.tea_id, courses.name, courses.exercises_count, courses.polls_count,
@ -66,13 +65,11 @@ class CoursesController < ApplicationController
.order("courses.id = 1309 DESC, courses.#{order_str} DESC") .order("courses.id = 1309 DESC, courses.#{order_str} DESC")
elsif @order == "created_at" elsif @order == "created_at"
# REDO:Extension # REDO:Extension
@courses = Course.joins(teacher: :user_extension) @courses = Course.where(is_delete: 0, is_hidden: 0, is_end: 0)
.where(is_delete: 0, is_hidden: 0, is_end: 0)
.order("courses.id = 1309 DESC, courses.#{order_str} DESC") .order("courses.id = 1309 DESC, courses.#{order_str} DESC")
else else
# REDO:Extension # REDO:Extension
@courses = Course.joins(teacher: :user_extension) @courses = Course.where(is_delete: 0, is_hidden: 0)
.where(is_delete: 0, is_hidden: 0)
.order("courses.id = 1309 DESC, courses.#{order_str} DESC") .order("courses.id = 1309 DESC, courses.#{order_str} DESC")
end end
@ -89,7 +86,7 @@ class CoursesController < ApplicationController
(course_members.role in(1,2,3) and CONCAT(users.lastname, users.firstname) like :keyword) or courses.name like :keyword (course_members.role in(1,2,3) and CONCAT(users.lastname, users.firstname) like :keyword) or courses.name like :keyword
or schools.name like :keyword or schools.name like :keyword
} }
@courses = @courses.joins(course_members: [user: [user_extension: :school]]) @courses = @courses.joins(:school, course_members: [user: :user_extension])
.where("#{sql}", keyword: "%#{params[:search]}%").distinct .where("#{sql}", keyword: "%#{params[:search]}%").distinct
end end
@courses_count = @courses.size @courses_count = @courses.size
@ -98,7 +95,8 @@ class CoursesController < ApplicationController
page = params[:page] || 1 page = params[:page] || 1
limit = params[:limit] || 16 limit = params[:limit] || 16
@courses= @courses.page(page).per(limit) @courses = @courses.page(page).per(limit)
@courses = @courses.preload(:school, :course_members, teacher: :user_extension)
end end
def visits_plus_one def visits_plus_one
@ -655,7 +653,8 @@ class CoursesController < ApplicationController
page = params[:page] || 1 page = params[:page] || 1
limit = params[:limit] || 20 limit = params[:limit] || 20
@students= Kaminari.paginate_array(@students).page(page).per(limit) @students= @students.page(page).per(limit)
@students = @students.includes(:course_group, user: :user_extension)
end end
# 获取当前课程所有分班 # 获取当前课程所有分班

@ -318,7 +318,12 @@ class User < ApplicationRecord
elsif business? elsif business?
Course::BUSINESS Course::BUSINESS
else else
role = course.course_members.find_by(user_id: id, is_active: 1)&.role role =
if course.course_members.loaded?
course.course_members.find{|member| member.user_id == id && member.is_active == 1}&.role
else
course.course_members.find_by(user_id: id, is_active: 1)&.role
end
case role case role
when nil then Course::NORMAL when nil then Course::NORMAL
when 'CREATOR' then Course::CREATOR when 'CREATOR' then Course::CREATOR

@ -1,18 +1,15 @@
json.courses do json.courses @courses do |course|
json.array! @courses do |course|
json.id course.id json.id course.id
json.name course.name json.name course.name
json.avatar_url url_to_avatar(course.teacher) json.avatar_url url_to_avatar(course.teacher)
json.creator course.teacher.real_name json.creator course.teacher.real_name
json.school course.teacher.school_name json.school course.school&.name
json.technical_title course.teacher.user_extension.technical_title json.technical_title course.teacher.identity
json.course_members_count course.course_members_count json.course_members_count course.course_members_count
json.tasks_count get_tasks_count course json.tasks_count get_tasks_count course
json.visits course.visits json.visits course.visits
json.is_public course.is_public json.is_public course.is_public
json.is_accessible course.is_public == 1 || @user.course_identity(course) < Course::NORMAL json.is_accessible course.is_public == 1 || @user.course_identity(course) < Course::NORMAL
json.is_end course.is_end json.is_end course.is_end
json.first_category_url module_url(course.course_modules.not_hidden.first, course)
end
end end
json.courses_count @courses_count json.courses_count @courses_count

Loading…
Cancel
Save