codemirror 每10秒保存一次;TIP样式调整

This commit is contained in:
daiao 2017-04-21 16:57:59 +08:00
parent d9580b5c29
commit 6afbed40d8
5 changed files with 38 additions and 8 deletions

View File

@ -94,11 +94,14 @@ class GamesController < ApplicationController
@g = Gitlab.client
content = params[:content].strip
@g.edit_file(@myshixun.gpid, :content => params[:content], :file_path => @path, :branch_name => @rev, :commit_message => "shixun exec")
render :json => {:success => "success"}
=begin
respond_to do |format|
format.js{redirect_to entry_myshixun_game_path(@game, :myshixun_id => @myshixun, :path => @path)}
format.js
end
rescue Exception => e
puts e.message
=end
end
# json调用显示左边的隐藏具体详情@game 字段 msg

View File

@ -1,5 +1,5 @@
<style type="text/css">
.CodeMirror{line-height: 1.2;}
.CodeMirror{line-height: 1.2; font-size: 14px}
</style>
<form action="/myshixuns/<%= @myshixun.id %>/games/<%= @game.id %>/file_update?path=<%= @path %>" method="post" id="file_update_id" data-remote="true">
@ -13,6 +13,9 @@
/* CodeMirror.commands.autocomplete = function(cm) {
cm.showHint({hint: CodeMirror.hint.anyword});
};*/
$(function(){
loading = $("#ajax-indicator").children('span')[0];
})
var editor_CodeMirror = CodeMirror.fromTextArea(document.getElementById("challenge-answer-edit-small"), {
mode: {name: "text/x-java",
// version: 2,
@ -28,11 +31,32 @@
editor_CodeMirror.on('change',function(cMirror){
// get value right from instance
$('#challenge-answer-edit-small').val(cMirror.getValue());
});
editor_CodeMirror.on('blur',function(cMirror){
$('#file_update_id').submit();
// 每10秒钟保存一次
editor_CodeMirror.on('focus',function(cMirror){
$("#ajax-indicator").children('span').remove();
$("#ajax-indicator").css('border', 0);
$("#ajax-indicator").css('padding', 0);
sh = setInterval(function(){
$("#save_status").html("saving");
$.ajax({
type: "POST",
url: '<%= file_update_myshixun_game_path(@myshixun.id, @game.id, :path => @path) %>',
data:{ content: $('#challenge-answer-edit-small').val()},
success: function(data){
$("#save_status").html("saved");
}
});
}, 10000);
});
// 失去焦点终止保存事件
editor_CodeMirror.on('blur',function(cMirror){
$("#ajax-indicator").css('border', "1px solid #bbb");
$("#ajax-indicator").css('padding', "0.6em");
$("#ajax-indicator").html(loading);
clearInterval(sh);
});
// 设置版本库字体间距
// $("#challenge-answer-edit-small" ).nextAll(".CodeMirror").css("line-height", 1.2);

View File

@ -25,7 +25,7 @@
</p>
<! }else{ !>
<p class="color-light-green mb10">
<i class="fa fa-check-circle font-16 " ></i><span class="ml5 mr5"><!= test_sets_count !>/<!= test_sets_count !></span> 全部通过
<i class="fa fa-check-circle font-16" ></i><span class="ml5 mr5"><!= test_sets_count !>/<!= test_sets_count !></span> 全部通过
</p>
<! } !>
<! } !>
@ -33,7 +33,7 @@
<div class="-task-ces-box mb10 clearfix">
<div class="-task-ces-top" onclick="toggle_test_case('<!= test_sets[i].is_public !>', '<!= i !>')" style="cursor:pointer">
<i class="fa fa-caret-down" ></i>
<span>测试集 <!= i + 1 !></span>
<span class="font-14">测试集 <!= i + 1 !></span>
<! if( test_sets[i].result == 0 ) { !>
<i class="fa fa-exclamation-circle -text-danger fr mt8 ml5" ></i>
<! } !>
@ -43,7 +43,7 @@
</div>
<! if(test_sets[i].is_public == 1) { !>
<div class="-task-ces-info <!= i == 0? '' : 'undis' !>" id="test_case_<!= i !>">
<ul>
<ul class=" font-14">
<li><span class="-task-ces-info-left color-blue">测试输入:</span><span><!= test_sets[i].input !></span></li>
<li><span class="-task-ces-info-left color-blue">预期输出:</span><span><!= test_sets[i].output !></span></li>
<li><span class="-task-ces-info-left color-blue">实际输出:</span><span class="color-orange"><!= test_sets[i].actual_output !></span></li>

View File

@ -1,6 +1,7 @@
<div class="panel-header clearfix" id="top_repository" style="border-bottom:0">
<h3 class="fl">
<%= render :partial => 'myshixun_breadcrumbs', :locals => {:path => @path, :kind => 'dir'} %>
<span id="save_status" class="ml15"></span>
</h3>
<div class="fr mt5 -horizontal">
<a href="javascript:void(0);" onclick="repository_extend_and_zoom();" id="extend_and_zoom"><i class="fa fa-arrows-alt font-16"></i></a>

View File

@ -43,7 +43,9 @@
</div>
<%= yield %>
</div>
<div class="ajax-indicator-new">
</div>
<div id="ajax-indicator" style="display:none;">
<span><%= l(:label_loading) %></span>
</div>