局部刷新的一些问题

This commit is contained in:
huang 2017-03-21 17:53:35 +08:00
parent 905dca7758
commit d68569d3ab
3 changed files with 54 additions and 42 deletions

View File

@ -20,6 +20,7 @@ class GamesController < ApplicationController
def show def show
@git_url = git_repository_url(@myshixun, "Myshixun") @git_url = git_repository_url(@myshixun, "Myshixun")
@entries = @repository.entries(@path, @rev) @entries = @repository.entries(@path, @rev)
@latest_output = @game.latest_output
@outputs = @game.outputs @outputs = @game.outputs
respond_to do |format| respond_to do |format|
format.html format.html
@ -81,7 +82,7 @@ class GamesController < ApplicationController
params = {:jobName => "#{jobName}", :taskId => "#{taskId}", :step => "#{step}", :gitUrl => "#{gitUrl}"} params = {:jobName => "#{jobName}", :taskId => "#{taskId}", :step => "#{step}", :gitUrl => "#{gitUrl}"}
uri = URI.parse("http://123.59.135.74:9999/jenkins-exec/api/buildJob") uri = URI.parse("http://123.59.135.74:9999/jenkins-exec/api/buildJob")
res = uri_exec uri, params res = uri_exec uri, params
@game.update_attribute(:status, 1) # @game.update_attribute(:status, 1)
@outputs = @game.outputs @outputs = @game.outputs
end end
end end
@ -89,7 +90,8 @@ class GamesController < ApplicationController
def game_status def game_status
@outputs = @game.outputs @outputs = @game.outputs
render :json => {status: @game.status, outputs: @outputs} @latest_output = @game.latest_output.try(:out_put)
render :json => {status: @game.status, outputs: @outputs, latest_output:@latest_output}
end end
# 自动推送下一个任务 # 自动推送下一个任务

View File

@ -12,4 +12,11 @@ class Game < ActiveRecord::Base
render_404 if game.nil? render_404 if game.nil?
return game return game
end end
# 获取game最新的一条输出结果
def latest_output
outputs = Output.where(:game_id => self.id).order("created_at desc")
output = outputs.blank? ? nil : outputs.first
return output
end
end end

View File

@ -1,5 +1,5 @@
<%= content_for(:header_tags) do %> <%= content_for(:header_tags) do %>
<%= javascript_include_tag 'baiduTemplate', 'jquery.datetimepicker.js' %> <%= javascript_include_tag 'baiduTemplate', 'jquery.datetimepicker.js' %>
<% end %> <% end %>
<div id="code_results"> <div id="code_results">
<div class=" col-width fl content-history mt15" > <div class=" col-width fl content-history mt15" >
@ -27,8 +27,9 @@
<h3 >测试输出</h3> <h3 >测试输出</h3>
</div> </div>
<div class="content-history-inner"> <div class="content-history-inner">
Thor position=(32,4).Light position={32,4}<br/> <% unless @latest_output.nil? %>
Engryg=74 <%= @latest_output.try(:out_put) %>
<% end %>
</div> </div>
</div> </div>
<div class=" col-width fl content-submit ml15 mt15"> <div class=" col-width fl content-submit ml15 mt15">
@ -49,6 +50,8 @@
</div> </div>
</div> </div>
</div> </div>
<script id="t:exec_results" type="text/html"> <script id="t:exec_results" type="text/html">
<div class="col-width fl mt15 content-half-fix undis" style="margin-top:125px;"> <div class="col-width fl mt15 content-half-fix undis" style="margin-top:125px;">
<div class="panel-header clearfix"> <div class="panel-header clearfix">
@ -96,7 +99,7 @@
<h3 >测试输出</h3> <h3 >测试输出</h3>
</div> </div>
<div class="content-history-inner"> <div class="content-history-inner">
999999 <! data.latest_output !>
</div> </div>
</div> </div>
<div class="col-width fl content-submit ml15 mt15"> <div class="col-width fl content-submit ml15 mt15">
@ -106,14 +109,13 @@
<div class="content-submitbox"> <div class="content-submitbox">
<a href="javascript:void(0)" class="task-btn mb10" onclick="file_edit_submit()">保存修改</a> <a href="javascript:void(0)" class="task-btn mb10" onclick="file_edit_submit()">保存修改</a>
<! if(data.status == 0){ !>
<! if(status == 0){ !>
<div id="game_commit"> <div id="game_commit">
<a href="javascript:void(0)" class="task-btn task-btn-green" onclick="training_task_submmit();">提交评测</a> <a href="javascript:void(0)" class="task-btn task-btn-green" onclick="training_task_submmit();">提交评测</a>
</div> </div>
<! }else if(status == 1){ !> <! }else if(data.status == 1){ !>
<a class="task-btn mb10">评测中..</a> <a class="task-btn mb10">评测中..</a>
<! }else if(status == 2){ !> <! }else if(data.status == 2){ !>
<%= link_to "下 一 步", {:controller => 'games', :action => "next_step", :id => @game, :myshixun_id => @myshixun}, :class => "task-btn task-btn-green", :onclick => "training_task_submmit();", :remote => true %> <%= link_to "下 一 步", {:controller => 'games', :action => "next_step", :id => @game, :myshixun_id => @myshixun}, :class => "task-btn task-btn-green", :onclick => "training_task_submmit();", :remote => true %>
<! } !> <! } !>
</div> </div>
@ -122,7 +124,6 @@
<script > <script >
function training_task_submmit(){ function training_task_submmit(){
$.ajax({ $.ajax({
url: '<%= game_build_myshixun_game_path(@game, :myshixun_id => @myshixun) %>', url: '<%= game_build_myshixun_game_path(@game, :myshixun_id => @myshixun) %>',
success: function (){ success: function (){
@ -134,7 +135,9 @@
data:'test', data:'test',
success:function(data){ success:function(data){
//如果查到了,就退出 //如果查到了,就退出
alert(data.outputs);
alert(data.status); alert(data.status);
alert(data.latest_output);
clearInterval(intId); clearInterval(intId);
var html = bt('t:exec_results', data); var html = bt('t:exec_results', data);
console.log(html); console.log(html);