|
|
|
@ -26,26 +26,19 @@ class ShixunsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
## 获取课程列表
|
|
|
|
|
def index
|
|
|
|
|
## 我的实训
|
|
|
|
|
@shixuns =
|
|
|
|
|
if params[:order_by] == 'mine'
|
|
|
|
|
tip_exception(401, "..") unless current_user.logged?
|
|
|
|
|
current_user.my_shixuns
|
|
|
|
|
else
|
|
|
|
|
Shixun.unhidden
|
|
|
|
|
end
|
|
|
|
|
@shixuns = current_laboratory.shixuns.unhidden.publiced
|
|
|
|
|
|
|
|
|
|
## 方向
|
|
|
|
|
if params[:tag_level].present? && params[:tag_id].present?
|
|
|
|
|
@shixuns = @shixuns.filter_tag(params[:tag_level].to_i, params[:tag_id].to_i)
|
|
|
|
|
@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}"
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
@ -61,27 +54,23 @@ class ShixunsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
## 筛选 状态
|
|
|
|
|
if params[:status].present? && params[:status].to_i != 0
|
|
|
|
|
if params[:status].present? && params[:status].to_i != 0
|
|
|
|
|
params[:status] = [0, 1] if params[:status].to_i == 1
|
|
|
|
|
@shixuns = @shixuns.where(status: params[:status])
|
|
|
|
|
end
|
|
|
|
|
@shixuns = @shixuns.where(status: params[:status])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
## 筛选 难度
|
|
|
|
|
if params[:diff].present? && params[:diff].to_i != 0
|
|
|
|
|
@shixuns = @shixuns.where(trainee: params[:diff])
|
|
|
|
|
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] || 'publish_time'
|
|
|
|
|
when 'new'
|
|
|
|
|
@shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.created_at #{bsort}")
|
|
|
|
|
when 'hot'
|
|
|
|
|
@shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.myshixuns_count #{bsort}")
|
|
|
|
|
when 'mine'
|
|
|
|
|
@shixuns = @shixuns.order("shixuns.created_at #{bsort}")
|
|
|
|
|
else
|
|
|
|
|
@shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.publish_time #{bsort}")
|
|
|
|
|
bsort = (params[:sort] == "desc" ? "desc" : "asc")
|
|
|
|
|
case params[:order_by] || 'new'
|
|
|
|
|
when 'hot'
|
|
|
|
|
@shixuns = @shixuns.order("shixuns.public = 2 desc, shixuns.myshixuns_count #{bsort}")
|
|
|
|
|
else
|
|
|
|
|
@shixuns = @shixuns.order("shixuns.public = 2 desc, shixuns.publish_time #{bsort}")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 用id计数会快10+MS左右,对于搜索的内容随着数据的增加,性能会提升一些。
|
|
|
|
@ -92,12 +81,6 @@ class ShixunsController < ApplicationController
|
|
|
|
|
limit = params[:limit] || 16
|
|
|
|
|
|
|
|
|
|
@shixuns = @shixuns.includes(:tag_repertoires, :challenges).page(page).per(limit)
|
|
|
|
|
|
|
|
|
|
@tag_name_map = TagRepertoire.joins(:shixun_tag_repertoires)
|
|
|
|
|
.where(shixun_tag_repertoires: { shixun_id: @shixuns.map(&:id) })
|
|
|
|
|
.group('shixun_tag_repertoires.shixun_id')
|
|
|
|
|
.select('shixun_id, tag_repertoires.name')
|
|
|
|
|
.each_with_object({}) { |r, obj| obj[r.shixun_id] = r.name }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def shixun_list
|
|
|
|
|