Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_aliyun_beta
caicai8 5 years ago
commit 145af86264

@ -230,6 +230,7 @@ class GraduationTopicsController < ApplicationController
topic_repeat: topic.topic_repeat,
province: topic.province,
city: topic.city,
topic_type: topic.topic_type,
course_list_id: @course.course_list_id)
topic_bank.attachments.destroy_all
else
@ -241,6 +242,7 @@ class GraduationTopicsController < ApplicationController
topic_repeat: topic.topic_repeat,
province: topic.province,
city: topic.city,
topic_type: topic.topic_type,
course_list_id: @course.course_list_id,
user_id: current_user.id,
graduation_topic_id: topic.id)

@ -8,11 +8,11 @@ class ShixunsController < ApplicationController
before_action :find_shixun, except: [:index, :new, :create, :menus, :get_recommend_shixuns,
:propaedeutics, :departments, :apply_shixun_mirror,
:get_mirror_script, :download_file]
:get_mirror_script, :download_file, :shixun_list]
before_action :shixun_access_allowed, except: [:index, :new, :create, :menus, :get_recommend_shixuns,
:propaedeutics, :departments, :apply_shixun_mirror,
:get_mirror_script, :download_file]
:get_mirror_script, :download_file, :shixun_list]
before_action :find_repo_name, only: [:repository, :commits, :file_content, :update_file, :shixun_exec, :copy, :add_file]
before_action :allowed, only: [:update, :close, :update_propaedeutics, :settings, :publish,
@ -98,6 +98,50 @@ class ShixunsController < ApplicationController
.each_with_object({}) { |r, obj| obj[r.shixun_id] = r.name }
end
def shixun_list
# 全部实训/我的实训
type = params[:type] || "all"
# 状态:已发布/未发布
status = params[:status] || "all"
# 超级管理员用户显示所有未隐藏的实训、非管理员显示所有已发布的实训(对本单位公开且未隐藏未关闭)
if type == "mine"
@shixuns = current_user.shixuns.none_closed
else
if current_user.admin?
@shixuns = Shixun.none_closed.where(hidden: 0)
else
none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id)
@shixuns = Shixun.where.not(id: none_shixun_ids).none_closed.where(hidden: 0)
end
end
unless status == "all"
@shixuns = status == "published" ? @shixuns.where(status: 2) : @shixuns.where(status: [0, 1])
end
## 搜索关键字创建者、实训名称、院校名称
unless params[:search].blank?
keyword = params[:search].strip
@shixuns = @shixuns.joins(user: [user_extension: :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
@total_count = @shixuns.count
page = params[:page] || 1
limit = params[:limit] || 15
@shixuns = @shixuns.order("myshixuns_count desc").page(page).per(limit).includes(:shixun_info, :subjects, user: [user_extension: :school])
end
## 获取顶部菜单
def menus
@repertoires = Repertoire.includes(sub_repertoires: [:tag_repertoires]).order("updated_at asc")

@ -59,6 +59,7 @@ class Shixun < ApplicationRecord
scope :visible, -> { where.not(status: -1) }
scope :published, lambda{ where(status: 2) }
scope :published_closed, lambda{ where(status: [2, 3]) }
scope :none_closed, lambda{ where(status: [0, 1, 2]) }
scope :unhidden, lambda{ where(hidden: 0, status: 2) }
scope :field_for_recommend, lambda{ select([:id, :name, :identifier, :myshixuns_count]) }
scope :find_by_ids,lambda{|k| where(id:k)}

@ -0,0 +1,15 @@
json.shixun_list @shixuns do |shixun|
json.shixun_id shixun.id
json.identifier shixun.identifier
json.shixun_name shixun.name
json.description shixun.description
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.subjects shixun.subjects do |subject|
json.(subject, :id, :name)
end
end
json.shixuns_count @total_count

@ -179,6 +179,7 @@ Rails.application.routes.draw do
get :get_mirror_script
post :apply_shixun_mirror
get :download_file
get :shixun_list
end
member do

Loading…
Cancel
Save