选用实训课程的弹框改版

dev_course
cxt 5 years ago
parent 48cfc3f39d
commit 0dbb4c6c54

@ -829,7 +829,13 @@ class HomeworkCommonsController < ApplicationController
if params[:order_by] == 'mine'
current_user.my_shixuns.unhidden
else
Shixun.unhidden
if current_user.admin?
Shixun.unhidden
else
none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id)
@shixuns = Shixun.where.not(id: none_shixun_ids).unhidden
end
end
## 方向
@ -903,34 +909,10 @@ class HomeworkCommonsController < ApplicationController
# 选用实训课程
def subjects
search = params[:search]
type = params[:type]
# 显示所有未隐藏的、已发布的实训课程
@subjects = Subject.select([:id, :name, :status, :repertoire_id]).visible.unhidden
@tags = Repertoire.select([:id, :name]).where(id: @subjects.pluck(:repertoire_id).uniq).order("updated_at desc")
if params[:search] && params[:search].strip != ""
@subjects = @subjects.joins(:user).where("subjects.name like ? or concat(users.lastname, users.firstname) like ?",
"%#{search}%", "%#{search}%")
end
unless type.blank? || type == "all"
@subjects = @subjects.where(repertoire_id: type)
end
@subjects = @subjects.reorder("subjects.created_at desc")
@subjects_count = @subjects.size
## 分页参数
page = params[:page] || 1
@subjects = @subjects.page(page).per(10)
@subjects = @subjects.includes(:shixuns)
@tags = Repertoire.where(nil).order("updated_at desc")
select = params[:select] # 路径导航类型
reorder = params[:order] || "myshixun_count"
sort = params[:sort] || "desc"
search = params[:search]
## 分页参数
@ -941,17 +923,17 @@ class HomeworkCommonsController < ApplicationController
# 最热排序
if reorder == "myshixun_count"
if select
@subjects = Subject.find_by_sql("SELECT subjects.id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status,
@subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status,
subjects.shixuns_count, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns
on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where
subjects`.`hidden` = 0 AND `subjects`.`status` = 2 AND `subjects`.`name` like '%#{search}%'
AND `subjects`.`repertoire_id` = #{select} GROUP BY subjects.id ORDER BY myshixun_member_count DESC")
AND `subjects`.`repertoire_id` = #{select} GROUP BY subjects.id ORDER BY myshixun_member_count #{sort}")
else
@subjects = Subject.find_by_sql("SELECT subjects.id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status,
@subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status,
subjects.shixuns_count, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns
on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where
`subjects`.`hidden` = 0 AND `subjects`.`status` = 2 AND `subjects`.`name` like '%#{search}%'
GROUP BY subjects.id ORDER BY myshixun_member_count DESC")
GROUP BY subjects.id ORDER BY myshixun_member_count #{sort}")
end
else
# 我的路径
@ -973,17 +955,18 @@ class HomeworkCommonsController < ApplicationController
end
# 排序
order_str = reorder == "publish_time" ? "status = 2 desc, publish_time asc" : "updated_at desc"
order_str = "updated_at #{sort}"
@subjects = @subjects.reorder(order_str)
end
@total_count = @subjects.size
if reorder != "myshixun_count"
@subjects = @subjects.page(page).per(limit).includes(:shixuns)
@subjects = @subjects.page(page).per(limit).includes(:shixuns, user: [user_extension: :school])
else
@subjects = @subjects[offset, limit]
subject_ids = @subjects.pluck(:id)
@subjects = Subject.where(id: subject_ids).order("field(id,#{subject_ids.join(',')})").includes(:shixuns, user: [user_extension: :school])
end
end

@ -88,4 +88,9 @@ class Subject < ApplicationRecord
def published?
status == 2
end
def shixun_tags
challenges = Challenge.where(shixun_id: shixuns.unhidden)
@tags = ChallengeTag.where(challenge_id: challenges).pluck(:name).uniq
end
end

@ -6,8 +6,12 @@ end
json.subject_list @subjects do |subject|
json.subject_id subject.id
json.subject_name subject.name
json.challenge_tags subject.shixun_tags
json.shixun_count subject.shixuns.unhidden.size
json.myshixun_count subject.shixuns.pluck(:myshixuns_count).sum
json.creator subject.user&.full_name
json.creator_login subject.user&.login
json.school subject.user&.school_name
end
json.subjects_count @subjects_count
json.subjects_count @total_count
Loading…
Cancel
Save