选用实训课程的弹框改版

dev_course
cxt 5 years ago
parent 48cfc3f39d
commit 0dbb4c6c54

@ -829,7 +829,13 @@ class HomeworkCommonsController < ApplicationController
if params[:order_by] == 'mine' if params[:order_by] == 'mine'
current_user.my_shixuns.unhidden current_user.my_shixuns.unhidden
else 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 end
## 方向 ## 方向
@ -903,34 +909,10 @@ class HomeworkCommonsController < ApplicationController
# 选用实训课程 # 选用实训课程
def subjects 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") @tags = Repertoire.where(nil).order("updated_at desc")
select = params[:select] # 路径导航类型 select = params[:select] # 路径导航类型
reorder = params[:order] || "myshixun_count" reorder = params[:order] || "myshixun_count"
sort = params[:sort] || "desc"
search = params[:search] search = params[:search]
## 分页参数 ## 分页参数
@ -941,17 +923,17 @@ class HomeworkCommonsController < ApplicationController
# 最热排序 # 最热排序
if reorder == "myshixun_count" if reorder == "myshixun_count"
if select 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 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 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}%' 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 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 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 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}%' `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 end
else else
# 我的路径 # 我的路径
@ -973,17 +955,18 @@ class HomeworkCommonsController < ApplicationController
end 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) @subjects = @subjects.reorder(order_str)
end end
@total_count = @subjects.size @total_count = @subjects.size
if reorder != "myshixun_count" 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 else
@subjects = @subjects[offset, limit] @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
end end

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

@ -6,8 +6,12 @@ end
json.subject_list @subjects do |subject| json.subject_list @subjects do |subject|
json.subject_id subject.id json.subject_id subject.id
json.subject_name subject.name json.subject_name subject.name
json.challenge_tags subject.shixun_tags
json.shixun_count subject.shixuns.unhidden.size json.shixun_count subject.shixuns.unhidden.size
json.myshixun_count subject.shixuns.pluck(:myshixuns_count).sum 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 end
json.subjects_count @subjects_count json.subjects_count @total_count
Loading…
Cancel
Save