选用实训的调整

dev_forum
cxt 5 years ago
parent 6d6098452f
commit a2779baf36

@ -822,66 +822,98 @@ class HomeworkCommonsController < ApplicationController
@main_catrgory = @course.course_modules.where(module_type: "shixun_homework") @main_catrgory = @course.course_modules.where(module_type: "shixun_homework")
@homework_category = @main_catrgory.take.course_second_categories @homework_category = @main_catrgory.take.course_second_categories
## 我的实训 search = params[:search]
@shixuns = type = params[:type]
if params[:order_by] == 'mine' # 超级管理员用户显示所有未隐藏的实训、非管理员显示所有已发布的实训(对本单位公开且未隐藏未关闭)
current_user.my_shixuns.unhidden
else
if current_user.admin? if current_user.admin?
Shixun.unhidden @shixuns = Shixun.unhidden
else else
none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id) none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id)
@shixuns = Shixun.where.not(id: none_shixun_ids).unhidden @shixuns = Shixun.where.not(id: none_shixun_ids).unhidden
end end
end
## 方向 # 实训的所有标签
if params[:tag_level].present? && params[:tag_id].present? @tags = TagRepertoire.select([:id, :name]).joins(:shixuns).where(shixuns: {id: @shixuns}).distinct
@shixuns = @shixuns.filter_tag(params[:tag_level].to_i, params[:tag_id].to_i)
case params[:tag_level].to_i
when 1 #大类
@search_tags = Repertoire.find(params[:tag_id].to_i).name
when 2 #子类
@search_tags = SubRepertoire.find(params[:tag_id].to_i).name
when 3 #tag
tag = TagRepertoire.find(params[:tag_id].to_i)
@search_tags = "#{tag.sub_repertoire.name} / #{tag.name}"
end
end
## 搜索关键字创建者、实训名称、院校名称 if params[:search] && params[:search].strip != ""
if params[:keyword].present? @shixuns = @shixuns.joins(:user).where("shixuns.name like ? or concat(users.lastname, users.firstname) like ?",
keyword = params[:keyword].strip "%#{search}%", "%#{search}%").distinct
@shixuns = @shixuns.joins(user: [user_extenison: :school]).
where("schools.name like '%#{keyword}%'
or concat(lastname, firstname) like '%#{keyword}%'
or shixuns.name like '%#{keyword.split(" ").join("%")}%'").distinct
end end
## 筛选 难度 unless type.blank? || type == "all"
if params[:diff].present? && params[:diff].to_i != 0 @shixuns = @shixuns.joins(:shixun_tag_repertoires).where(shixun_tag_repertoires: {tag_repertoire_id: type}).distinct
@shixuns = @shixuns.where(trainee: params[:diff])
end end
## 排序参数 @shixuns = @shixuns.select([:id, :name, :status, :myshixuns_count, :identifier, :user_id, :trainee]).reorder("shixuns.created_at desc")
bsort = params[:sort] || 'desc' @shixuns_count = @shixuns.size
case params[:order_by] || 'hot'
when 'hot'
@shixuns = @shixuns.order("myshixuns_count #{bsort}")
when 'mine'
@shixuns = @shixuns.order("shixuns.created_at #{bsort}")
else
@shixuns = @shixuns.order("myshixuns_count #{bsort}")
end
@total_count = @shixuns.count
## 分页参数 ## 分页参数
page = params[:page] || 1 page = params[:page] || 1
limit = params[:limit] || 15 @shixuns = @shixuns.includes(:challenges, user: [user_extension: :school]).page(page).per(10)
@shixuns = @shixuns.includes(:challenges, user: [user_extension: :school]).page(page).per(limit) # 新版用下面的代码
# ## 我的实训
# @shixuns =
# if params[:order_by] == 'mine'
# current_user.my_shixuns.unhidden
# else
# 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
#
# ## 方向
# if params[:tag_level].present? && params[:tag_id].present?
# @shixuns = @shixuns.filter_tag(params[:tag_level].to_i, params[:tag_id].to_i)
# case params[:tag_level].to_i
# when 1 #大类
# @search_tags = Repertoire.find(params[:tag_id].to_i).name
# when 2 #子类
# @search_tags = SubRepertoire.find(params[:tag_id].to_i).name
# when 3 #tag
# tag = TagRepertoire.find(params[:tag_id].to_i)
# @search_tags = "#{tag.sub_repertoire.name} / #{tag.name}"
# end
# end
#
# ## 搜索关键字创建者、实训名称、院校名称
# if params[:keyword].present?
# keyword = params[:keyword].strip
# @shixuns = @shixuns.joins(user: [user_extenison: :school]).
# where("schools.name like '%#{keyword}%'
# or concat(lastname, firstname) like '%#{keyword}%'
# or shixuns.name like '%#{keyword.split(" ").join("%")}%'").distinct
# end
#
# ## 筛选 难度
# if params[:diff].present? && params[:diff].to_i != 0
# @shixuns = @shixuns.where(trainee: params[:diff])
# end
#
# ## 排序参数
# bsort = params[:sort] || 'desc'
# case params[:order_by] || 'hot'
# when 'hot'
# @shixuns = @shixuns.order("myshixuns_count #{bsort}")
# when 'mine'
# @shixuns = @shixuns.order("shixuns.created_at #{bsort}")
# else
# @shixuns = @shixuns.order("myshixuns_count #{bsort}")
# end
#
# @total_count = @shixuns.count
#
# ## 分页参数
# page = params[:page] || 1
# limit = params[:limit] || 15
#
# @shixuns = @shixuns.includes(:challenges, user: [user_extension: :school]).page(page).per(limit)
#
end end
def create_shixun_homework def create_shixun_homework

@ -1,12 +1,27 @@
# json.shixun_list @shixuns do |shixun|
# json.shixun_identifier shixun.identifier
# json.name shixun.name
# json.creator shixun.user&.full_name
# json.creator_login shixun.user&.login
# json.school shixun.user&.school_name
# json.myshixuns_count shixun.myshixuns_count
# json.level level_to_s(shixun.trainee)
# json.challenge_tags shixun.challenge_tags_name
# end
json.shixun_list @shixuns do |shixun| json.shixun_list @shixuns do |shixun|
json.shixun_identifier shixun.identifier json.shixun_id shixun.id
json.name shixun.name json.identifier shixun.identifier
json.creator shixun.user&.full_name json.shixun_name shixun.name
json.creator_login shixun.user&.login
json.school shixun.user&.school_name
json.myshixuns_count shixun.myshixuns_count json.myshixuns_count shixun.myshixuns_count
json.school shixun.user&.school_name
json.creator shixun.user&.full_name
json.level level_to_s(shixun.trainee) json.level level_to_s(shixun.trainee)
json.challenge_tags shixun.challenge_tags_name end
json.tags @tags do |tag|
json.tag_id tag.id
json.tag_name tag.name
end end
json.shixuns_count @total_count json.shixuns_count @total_count

Loading…
Cancel
Save