@ -19,14 +19,14 @@ class ShixunsController < ApplicationController
before_action :allowed , only : [ :update , :close , :update_propaedeutics , :settings , :publish ,
:shixun_members_added , :change_manager , :collaborators_delete ,
:cancel_ publish, :add_collaborators , :add_file ]
:cancel_ apply_public, :cancel_ publish, :add_collaborators , :add_file ]
before_action :portion_allowed , only : [ :copy ]
before_action :special_allowed , only : [ :send_to_course , :search_user_courses ]
## 获取课程列表
def index
@shixuns = current_laboratory . shixuns . unhidden
@shixuns = current_laboratory . shixuns . unhidden . publiced
## 方向
if params [ :tag_level ] . present? && params [ :tag_id ] . present?
@ -818,37 +818,41 @@ class ShixunsController < ApplicationController
@status = 0
@position = [ ]
begin
if @shixun . challenges . count == 0
@status = 4
else
@shixun . challenges . each do | challenge |
if challenge . challenge_tags . count == 0
@status = 3
@position << challenge . position
unless @shixun . is_jupyter?
if @shixun . challenges . count == 0
@status = 4
else
@shixun . challenges . each do | challenge |
if challenge . challenge_tags . count == 0
@status = 3
@position << challenge . position
end
end
end
unfinish_challenge = @shixun . challenges . where ( :st = > 0 , :path = > nil )
if unfinish_challenge . count > 0 && ! @shixun . is_choice_type?
@status = 2
@pos = [ ]
unfinish_challenge . each do | challenge |
@pos << challenge . position
unfinish_challenge = @shixun . challenges . where ( :st = > 0 , :path = > nil )
if unfinish_challenge . count > 0 && ! @shixun . is_choice_type?
@status = 2
@pos = [ ]
unfinish_challenge . each do | challenge |
@pos << challenge . position
end
end
end
end
if @status == 0
@shixun . update_attributes! ( :status = > 1 )
apply = ApplyAction . where ( :container_type = > " ApplyShixun " , :container_id = > @shixun . id ) . order ( " created_at desc " ) . first
if apply && apply . status == 0
@status = 0
else
ApplyAction . create ( :container_type = > " ApplyShixun " , :container_id = > @shixun . id , :user_id = > current_user . id , :status = > 0 )
#begin
# status = Trustie::Sms.send(mobile: '18711011226', send_type:'publish_shixun' , name: '管理员')
#rescue => e
# Rails.logger.error "发送验证码出错: #{e}"
#end
@status = 1
ActiveRecord :: Base . transaction do
@shixun . update_attributes! ( :status = > 2 )
apply = ApplyAction . where ( :container_type = > " ApplyShixun " , :container_id = > @shixun . id ) . order ( " created_at desc " ) . first
if apply && apply . status == 0
@status = 0
else
ApplyAction . create ( :container_type = > " ApplyShixun " , :container_id = > @shixun . id , :user_id = > current_user . id , :status = > 0 )
#begin
# status = Trustie::Sms.send(mobile: '18711011226', send_type:'publish_shixun' , name: '管理员')
#rescue => e
# Rails.logger.error "发送验证码出错: #{e}"
#end
@status = 1
end
end
end
rescue Exception = > e
@ -993,14 +997,24 @@ class ShixunsController < ApplicationController
:disposition = > 'attachment' #inline can open in browser
end
# 撤销申请公开
def cancel_apply_public
tip_exception ( " 实训已经公开,无法撤销 " ) if @shixun . public == 2
ActiveRecord :: Base . transaction do
apply = ApplyAction . where ( :container_type = > " ApplyShixun " , :container_id = > @shixun . id ) . order ( " created_at desc " ) . first
if apply && apply . status == 0
apply . update_attributes! ( status : 3 )
apply . tidings & . destroy_all
end
@shixun . update_column ( :public , 0 )
end
normal_status ( 0 , " 成功撤销申请 " )
end
# 撤销发布
def cancel_publish
tip_exception ( " 实训已经发布,无法撤销 " ) if @shixun . status == 2
apply = ApplyAction . where ( :container_type = > " ApplyShixun " , :container_id = > @shixun . id ) . order ( " created_at desc " ) . first
if apply && apply . status == 0
apply . update_attribute ( :status , 3 )
apply . tidings . destroy_all
end
tip_exception ( " 请先撤销申请公开,再撤销发布 " ) if @shixun . public == 1
tip_exception ( " 实训已经公开,无法撤销 " ) if @shixun . public == 2
@shixun . update_column ( :status , 0 )
end