games下一关方法封装,部分模块封装
This commit is contained in:
parent
19456503da
commit
c7cf576aae
|
@ -14,9 +14,7 @@ class GamesController < ApplicationController
|
|||
def show
|
||||
@git_url = git_repository_url(@myshixun, "Myshixun")
|
||||
@entries = @repository.entries(@path, @rev)
|
||||
# if request.xhr?
|
||||
# @entries ? render(:partial => 'tree') : render(:nothing => true)
|
||||
# end
|
||||
@outputs =
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js
|
||||
|
@ -32,19 +30,19 @@ class GamesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# REDO:回复状态更新
|
||||
# status 0: 未提交测评或者提交测评失败后报错;1:中间状态还没返回值;2:返回值并成功
|
||||
def game_build
|
||||
gitUrl = git_repository_url(@myshixun, "Myshixun")
|
||||
gitUrl = Base64.encode64(gitUrl)
|
||||
taskId = params[:id]
|
||||
jobName = @myshixun.forked_from
|
||||
step = @game.stage
|
||||
|
||||
if @game.status == 0
|
||||
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
|
||||
# @challenge.update_attribute(:status, 1)
|
||||
@game.update_attribute(:status, 1)
|
||||
@outputs = @game.game_outputses
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
|
@ -56,6 +54,11 @@ class GamesController < ApplicationController
|
|||
shixun = @myshixun.parent
|
||||
position = @game.stage + 1
|
||||
challenge = Challenge.where(:shixun_id => shixun, :position => position).first
|
||||
render_404 if challenge.blank?
|
||||
next_game = publish_games challenge, @myshixun.id, position
|
||||
respond_to do |format|
|
||||
format.html{redirect_to myshixun_game_path(next_game, :myshixun_id => @myshixun.id)}
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -4,12 +4,25 @@ class MyshixunsController < ApplicationController
|
|||
before_filter :require_login, :except => [:training_task_status]
|
||||
before_filter :find_myshixun, :only => [:show]
|
||||
|
||||
# taskId 即返回的game id
|
||||
# params [:stauts] 0 表示成功,其它则失败
|
||||
# msg 错误信息
|
||||
# output 为测试用户编译输出结果
|
||||
def training_task_status
|
||||
status = params[:status].to_i
|
||||
task_id = params[:taskId]
|
||||
outPut = params[:outPut]
|
||||
message = Base64.decode64(params[:msg]) unless params[:msg].blank?
|
||||
GameOutputs.create(:code => status, :msg => message, :game_id => task_id, :out_put => outPut)
|
||||
game = Game.find(task_id)
|
||||
return if game.status == 1
|
||||
if game.status == 0
|
||||
game.update_attribute(:status, 2)
|
||||
message = nil
|
||||
else
|
||||
# 失败的时候可以继续提交
|
||||
game.update_attribute(:status, 0)
|
||||
end
|
||||
game_outputs = GameOutputs.create(:code => status, :msg => message, :game_id => task_id, :out_put => outPut)
|
||||
end
|
||||
|
||||
def show
|
||||
|
|
|
@ -37,7 +37,9 @@ class ShixunsController < ApplicationController
|
|||
end
|
||||
gshixun = g.fork(@shixun.gpid, User.current.gid)
|
||||
myshixun = copy_myshixun(@shixun, gshixun)
|
||||
publish_games(@shixun.id, myshixun.id, position = 1)
|
||||
first_challenge = Challenge.where(:shixun_id => @shixun.id, :position => 1).first
|
||||
render_404 if first_challenge.blank?
|
||||
publish_games(first_challenge, myshixun.id, position = 1)
|
||||
|
||||
respond_to do |format|
|
||||
format.html{redirect_to myshixun_games_path(myshixun)}
|
||||
|
@ -173,12 +175,7 @@ class ShixunsController < ApplicationController
|
|||
end
|
||||
|
||||
private
|
||||
def publish_games original_shixun_id, new_shixun_id, position
|
||||
original_challenge = Challenge.where(:shixun_id => original_shixun_id, :position => position).first
|
||||
challenge = Game.create(:subject => original_challenge.subject, :description => original_challenge.description,
|
||||
:stage => position, :myshixun_id => new_shixun_id, :user_id => User.current.id)
|
||||
end
|
||||
|
||||
# REDO: 新增类型copy的时候
|
||||
# 复制项目
|
||||
# gshixun --> gitlab project
|
||||
def copy_myshixun tpm_shixun, gshixun
|
||||
|
|
|
@ -36,6 +36,10 @@ module ApplicationHelper
|
|||
# def user_blogs_path(resource,parameters={})
|
||||
# super
|
||||
# end
|
||||
def publish_games challenge, myshixun_id, position
|
||||
challenge = Game.create(:subject => challenge.subject, :description => challenge.description,
|
||||
:stage => position, :myshixun_id => myshixun_id, :user_id => User.current.id)
|
||||
end
|
||||
|
||||
def git_repository_url project, type
|
||||
if type == "Shixun"
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
class Game < ActiveRecord::Base
|
||||
# stauts 0: can exe 1:failed 2:successed
|
||||
attr_accessible :description, :myshixun_id, :stage, :subject, :user_id, :status
|
||||
belongs_to :myshixun,:touch=> true
|
||||
belongs_to :user
|
||||
has_many :game_comments
|
||||
has_many :game_outputses, :dependent => :destroy
|
||||
end
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
class GameOutputs < ActiveRecord::Base
|
||||
attr_accessible :code, :msg, :out_put, :game_id
|
||||
belongs_to :game
|
||||
end
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
<div class=" col-width-5 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="#"><i class="fa fa-minus-square font-14 fl color-grey"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content-history-inner">
|
||||
<div class="clearfix history-success mb10">
|
||||
<span class="icon-success fl mr5">2</span>
|
||||
<p class="fl">恭喜,您已经完成了本任务!</p>
|
||||
<a href="#" class="fr mr10">详情</a>
|
||||
</div>
|
||||
<div class="clearfix history-fail mb10">
|
||||
<span class="icon-fail fl mr5">1</span>
|
||||
<p class="fl">错误结果!</p>
|
||||
<a href="#" class="fr mr10">详情</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class=" col-width-4 fl content-output ml15 mt15">
|
||||
<div class="panel-header ">
|
||||
<h3 >测试输出</h3>
|
||||
</div>
|
||||
<div class="content-history-inner">
|
||||
Thor position=(32,4).Light position={32,4}<br/>
|
||||
Engryg=74
|
||||
</div>
|
||||
</div>
|
||||
<div class=" col-width-2 fl content-submit ml15 mt15">
|
||||
<div class="panel-header ">
|
||||
<h3 >操作</h3>
|
||||
</div>
|
||||
<div class="content-submitbox">
|
||||
<a href="#" class="task-btn mb10 ">保存修改</a>
|
||||
<% %>
|
||||
<%= link_to "提交评测", {:controller => 'games', :action => "game_build", :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>
|
|
@ -10,17 +10,6 @@
|
|||
|
||||
<tr id="<%= tr_id %>" class="<%= h params[:parent_id] %> entry <%= entry.kind %>">
|
||||
<td style="padding-left: <%=18 * depth%>px;" class="filename_no_report hidden">
|
||||
<% if entry.is_dir? %>
|
||||
<%# 展开文件目录 %>
|
||||
<span class="expander" onclick="scmEntryClick('<%= tr_id %>', '<%= escape_javascript(url_for(
|
||||
:action => 'show',
|
||||
:id => @myshixun,
|
||||
:repository_id => @repository.identifier_param,
|
||||
:path => to_path_param(ent_path),
|
||||
:rev => @rev,
|
||||
:depth => (depth + 1),
|
||||
:parent_id => tr_id)) %>');"> </span>
|
||||
<% end %>
|
||||
<%= link_to h(ent_name),
|
||||
{:action => (entry.is_dir? ? 'show' : 'entry'), :id => @game, :myshixun_id => @myshixun, :path => to_path_param(ent_path), :rev => @rev},
|
||||
:remote => true,
|
||||
|
|
|
@ -83,46 +83,10 @@
|
|||
<div id="code_content">
|
||||
<%= render :partial => 'repository' %>
|
||||
</div>
|
||||
<div class=" col-width-5 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="#"><i class="fa fa-minus-square font-14 fl color-grey"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content-history-inner">
|
||||
<div class="clearfix history-success mb10">
|
||||
<span class="icon-success fl mr5">2</span>
|
||||
<p class="fl">恭喜,您已经完成了本任务!</p>
|
||||
<a href="#" class="fr mr10">详情</a>
|
||||
</div>
|
||||
<div class="clearfix history-fail mb10">
|
||||
<span class="icon-fail fl mr5">1</span>
|
||||
<p class="fl">错误结果!</p>
|
||||
<a href="#" class="fr mr10">详情</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class=" col-width-4 fl content-output ml15 mt15">
|
||||
<div class="panel-header ">
|
||||
<h3 >测试输出</h3>
|
||||
</div>
|
||||
<div class="content-history-inner">
|
||||
Thor position=(32,4).Light position={32,4}<br/>
|
||||
Engryg=74
|
||||
</div>
|
||||
</div>
|
||||
<div class=" col-width-1 fl content-submit ml15 mt15">
|
||||
<div class="panel-header ">
|
||||
<h3 >操作</h3>
|
||||
</div>
|
||||
<div class="content-submitbox">
|
||||
<a href="#" class="task-btn mb10 ">保存修改</a><br/>
|
||||
<%= link_to "提交评测", {:controller => 'games', :action => "game_build", :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 id="code_outputs">
|
||||
<%= render :partial => 'outputs' %>
|
||||
</div>
|
||||
<div id="outputs"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<label class="mr27"> </label>
|
||||
<a href="javascript:void(0);" class="sy_btn_grey fl " onclick="hideModal()">取 消</a>
|
||||
<% if @had_exec == true %>
|
||||
<%= link_to "确 定", shixun_path(@tpm), :class => "sy_btn_blue fl ml20", :onclick => "hideModal();", :target => "_blank" %>
|
||||
<%= link_to "确 定", myshixun_path(@tpm), :class => "sy_btn_blue fl ml20", :onclick => "hideModal();", :target => "_blank" %>
|
||||
<% else %>
|
||||
<%= link_to "确 定", shixun_exec_shixun_path(@shixun), :class => "sy_btn_blue fl ml20", :onclick => "hideModal();", :target => "_blank" %>
|
||||
<% end %>
|
||||
|
|
|
@ -117,9 +117,9 @@ a.rightbar-pause{ color:#29bd8b; font-size: 18px; margin-right:245px; margin-top
|
|||
.history-fail{ width: 100%; height:40px; line-height: 40px; background:#fdebeb; color:#e53238; }
|
||||
.icon-fail{ display:inline-block; padding:0 8px; background:#e53238; color:#fff;}
|
||||
.icon-success{ display:inline-block; padding:0 8px; background:#252e38; color:#fff;}
|
||||
.content-output{width:38%; min-width:250px;}
|
||||
.content-submit{width:10%; min-width:135px;}
|
||||
.content-submitbox{ width:120px; margin: 15px auto; height:135px;}
|
||||
.content-output{width:33%; min-width:250px;}
|
||||
.content-submit{width:10%; min-width:160px;}
|
||||
.content-submitbox{ width:130px; margin: 15px auto; height:135px;}
|
||||
.panel-inner{ background:#EFF2F7; margin:15px; padding:15px;}
|
||||
.panel-inner-title{ font-size: 14px; color: #666;}
|
||||
/* 弹框 */
|
||||
|
|
Loading…
Reference in New Issue