shixun结构修改
This commit is contained in:
parent
4fc3c823b7
commit
a175c4ad37
|
@ -10,9 +10,6 @@ class ChallengesController < ApplicationController
|
|||
include ApplicationHelper
|
||||
|
||||
def new
|
||||
unless @shixun.parent_id.nil?
|
||||
return render_403
|
||||
end
|
||||
# 顶部导航
|
||||
@project_menu_type = 11
|
||||
respond_to do |format|
|
||||
|
|
|
@ -24,8 +24,7 @@ class ShixunsController < ApplicationController
|
|||
# copy_myshixun自动创建系列game,game中只包含状态等信息,公共信息从Challeges中读取
|
||||
#
|
||||
def shixun_exec
|
||||
monitor_filter
|
||||
if @had_exec == true || User.current.id == @shixun.user_id
|
||||
if has_exec_cur_shixun(@shixun) || User.current.id == @shixun.user_id
|
||||
render_403
|
||||
end
|
||||
repository = @shixun.repository
|
||||
|
@ -37,14 +36,18 @@ class ShixunsController < ApplicationController
|
|||
s.sync_user(User.current)
|
||||
end
|
||||
gshixun = g.fork(@shixun.gpid, User.current.gid)
|
||||
if gshixun.id
|
||||
if !gshixun.nil?
|
||||
myshixun = copy_myshixun(@shixun, gshixun)
|
||||
challenges = @shixun.challenges
|
||||
# 之所以增加user_id是为了方便统计查询性能
|
||||
challenges.each_with_index do |challenge, index|
|
||||
publish_games(challenge, myshixun.id, index)
|
||||
status = (index == 0 ? game.status = 0 : game.status = 3)
|
||||
Game.create(:challenge_id => challenge, :myshixun_id => myshixun.id, :status => status, :user_id => myshixun.user_id)
|
||||
end
|
||||
else
|
||||
flash[:error] = "版本库创建失败"
|
||||
raise("create repository failed")
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html{redirect_to myshixun_path(myshixun)}
|
||||
end
|
||||
|
@ -90,10 +93,6 @@ class ShixunsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def index
|
||||
|
||||
end
|
||||
|
||||
def edit
|
||||
|
||||
end
|
||||
|
@ -101,10 +100,9 @@ class ShixunsController < ApplicationController
|
|||
def update
|
||||
@shixun.attributes = params[:shixun]
|
||||
params[:shixun][:is_public] == "on" ? @shixun.is_public = 1 : @shixun.is_public = 0
|
||||
if @shixun.save
|
||||
redirect_to settings_shixun_url(@shixun)
|
||||
else
|
||||
|
||||
@shixun.save
|
||||
respond_to do |format|
|
||||
format.html{redirect_to settings_shixun_url(@shixun)}
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -140,15 +138,6 @@ class ShixunsController < ApplicationController
|
|||
return
|
||||
end
|
||||
@shixun.update_attribute(:status, 1)
|
||||
# jobName = "#{@shixun.id}"
|
||||
# pipeLine = "#{Base64.encode64(@shixun.script)}"
|
||||
# uri = URI("http://123.59.135.74:9999/jenkins-exec/api/createJob")
|
||||
# params = {jobName: jobName, pipeLine: pipeLine}
|
||||
# res = uri_exec uri, params
|
||||
# training_shixun_notice res
|
||||
# if res['code'] == 0
|
||||
# @shixun.update_attribute(:status, 1)
|
||||
# end
|
||||
end
|
||||
|
||||
# 更新实训job
|
||||
|
@ -189,39 +178,32 @@ class ShixunsController < ApplicationController
|
|||
# REDO: 新增类型copy的时候
|
||||
# 复制项目
|
||||
# gshixun --> gitlab project
|
||||
def copy_myshixun tpm_shixun, gshixun
|
||||
def copy_myshixun shixun, gshixun
|
||||
myshixun = Myshixun.new
|
||||
myshixun.name = tpm_shixun.name
|
||||
myshixun.description = tpm_shixun.description
|
||||
myshixun.is_public = tpm_shixun.is_public
|
||||
myshixun.parent_id = tpm_shixun.id
|
||||
myshixun.attributes = shixun.attributes.dup.except("id","user_id","visits","gpid","status")
|
||||
myshixun.shixun_id = tpm_shixun.id
|
||||
myshixun.user_id = User.current.id
|
||||
myshixun.gpid = gshixun.id
|
||||
myshixun.forked_from = tpm_shixun.id
|
||||
jenkins_shixuns = Redmine::Configuration['jenkins_shixuns']
|
||||
if myshixun.save
|
||||
m = MyshixunMember.new(:user_id => User.current.id, :role => 1)
|
||||
myshixun.myshixun_members << m
|
||||
MyshixunMember.create(:myshixun_id => myshixun.id, :user_id => User.current.id, :role => 1)
|
||||
uri = URI("#{jenkins_shixuns}/jenkins-exec/api/createJob")
|
||||
pipeLine = "#{Base64.encode64(tpm_shixun.script)}"
|
||||
params = {jobName: "myshixun_#{myshixun.id}", pipeLine: pipeLine}
|
||||
res = uri_exec uri, params
|
||||
copy_myshixun_repository(myshixun, gshixun)
|
||||
rep = Repository.create(:myshixun_id => myshixun.id, :type => "Repository::Gitlab", :identifier => gshixun.name,
|
||||
:project_id => -1, :shixun_id => -2)
|
||||
if res.code != 0 || rep.blank?
|
||||
flash[:error] = "Job 创建失败"
|
||||
raise("Job create failed")
|
||||
end
|
||||
return myshixun
|
||||
else
|
||||
flash[:error] = "实训开启失败"
|
||||
raise("copy myshixun failed")
|
||||
end
|
||||
end
|
||||
|
||||
def copy_myshixun_repository(myshixun, gshixun)
|
||||
repository = Repository.factory('Git')
|
||||
repository.myshixun_id = myshixun.id
|
||||
repository.type = 'Repository::Gitlab'
|
||||
repository.url = gshixun.name
|
||||
repository.identifier = gshixun.name
|
||||
repository.project_id = -1
|
||||
repository.shixun_id = -2
|
||||
repository = repository.save
|
||||
end
|
||||
|
||||
def training_shixun_notice res
|
||||
if res['code'] == 0
|
||||
@notice = "实训开启成功"
|
||||
|
|
|
@ -47,12 +47,12 @@ module ApplicationHelper
|
|||
|
||||
# 正在进行中任务
|
||||
def shixun_running shixun, position
|
||||
Myshixun.find_by_sql("SELECT * FROM `myshixuns` ms, `games` g where g.myshixun_id = ms.id and parent_id =#{shixun.id} and g.stage=#{position} and (g.status=0 or g.status=1);").count
|
||||
Myshixun.find_by_sql("SELECT * FROM `myshixuns` ms, `games` g where g.myshixun_id = ms.id and shixun_id =#{shixun.id} and g.stage=#{position} and (g.status=0 or g.status=1);").count
|
||||
end
|
||||
|
||||
# 已完成任务
|
||||
def shixun_done shixun, position
|
||||
Myshixun.find_by_sql("SELECT * FROM `myshixuns` ms, `games` g where g.myshixun_id = ms.id and parent_id =#{shixun.id} and g.stage=#{position} and g.status=2;").count
|
||||
Myshixun.find_by_sql("SELECT * FROM `myshixuns` ms, `games` g where g.myshixun_id = ms.id and shixun_id =#{shixun.id} and g.stage=#{position} and g.status=2;").count
|
||||
end
|
||||
|
||||
# 测评次数
|
||||
|
@ -230,7 +230,7 @@ module ApplicationHelper
|
|||
# 判断当前用户是否已经实训过当前项目
|
||||
# project: current_project
|
||||
def has_exec_cur_shixun shixun
|
||||
Myshixun.where(:user_id => User.current.id, :parent_id => shixun.id).count > 0 ? true : false
|
||||
Myshixun.where(:user_id => User.current.id, :shixun_id => shixun.id).count > 0 ? true : false
|
||||
end
|
||||
|
||||
def allow_shixun_exec shixun
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
</li>
|
||||
<li class="clearfix">
|
||||
<label class="panel-form-label fl">文件路径:</label>
|
||||
<%= f.text_field :path, :class => "panel-form-width-690 panel-form-height-30 fl", :no_label => true, :placeholder => "进入实训后将默认打开该文件" %>
|
||||
<%= f.text_field :path, :class => "panel-form-width-690 panel-form-height-30 fl", :no_label => true, :placeholder => "进入实训后将默认打开该文件,如:app/controllers/welcome_controller.rb" %>
|
||||
</li>
|
||||
<li class="clearfix">
|
||||
<label class="panel-form-label fl">预备知识:</label>
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
class ModifyGames < ActiveRecord::Migration
|
||||
def up
|
||||
remove_column :games, :subject
|
||||
remove_column :games, :description
|
||||
remove_column :games, :stage
|
||||
remove_column :games, :ready_knowledge
|
||||
remove_column :games, :task_pass
|
||||
remove_column :games, :answer
|
||||
remove_column :games, :score
|
||||
remove_column :games, :path
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
class AddChallengeIdToGame < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :games, :challenge_id, :integer
|
||||
end
|
||||
end
|
19
db/schema.rb
19
db/schema.rb
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20170328065735) do
|
||||
ActiveRecord::Schema.define(:version => 20170328082148) do
|
||||
|
||||
create_table "activities", :force => true do |t|
|
||||
t.integer "act_id", :null => false
|
||||
|
@ -1081,18 +1081,11 @@ ActiveRecord::Schema.define(:version => 20170328065735) do
|
|||
create_table "games", :force => true do |t|
|
||||
t.integer "myshixun_id"
|
||||
t.integer "user_id"
|
||||
t.string "subject"
|
||||
t.text "description"
|
||||
t.integer "stage"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.integer "status", :default => 0
|
||||
t.text "ready_knowledge"
|
||||
t.text "task_pass"
|
||||
t.text "answer"
|
||||
t.integer "score"
|
||||
t.integer "final_score", :default => 0
|
||||
t.string "path"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.integer "status", :default => 0
|
||||
t.integer "final_score", :default => 0
|
||||
t.integer "challenge_id"
|
||||
end
|
||||
|
||||
create_table "groups_users", :id => false, :force => true do |t|
|
||||
|
|
Loading…
Reference in New Issue