diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 35d7aa281..beb32677d 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -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 diff --git a/app/views/games/_file_edit_form.html.erb b/app/views/games/_file_edit_form.html.erb index 107088eca..8501a6c3f 100644 --- a/app/views/games/_file_edit_form.html.erb +++ b/app/views/games/_file_edit_form.html.erb @@ -1,5 +1,5 @@
@@ -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); diff --git a/app/views/games/_game_results.html.erb b/app/views/games/_game_results.html.erb index 112dd68ed..62782961a 100644 --- a/app/views/games/_game_results.html.erb +++ b/app/views/games/_game_results.html.erb @@ -25,7 +25,7 @@

- / 全部通过 + / 全部通过

@@ -33,7 +33,7 @@
- 测试集 + 测试集 @@ -43,7 +43,7 @@
-
    +
    • 测试输入:
    • 预期输出:
    • 实际输出:
    • diff --git a/app/views/games/_repository.html.erb b/app/views/games/_repository.html.erb index c2739a980..24ae2442c 100644 --- a/app/views/games/_repository.html.erb +++ b/app/views/games/_repository.html.erb @@ -1,6 +1,7 @@

      <%= render :partial => 'myshixun_breadcrumbs', :locals => {:path => @path, :kind => 'dir'} %> +

      diff --git a/app/views/layouts/base_myshixun.html.erb b/app/views/layouts/base_myshixun.html.erb index 02272dac5..16ddaf3bf 100644 --- a/app/views/layouts/base_myshixun.html.erb +++ b/app/views/layouts/base_myshixun.html.erb @@ -43,7 +43,9 @@
      <%= yield %>
      +
      +