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

This commit is contained in:
daiao 2017-03-21 09:17:56 +08:00
commit c77fe5f2dd
7 changed files with 102 additions and 45 deletions

View File

@ -1,5 +1,6 @@
class GamesController < ApplicationController
layout "base_myshixun"
skip_before_filter :verify_authenticity_token, :only => [:file_update]
before_filter :find_myshixun, :only => [:index]
before_filter :find_game, :only => [:show, :game_build, :entry,:next_step, :output_show, :file_edit, :file_update, :game_status]
before_filter :find_repository, :only => [:show, :entry, :file_edit, :file_update]
@ -37,12 +38,20 @@ class GamesController < ApplicationController
def file_edit
entry_and_raw(false)
@content = @repository.cat(@path, @rev)
@content
@content = @repository.cat(@path, @rev).rstrip
respond_to do |format|
format.js
end
end
def file_update
@g = Gitlab.client
@g.edit_file(@myshixun.gpid, :content => params[:content], :file_path => @path, :branch_name => @rev, :commit_message => "shixun exec")
respond_to do |format|
format.js{redirect_to entry_myshixun_game_path(@game, :myshixun_id => @myshixun)}
end
rescue Exception => e
puts e.message
end
# json调用显示左边的隐藏具体详情@game 字段 msg

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>
@ -25,52 +25,51 @@
</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-minus-square 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" %>
</div>
<% end %>
<% end %>
<% 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>
</div>
<div class="col-width fl content-output ml15 mt15">
<div class="panel-header ">
<h3 >测试输出</h3>
<% end %>
<% end %>
</div>
</div>
<div class="col-width fl content-output ml15 mt15">
<div class="panel-header ">
<h3 >测试输出</h3>
</div>
<div class="content-history-inner">
999999
999999
</div>
</div>
</div>
<div class=" col-width fl content-submit ml15 mt15">
<div class="panel-header ">
<h3 >操作</h3>
<div class=" col-width fl content-submit ml15 mt15">
<div class="panel-header ">
<h3 >操作</h3>
</div>
<div class="content-submitbox">
<a href="#" class="task-btn mb10 ">保存修改</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 %>
<! } !>
<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>
</div>
</div>
</script>
<script >
@ -86,7 +85,7 @@
$.ajax({
url: '<%= game_build_myshixun_game_path(@game, @myshixun) %>',
success: function (){
success: function (){
$("#training_tasl_commit").html("<span class='task-display-span alert-blue mt10'>当前任务正在后台测评中,稍后将显示您的任务完成情况......</span>");
//循环等1分钟
var intId = setInterval(function(){
@ -139,4 +138,10 @@
function hide_windows(){
$(".content-half-fix").hide();
}
function file_edit_submit(){
$('#file_update_id').submit();
}
</script>

View File

@ -0,0 +1,34 @@
<%= javascript_include_tag 'baiduTemplate', 'jquery.datetimepicker.js' %>
<%= javascript_include_tag "/assets/codemirror/codemirror_python_ruby_c" %>
<%= stylesheet_link_tag "/assets/codemirror/codemirror" %>
<form action="/myshixuns/<%= @myshixun.id %>/games/<%= @game.id %>/file_update?path=<%= @path %>" method="post" id="file_update_id">
<li class="clearfix" xmlns="http://www.w3.org/1999/html">
<textarea class = "panel-form-width-690 fl task-textarea-pd" id="challenge-answer" name="content">
<%= Redmine::CodesetUtil.replace_invalid_utf8(@content) %>
</textarea>
<script>
var text = document.getElementById("challenge-answer");
</script>
</li>
</form>
<script type="text/javascript">
var editor = CodeMirror.fromTextArea(document.getElementById("challenge-answer"), {
mode: {name: 'text/x-java',
version: 2,
singleLineStringErrors: false},
lineNumbers: true,
indentUnit: 2,
matchBrackets: true
});
editor.on('change',function(cMirror){
// get value right from instance
$('#challenge-answer').val(cMirror.getValue());
});
</script>

View File

@ -18,14 +18,16 @@
</h3>
<div class="fr mt5 ">
<% if params[:action] == "entry" %>
<a href="<%= file_edit_myshixun_game_path(@game, :myshixun_id => @myshixun) %>"><i class="fa fa-edit font-18 fl color-grey mr10"></i></a>
<a href="<%= file_edit_myshixun_game_path(@game, :myshixun_id => @myshixun, :path => params[:path]) %>" data-remote="true"><i class="fa fa-edit font-18 fl color-grey mr10"></i></a>
<% end %>
<a href="javascript:void(0)" onclick="extend_repository();"><i class="fa fa-check-circle font-18 fl color-grey"></i></a>
</div>
</div>
<div class="content-editor-inner">
<% if params[:action] == "entry" %>
<%= render :partial => 'common/file', :locals => {:filename => @path, :content => @content} %>
<div id="file_entry_content">
<%= render :partial => 'common/file', :locals => {:filename => @path, :content => @content} %>
</div>
<% else %>
<% if !@entries.blank? %>
<%= render :partial => 'tree' %>
@ -72,4 +74,4 @@
function extend_repository(){
$(".content-half-fix02").show()
}
</script>
</script>

View File

@ -5,7 +5,7 @@
<li class="clearfix" xmlns="http://www.w3.org/1999/html">
<label class=" panel-form-label fl"> 参考答案:</label>
<textarea class = "panel-form-width-690 panel-form-height-150 fl task-textarea-pd">
<%= @content %>
<%= Redmine::CodesetUtil.replace_invalid_utf8(@content) %>
</textarea>
<script>
var text = document.getElementById("challenge-answer");

View File

@ -0,0 +1 @@
$("#file_entry_content").html('<%= escape_javascript(render :partial => 'games/file_edit_form') %>');

View File

@ -199,6 +199,12 @@ class Gitlab::Client
def project_archive(project, sha)
get("/projects/#{project}/repository/archive?sha=#{sha}")
end
# update file
def edit_file(project, options={})
put("/projects/#{project}/repository/files", :body => options)
end
alias_method :repo_project_archive, :project_archive
end
end