|
|
|
@ -26,14 +26,7 @@ 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?
|
|
|
|
@ -72,16 +65,12 @@ class ShixunsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
## 排序参数
|
|
|
|
|
bsort = params[:sort] || 'desc'
|
|
|
|
|
case params[:order_by] || 'publish_time'
|
|
|
|
|
when 'new'
|
|
|
|
|
@shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.created_at #{bsort}")
|
|
|
|
|
bsort = (params[:sort] == "desc" ? "desc" : "asc")
|
|
|
|
|
case params[:order_by] || 'new'
|
|
|
|
|
when 'hot'
|
|
|
|
|
@shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.myshixuns_count #{bsort}")
|
|
|
|
|
when 'mine'
|
|
|
|
|
@shixuns = @shixuns.order("shixuns.created_at #{bsort}")
|
|
|
|
|
@shixuns = @shixuns.order("shixuns.public = 2 desc, shixuns.myshixuns_count #{bsort}")
|
|
|
|
|
else
|
|
|
|
|
@shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.publish_time #{bsort}")
|
|
|
|
|
@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
|
|
|
|
|