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