版本库添加编辑功能
This commit is contained in:
parent
0d4928da24
commit
56da0352b1
|
@ -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]
|
||||
|
@ -38,11 +39,19 @@ class GamesController < ApplicationController
|
|||
def file_edit
|
||||
entry_and_raw(false)
|
||||
@content = @repository.cat(@path, @rev)
|
||||
@content
|
||||
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
|
||||
|
|
|
@ -37,8 +37,7 @@
|
|||
<h3 >操作</h3>
|
||||
</div>
|
||||
<div class="content-submitbox">
|
||||
<a href="#" class="task-btn mb10 ">保存修改</a>
|
||||
|
||||
<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>
|
||||
|
@ -86,4 +85,8 @@
|
|||
})
|
||||
|
||||
}
|
||||
|
||||
function file_edit_submit(){
|
||||
$('#file_update_id').submit();
|
||||
}
|
||||
</script>
|
|
@ -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>
|
|
@ -5,14 +5,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="#"><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' %>
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
$("#file_entry_content").html('<%= escape_javascript(render :partial => 'games/file_edit_form') %>');
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue