添加代码在线编辑功能

This commit is contained in:
huang 2017-11-08 19:01:29 +08:00
parent f607f72ce4
commit aadba839ae
7 changed files with 22 additions and 6 deletions

View File

@ -601,6 +601,7 @@ update
end
def entry_edit
entry_and_raw(false)
@content = @repository.cat(@path, @rev)
# @changesets_latest_coimmit = @g.commit(@project.gpid, @entry.try(:lastrev))
@changesets_latest_coimmit = @g.rep_last_changes(@project.gpid, :rev => @rev, :path => @path)

View File

@ -1,5 +1,7 @@
<form action="<%= entry_update_shixun_path(@project, :rev => @rev, :path => @path) %>" method="post" id="shixun_entry_update_id" data-remote="true">
<form action="/projects/<%= @project.id %>/repository/<%= @repository.identifier %>/entry_update?path=<%= @path %>&rev=<%= @rev %>" method="post" id="project_entry_update_id" data-remote="true">
<li class="clearfix" xmlns="http://www.w3.org/1999/html" id="edit_code_contents">
<textarea class="undis" id="content_shixun_entry" name="content"><%= Redmine::CodesetUtil.replace_invalid_utf8(@content) %></textarea>
<div class="autoscroll">
<textarea id="content_shixun_entry" name="content" style="width:100%;height: 700px;"><%= Redmine::CodesetUtil.replace_invalid_utf8(@content) %></textarea>
</div>
</li>
</form>

View File

@ -5,7 +5,9 @@
<div class="fl">提交于 <%= time_tag(@changesets_latest_coimmit.try(:time)) %> 前:</div>
<div class="commit_content_dec fl" title="<%= @changesets_latest_coimmit.message %>"><%= @changesets_latest_coimmit.message %></div>
<% if @entry && @entry.kind == 'file' %>
<%= render :partial => 'link_to_functions' %>
<div id="file_action" >
<%= render :partial => 'link_to_functions' %>
</div>
<% end %>
</div>
<% end %>

View File

@ -24,8 +24,10 @@
<%= "(#{number_to_human_size(@entry.size)})" if @entry.size %>
<% if params[:action] == "entry_edit" %>
<a href="javascript:void(0);" onclick="$('#shixun_entry_update_id').submit();" class = "fl mr5">保存</a>
<a href="javascript:void(0);" onclick="$('#project_entry_update_id').submit();" class = "fr mr5">保存</a>
<% elsif params[:action] == "entry" || params[:action] == "entry_update" %>
<%= link_to "编辑", entry_edit_repository_path(@project, :path => @path, :rev => @rev), :class => "fl mr5", :remote => true %>
<%= link_to "编辑", {:controller => "repositories", :action => "entry_edit", :id => @project.id, :repository_id => @repository.identifier, :path => @path, :rev => @rev}, :class => "fr mr5", :remote => true %>
<!--{:controller => 'repositories', :action => 'show', :id => @project, :repository_id => gitlab_repository(@project).try(:identifier)}-->
<% end %>
<% end %>

View File

@ -10,7 +10,9 @@
</div>
<div class="cl"></div>
<%= render :partial => 'latest_commit' %>
<%= render :partial => 'common/file', :locals => {:filename => @path, :content => @content} %>
<div id="common_file_content">
<%= render :partial => 'common/file', :locals => {:filename => @path, :content => @content} %>
</div>
<% content_for :header_tags do %>
<%= stylesheet_link_tag "scm" %>

View File

@ -1211,6 +1211,8 @@ RedmineApp::Application.routes.draw do
:action => /(browse|show|entry|raw|changes|annotate|diff|commit_diff)/
get 'projects/:id/repository/:repository_id', :to => 'repositories#show', :path => nil
get 'projects/:id/repository/:repository_id/entry_edit', :to => 'repositories#entry_edit', :path => nil
post 'projects/:id/repository/:repository_id/entry_update', :to => 'repositories#entry_update', :path => nil
get 'projects/:id/repository', :to => 'repositories#show', :path => nil
get 'projects/:id/exit', :to => 'projects#exit_project', :as => 'exit_cur_project'

View File

@ -192,6 +192,11 @@ class Gitlab::Client
get("/projects/#{project}/repository/contributors")
end
# update file
def edit_file(project, options={})
put("/projects/#{project}/repository/files", :body => options)
end
# Get an archive of the repository
# @param [Integer] project the ID fo a project.
# sha (optional) - The commit SHA to download defaults to the tip of the default branch