From a4eec42b7f34c7a099ea678addca4841d13a16df Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 23 Mar 2017 20:23:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=B2=E9=80=9A=E8=BF=87=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 22 +++++++++++----------- app/controllers/myshixuns_controller.rb | 5 +++++ app/views/games/_exec_results.html.erb | 9 ++++++--- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 174b01f61..4b61f02b1 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -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,8 +100,9 @@ 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 # 自动推送下一个任务 diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 86445d4ce..b93e73050 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -15,6 +15,11 @@ class MyshixunsController < ApplicationController message = Base64.decode64(params[:msg]) unless params[:msg].blank? game = Game.find(task_id) if status == 0 + 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 => nil, :game_id => task_id, :out_put => outPut) game.update_attribute(:status, 2) game.update_attribute(:final_score, game.score) diff --git a/app/views/games/_exec_results.html.erb b/app/views/games/_exec_results.html.erb index d70d1146c..6a4d23f2a 100644 --- a/app/views/games/_exec_results.html.erb +++ b/app/views/games/_exec_results.html.erb @@ -76,9 +76,12 @@ 评测中.. - + <%= link_to "下 一 步", {:controller => 'games', :action => "next_step", :id => @game, :myshixun_id => @myshixun}, :class => "task-btn task-btn-green", :remote => true %> + + 已通关 + @@ -88,7 +91,7 @@ bt.LEFT_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); }