Merge branch 'dev_shixun_project' of https://git.trustie.net/jacknudt/trustieforge into dev_shixun_project

This commit is contained in:
daiao 2017-03-24 10:28:39 +08:00
commit 0dd140749c
6 changed files with 35 additions and 24 deletions

View File

@ -4,7 +4,7 @@ class GamesController < ApplicationController
before_filter :find_myshixun, :only => [:index]
before_filter :find_game, :only => [:show, :game_build, :entry,:next_step, :outputs_show, :file_edit, :file_update, :game_status]
before_filter :find_repository, :only => [:show, :entry, :file_edit, :file_update]
before_filter :allowd_manager, :only => [:game_build]
before_filter :allowd_manager
include ApplicationHelper
def index
@ -22,6 +22,7 @@ class GamesController < ApplicationController
@entries = @repository.entries(@path, @rev)
@latest_output = @game.latest_output.try(:out_put)
outputs = @game.outputs
@had_done = 1 if (@myshixun.games.count == @game.stage && @game.status ==2)
if outputs.count == 0
@results = []
else
@ -76,18 +77,16 @@ class GamesController < ApplicationController
taskId = params[:id]
jobName = "myshixun_#{@myshixun.id}"
@game.update_attribute(:status, 1)
# input = {}
# output = {}
# test_sets = @game.test_sets
# unless test_sets.blank?
# test_sets.each_with_index do |test_set, index|
# input.store("input_#{index}",test_set.try(:input))
# output.store("output_#{index}",test_set.try(:output))
# end
# end
testCode = {}
test_sets = @game.test_sets
unless test_sets.blank?
test_sets.each_with_index do |test_set, index|
testCode.store("testCode_#{index}",test_set.try(:output))
end
end
step = @game.stage
params = {:jobName => "#{jobName}", :taskId => "#{taskId}", :step => "#{step}", :gitUrl => "#{gitUrl}"}
params = {:jobName => "#{jobName}", :taskId => "#{taskId}", :step => "#{step}", :gitUrl => "#{gitUrl}", :testCode => "#{testCode}"}
uri = URI.parse("http://123.59.135.74:9999/jenkins-exec/api/buildJob")
res = uri_exec uri, params
render :json => {data:"success"}
@ -101,14 +100,17 @@ class GamesController < ApplicationController
else
outputs = outputs.map{|result| [result.code, result.id]}
end
had_done = 1 if (@myshixun.games.count == @game.stage && @game.status ==2)
latest_output = @game.latest_output.try(:out_put)
render :json => {status: @game.status, output: latest_output, results: outputs}
render :json => {status: @game.status, output: latest_output, results: outputs, had_done: had_done}
end
# 自动推送下一个任务
def next_step
render_403 if @game.status != 2
next_game = @game.next_game
next_game.update_attribute(:status, 0)
next_game.update_attribute(:status, 0) if next_game.status == 3
respond_to do |format|
format.js{redirect_to myshixun_game_path(next_game, :myshixun_id => @myshixun.id)}
end
@ -165,7 +167,7 @@ class GamesController < ApplicationController
end
def allowd_manager
render_403 unless User.current.manager_of_myshixun?(@myshixun)
render_403 unless (User.current.manager_of_myshixun?(@myshixun) || User.current.admin?)
end
# Find myshixun of id params[:id]

View File

@ -15,11 +15,16 @@ class MyshixunsController < ApplicationController
message = Base64.decode64(params[:msg]) unless params[:msg].blank?
game = Game.find(task_id)
if status == 0
game_outputs = Output.create(:code => status, :msg => nil, :game_id => task_id, :out_put => outPut)
myshixun = game.myshixun
games_count = myshixun.games.count
if game.stage == games_count
myshixun.update_attribute(:status, 1)
end
game_outputs = Output.create(:code => status, :msg => message, :game_id => task_id, :out_put => outPut)
game.update_attribute(:status, 2)
game.update_attribute(:final_score, game.score)
else
game_outputs = Output.create(:code => status, :msg => nil, :game_id => task_id, :out_put => outPut)
game_outputs = Output.create(:code => status, :msg => message, :game_id => task_id, :out_put => outPut)
game.update_attribute(:status, 0)
end
render :json => {:data => "success"}

View File

@ -6,12 +6,13 @@ class Myshixun < ActiveRecord::Base
has_many :games, :dependent => :destroy, :order => "games.id ASC"
# 当前任务:一个实训中只可能一个未完成任务(status 0或1只会存在一条记录)
# 优先取未完成的任务如果任务都完成则取stage最大的任务有下一步
# status:0 可以测评的,正在测评的
# 如果都完成,则当前任务为最后一个任务
def current_task
games = self.games
current_game = games.select{|game| game.status != 2 && game.status != 3}
current_game = games.select{|game| game.status==1 || game.status==1}.first
if current_game.blank?
current_game = Game.where(:status => 2, :myshixun_id => self.id).order("stage desc").first
current_game = games.last
end
return current_game
end

View File

@ -76,9 +76,12 @@
</div>
<! }else if(status == 1){ !>
<a class="task-btn mb10">评测中..</a>
<! }else if(status == 2){ !>
<! }else if(status == 2 && had_done != 1){ !>
<%= link_to "下 一 步", {:controller => 'games', :action => "next_step", :id => @game, :myshixun_id => @myshixun}, :class => "task-btn task-btn-green", :remote => true %>
<! } !>
<! if(had_done == 1) { !>
<a href="javascript:void(0)" class="task-btn mb10" >已通关</a>
<! } !>
</div>
</div>
</script>
@ -88,7 +91,7 @@
bt.LEFT_DELIMITER = '<!';
bt.RIGHT_DELIMITER = '!>';
$(function(){
var html = bt('t:exec_results',{status: <%= @game.status %>, output:"<%= @latest_output %>", results: <%= @results %>});
var html = bt('t:exec_results',{status: <%= @game.status %>, output:"<%= @latest_output %>", results: <%= @results %>, had_done: "<%= @had_done %>"});
$("#code_results").html(html);
});
@ -109,7 +112,7 @@
if(data.status == 2 || data.status == 0){
alert("进来了");
clearInterval(intId);
var html = bt('t:exec_results',{status: data.status, output: data.output, results: data.results});
var html = bt('t:exec_results',{status: data.status, output: data.output, results: data.results, had_done: data.had_done});
console.log(html);
$("#code_results").html(html);
}

View File

@ -7,7 +7,7 @@
<div class="sy_popup_con" style="width:380px;">
<ul class="sy_popup_add" >
<li class="center mb30" style="line-height:20px">
确定开启后,将开始计算耗时<br/>请问是否确定继续?
<%= @notice %>
</li>
<div class="task-popup-submit clearfix">
<a href="javascript:void(0);" class="task-btn fl" onclick="hideModal()">取消</a>

View File

@ -2196,4 +2196,4 @@ zh:
label_shixun_mine: 很抱歉,您不能在自己的实训项目中启动训练
label_shixun_rep_nil: 该项目还没有创建版本库,暂时不支持实训
label_shixun_had_forked: 您已经实训过该项目,点击“确定”将会跳转到您的实训项目主页,请问您是否继续?
label_shixun_exec: 实训将在后台为您创建一个新的同名项目,并为您推送第一个任务,请问您是否继续?
label_shixun_exec: 确定开启后,将开始计算耗时,请问是否确定继续?