实训关卡、测试集、tag复制
This commit is contained in:
parent
ea29e79365
commit
f88bc764bb
|
|
@ -18,6 +18,7 @@ class ShixunsController < ApplicationController
|
|||
def statistics_students
|
||||
|
||||
end
|
||||
|
||||
# push代码的时候会触发gitlab hook
|
||||
def ghook
|
||||
# shixun_modify_status_without_publish(@shixun, 1)
|
||||
|
|
@ -514,9 +515,9 @@ class ShixunsController < ApplicationController
|
|||
s = Trustie::Gitlab::Sync.new
|
||||
gproject = s.create_shixun(@shixun, repository)
|
||||
raise "版本库创建失败" if @shixun.gpid.blank? # 若和gitlab没同步成功,则抛出异常
|
||||
g = Gitlab.client
|
||||
hook_url = Setting.protocol + "://" + Setting.host_name + "/shixuns/#{@shixun.identifier}" + "/ghook"
|
||||
g.add_project_hook(@shixun.gpid, hook_url)
|
||||
# g = Gitlab.client
|
||||
# hook_url = Setting.protocol + "://" + Setting.host_name + "/shixuns/#{@shixun.identifier}" + "/ghook"
|
||||
# g.add_project_hook(@shixun.gpid, hook_url)
|
||||
redirect_to shixun_path @shixun, notice: l(:notice_successful_create)
|
||||
rescue Exception => e
|
||||
respond_to do |format|
|
||||
|
|
@ -528,6 +529,96 @@ class ShixunsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def copy
|
||||
begin
|
||||
new_shixun = Shixun.new
|
||||
new_shixun.attributes = @shixun.attributes.dup.except("id","user_id","visits","gpid","status", "identifier", "homepage_show")
|
||||
new_shixun.user_id = User.current.id
|
||||
new_shixun.identifier = generate_identifier
|
||||
new_shixun.save!
|
||||
|
||||
# 同步复制合作者
|
||||
# 合作者加入到gitlab
|
||||
@shixun.shixun_members.each do ||
|
||||
m = ShixunMember.new(:user_id => new_shixun.user_id, :role => 1)
|
||||
new_shixun.shixun_members << m
|
||||
# REDO: 合作者加入到项目,注意不同的用户复制可能觉得会变?是否需要加入合作者??
|
||||
# 成员存在的时候则不加入
|
||||
end
|
||||
|
||||
# 同步复制版本库,先fork再修改版本库名
|
||||
# forge用户来复制版本库
|
||||
# repository = Repository.new
|
||||
# repository.shixun = new_shixun
|
||||
# repository.type = 'Repository::Gitlab'
|
||||
# repository.identifier = new_shixun.identifier.downcase
|
||||
# repository.project_id = -1
|
||||
# repository.save!
|
||||
# g = Gitlab.client
|
||||
# user_gid = User.find_by_mail("eduforge@163.com").try(:gid)
|
||||
# gshixun = g.fork(@shixun.gpid, user_gid)
|
||||
# raise "版本库创建失败" if gshixun.try(:id).blank?
|
||||
# g.edit_project(gshixun.id, :name => new_shixun.name)
|
||||
|
||||
# 同步复制关卡
|
||||
if @shixun.challenges.present?
|
||||
@shixun.challenges.each do |challenge|
|
||||
new_challenge = Challenge.new
|
||||
new_challenge.attributes = challenge.attributes.dup.except("id","shixun_id","user_id")
|
||||
new_challenge.user_id = User.current.id
|
||||
new_challenge.shixun_id = new_shixun.id
|
||||
new_challenge.save!
|
||||
if challenge.st == 0 # 评测题
|
||||
# 同步测试集
|
||||
if challenge.test_sets.present?
|
||||
challenge.test_sets.each do |test_set|
|
||||
new_test_set = TestSet.new
|
||||
new_test_set.attributes = test_set.attributes.dup.except("id","challenge_id")
|
||||
new_test_set.challenge_id = new_challenge.id
|
||||
new_test_set.save!
|
||||
end
|
||||
end
|
||||
# 同步关卡标签
|
||||
challenge_tags = ChallengeTag.where("challenge_id =? and challenge_choose_id is null", challenge.id)
|
||||
if challenge_tags.present?
|
||||
challenge_tags.each do |challenge_tag|
|
||||
ChallengeTag.create(:challenge_id => new_challenge.id, :name => challenge_tag.try(:name))
|
||||
end
|
||||
end
|
||||
elsif challenge.st == 1 # 选择题
|
||||
if challenge.challenge_chooses.present?
|
||||
challenge.challenge_chooses.each do |challenge_choose|
|
||||
new_challenge_choose = ChallengeChoose.new
|
||||
new_challenge_choose.attributes = challenge_choose.attributes.dup.except("id","challenge_id")
|
||||
new_challenge_choose.challenge_id = new_challenge.id
|
||||
new_challenge_choose.save!
|
||||
# 每一题的选项
|
||||
if challenge_choose.challenge_questions.present?
|
||||
challenge_choose.challenge_questions.each do |challenge_question|
|
||||
new_challenge_question = ChallengeQuestion.new
|
||||
new_challenge_question.attributes = challenge_question.attributes.dup.except("id","challenge_choose_id")
|
||||
new_challenge_question.challenge_choose_id = new_challenge_choose.id
|
||||
new_challenge_question.save!
|
||||
end
|
||||
end
|
||||
# 每一题的知识标签
|
||||
st_challenge_tags = ChallengeTag.where(:challenge_id => challenge.id, :challenge_choose_id => challenge_choose.id)
|
||||
if st_challenge_tags.present?
|
||||
st_challenge_tags.each do |st_challenge_tag|
|
||||
ChallengeTag.create(:challenge_id => new_challenge.id, :name => st_challenge_tag.try(:name), :challenge_choose_id => new_challenge_choose.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
redirect_to shixun_path(new_shixun)
|
||||
rescue Exception => e
|
||||
logger.info("copy shixun failed ##{e.message}")
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
respond_to do |format|
|
||||
format.html{redirect_to shixun_challenges_path(@shixun)}
|
||||
|
|
|
|||
|
|
@ -29,9 +29,9 @@
|
|||
<%= link_to "继续实战", operation_shixun_path(@shixun, :myshixun_id => myshixun.try(:id)), :class => "fr shixun-task-btn task-btn-orange mr15 ", :id => "shixun_operation", :remote => true %>
|
||||
<% end %>
|
||||
<%= link_to '发送至', search_user_courses_shixun_path(@shixun), :remote => true, :class => "fr shixun-task-btn task-btn-green mr15" %>
|
||||
<%# if User.current.manager_of_shixun?(@shixun) %>
|
||||
<%#= link_to "复制", copy_shixun_path(@shixun), :class => "fr shixun-task-btn task-btn-green mr15", :target => "_blank" %>
|
||||
<%# end %>
|
||||
<% if User.current.manager_of_shixun?(@shixun) %>
|
||||
<a href="javascript:void(0);" onclick="op_confirm_box('<%= copy_shixun_path(@shixun) %>', '实训复制信息包括:实训关卡、版本库等基本信息');" class = "fr shixun-task-btn task-btn-green mr15">复制</a>
|
||||
<% end %>
|
||||
<% elsif @shixun.status == 3 %>
|
||||
<% unless myshixun.blank? %>
|
||||
<%= link_to "继续实战", operation_shixun_path(@shixun, :myshixun_id => myshixun.try(:id)), :class => "fr shixun-task-btn task-btn-orange mr15 ", :id => "shixun_operation", :remote => true %>
|
||||
|
|
|
|||
Loading…
Reference in New Issue