局部刷新的一些问题

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

View File

@ -12,4 +12,11 @@ class Game < ActiveRecord::Base
render_404 if game.nil?
return game
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

View File

@ -1,5 +1,5 @@
<%= content_for(:header_tags) do %>
<%= javascript_include_tag 'baiduTemplate', 'jquery.datetimepicker.js' %>
<%= javascript_include_tag 'baiduTemplate', 'jquery.datetimepicker.js' %>
<% end %>
<div id="code_results">
<div class=" col-width fl content-history mt15" >
@ -27,8 +27,9 @@
<h3 >测试输出</h3>
</div>
<div class="content-history-inner">
Thor position=(32,4).Light position={32,4}<br/>
Engryg=74
<% unless @latest_output.nil? %>
<%= @latest_output.try(:out_put) %>
<% end %>
</div>
</div>
<div class=" col-width fl content-submit ml15 mt15">
@ -49,6 +50,8 @@
</div>
</div>
</div>
<script id="t:exec_results" type="text/html">
<div class="col-width fl mt15 content-half-fix undis" style="margin-top:125px;">
<div class="panel-header clearfix">
@ -71,61 +74,59 @@
</div>
</div>
</div>
<div class="col-width fl content-history mt15" >
<div class="panel-header clearfix">
<h3 class="fl">测评历史</h3>
<div class="fr mt5">
<a href="#"><i class="fa fa-minus font-14 mr10 fl color-grey"></i></a>
<div class="col-width fl content-history mt15" >
<div class="panel-header clearfix">
<h3 class="fl">测评历史</h3>
<div class="fr mt5">
<a href="#"><i class="fa fa-minus font-14 mr10 fl color-grey"></i></a>
<a href="javascript:void(0)" onclick="extend_window()"><i class="fa fa-expand font-14 fl color-grey"></i></a>
</div>
</div>
</div>
<div class="content-history-inner">
<% unless @outputs.blank? %>
<% @outputs.each do |output| %>
<div class="<%= output.code == 0 ? 'clearfix history-success mb10' : 'clearfix history-fail mb10' %>">
<span class="<%= output.code == 0 ? 'icon-success fl mr5' : 'icon-fail fl mr5' %>">2</span>
<p class="fl"><%= output.code == 0 ? '恭喜,您已经完成了本任务!' : '错误结果!' %></p>
<%= link_to "详情", outputs_show_myshixun_game_path(@game, :myshixun_id => @myshixun, :game_output_id => output.id), :class => "fr mr10" %>
<% unless @outputs.blank? %>
<% @outputs.each do |output| %>
<div class="<%= output.code == 0 ? 'clearfix history-success mb10' : 'clearfix history-fail mb10' %>">
<span class="<%= output.code == 0 ? 'icon-success fl mr5' : 'icon-fail fl mr5' %>">2</span>
<p class="fl"><%= output.code == 0 ? '恭喜,您已经完成了本任务!' : '错误结果!' %></p>
<%= link_to "详情", outputs_show_myshixun_game_path(@game, :myshixun_id => @myshixun, :game_output_id => output.id), :class => "fr mr10" %>
</div>
<% end %>
<% end %>
</div>
<% end %>
<% end %>
</div>
</div>
<div class="col-width fl content-output ml15 mt15">
<div class="panel-header ">
<h3 >测试输出</h3>
</div>
<div class="col-width fl content-output ml15 mt15">
<div class="panel-header ">
<h3 >测试输出</h3>
</div>
<div class="content-history-inner">
999999
</div>
<! data.latest_output !>
</div>
<div class="col-width fl content-submit ml15 mt15">
<div class="panel-header ">
<h3 >操作</h3>
</div>
<div class="col-width fl content-submit ml15 mt15">
<div class="panel-header ">
<h3 >操作</h3>
</div>
<div class="content-submitbox">
<a href="javascript:void(0)" class="task-btn mb10" onclick="file_edit_submit()">保存修改</a>
<! if(status == 0){ !>
<div id="game_commit">
<a href="javascript:void(0)" class="task-btn task-btn-green" onclick="training_task_submmit();">提交评测</a>
</div>
<! }else if(status == 1){ !>
<a class="task-btn mb10">评测中..</a>
<! }else if(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 %>
<! } !>
</div>
<! if(data.status == 0){ !>
<div id="game_commit">
<a href="javascript:void(0)" class="task-btn task-btn-green" onclick="training_task_submmit();">提交评测</a>
</div>
<! }else if(data.status == 1){ !>
<a class="task-btn mb10">评测中..</a>
<! }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 %>
<! } !>
</div>
</div>
</script>
<script >
function training_task_submmit(){
$.ajax({
url: '<%= game_build_myshixun_game_path(@game, :myshixun_id => @myshixun) %>',
success: function (){
success: function (){
// $("#training_tasl_commit").html("<span class='task-display-span alert-blue mt10'>当前任务正在后台测评中,稍后将显示您的任务完成情况......</span>");
//循环等1分钟
var intId = setInterval(function(){
@ -134,7 +135,9 @@
data:'test',
success:function(data){
//如果查到了,就退出
alert(data.outputs);
alert(data.status);
alert(data.latest_output);
clearInterval(intId);
var html = bt('t:exec_results', data);
console.log(html);