Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun
commit
6687107cf1
@ -0,0 +1,15 @@
|
|||||||
|
class Weapps::ShixunListsController < ApplicationController
|
||||||
|
before_action :require_login
|
||||||
|
|
||||||
|
def index
|
||||||
|
results = Weapps::ShixunSearchService.call(search_params, current_laboratory)
|
||||||
|
@total_count = results.size
|
||||||
|
@results = paginate results
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def search_params
|
||||||
|
params.permit(:keyword, :type, :page, :limit, :order, :status, :diff, :sort, :no_jupyter)
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,53 @@
|
|||||||
|
class Weapps::ShixunSearchService < ApplicationService
|
||||||
|
|
||||||
|
attr_reader :params, :laboratory
|
||||||
|
|
||||||
|
def initialize(params, laboratory)
|
||||||
|
@params = params
|
||||||
|
@laboratory = laboratory
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
# 全部实训/我的实训
|
||||||
|
type = params[:type] || "all"
|
||||||
|
shixuns = laboratory.shixuns.published.no_jupyter
|
||||||
|
|
||||||
|
if type == "mine"
|
||||||
|
shixuns = shixuns.where(id: User.current.shixuns)
|
||||||
|
else
|
||||||
|
# 超级管理员用户显示所有未隐藏的实训、非管理员显示所有已发布的实训(对本单位公开且未隐藏未关闭)
|
||||||
|
if User.current.admin? || User.current.business? || !User.current.school_id
|
||||||
|
shixuns = shixuns.where(hidden: 0)
|
||||||
|
else
|
||||||
|
shixun_ids = ShixunSchool.where(school_id: User.current.school_id).pluck(:shixun_id)
|
||||||
|
shixun_ids = shixun_ids.reject(&:blank?).length == 0 ? -1 : shixun_ids.join(",")
|
||||||
|
|
||||||
|
shixuns = shixuns.where("use_scope = 0 or shixuns.id in (#{shixun_ids})").unhidden.publiced.or(shixuns.where(id: User.current.shixuns))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
## 筛选 难度
|
||||||
|
if params[:diff].present? && params[:diff].to_i != 0
|
||||||
|
shixuns = shixuns.where(trainee: params[:diff])
|
||||||
|
end
|
||||||
|
|
||||||
|
unless params[:keyword].blank?
|
||||||
|
keyword = params[:keyword].strip
|
||||||
|
shixuns = shixuns.joins(:user).
|
||||||
|
where("concat(lastname, firstname) like :keyword or shixuns.name like :keyword",
|
||||||
|
keyword: "%#{keyword}%", name: "%#{keyword.split(" ").join("%")}%").distinct
|
||||||
|
end
|
||||||
|
|
||||||
|
shixuns.order("#{sort_str} #{order_str}")
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def order_str
|
||||||
|
params[:order] || "desc"
|
||||||
|
end
|
||||||
|
|
||||||
|
def sort_str
|
||||||
|
params[:sort] || "myshixuns_count"
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,9 @@
|
|||||||
|
json.shixun_list @results do |obj|
|
||||||
|
json.(obj, :id, :identifier)
|
||||||
|
json.title obj.name
|
||||||
|
json.level level_to_s(obj.trainee)
|
||||||
|
json.study_count obj.myshixuns_count
|
||||||
|
json.author_name obj.user.real_name
|
||||||
|
json.author_img url_to_avatar(obj.user)
|
||||||
|
end
|
||||||
|
json.shixuns_count @total_count
|
@ -0,0 +1,12 @@
|
|||||||
|
class AddVideoToCourseModule < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
Course.all.each do |course|
|
||||||
|
unless course.course_modules.exists?(module_type: "video")
|
||||||
|
atta_position = course.course_modules.find_by(module_type: 'attachment')&.position.to_i
|
||||||
|
video_position = atta_position != 0 ? (atta_position + 1) : 11
|
||||||
|
course.course_modules.where("position >= #{video_position}").update_all("position = position + 1")
|
||||||
|
course.course_modules << CourseModule.new(module_type: "video", hidden: 1, module_name: "视频", position: video_position)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in new issue