Created
October 22, 2009 05:58
-
-
Save xhan/215777 to your computer and use it in GitHub Desktop.
redmine image svn system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ImagecommitController < ApplicationController | |
before_filter :find_svn_modify | |
def index | |
@result = "SVN仓库没有改变!" and return unless @is_modify | |
end | |
def commit | |
unless @is_modify | |
render :update do |page| | |
page.alert "SVN 没有改变,非法提交!" | |
end | |
return | |
end | |
comment = params[:comment].empty? ? "none comments" : params[:comment] | |
comment = "commited by " + User.current.login + ' : ' + comment | |
unless comment.unpack("U*").select{ |p| (0x4e00..0x9fa5).member? p }.pack("U*").empty? | |
render :update do |page| | |
page.alert "SVN 暂时不支持中文 :)" | |
end | |
return | |
end | |
a = `#{@params_add}` unless @params_add.empty? | |
b = `#{@params_del}` unless @params_del.empty? | |
# puts @params_add | |
# puts @params_del | |
# puts a | |
# puts b | |
result = `svn ci -m "#{comment}" /data/fileserver/proj/Mee_proj/Design/images/` | |
# puts result | |
respond_to do |wants| | |
wants.html { render :text => "<pre>success #{result}</pre>" } | |
wants.js do | |
render :update do |page| | |
# page.alert "success" | |
page.replace_html 'result',"<h2>Update Success!!</h2><p><pre>#{result}</pre></p>" | |
page.visual_effect :highlight , 'result' | |
page.hide 'commit_form' | |
end | |
end | |
end | |
end | |
private | |
def find_svn_modify | |
@params_add = "" | |
@params_del = "" | |
@array_add = [] | |
@array_del = [] | |
@array_mod = [] | |
svn_path = "**the path to your svn folder" | |
@svn_result = `svn status **the path to your svn folder**` | |
@svn_result.each_line do |line| | |
pre_sym ,path = line.split ' ' | |
# path.sub!(svn_path,'') | |
case pre_sym | |
when "?" | |
@params_add += path + " " | |
@array_add << path.sub(svn_path,'') | |
when "!" | |
@params_del += path + " " | |
@array_del << path.sub(svn_path,'') | |
when "M" | |
@array_mod << path.sub(svn_path,'') | |
when "D" | |
@array_del << "(已有状态)#{path.sub(svn_path,'')}" | |
when "A" | |
@array_add << "(已有状态)#{path.sub(svn_path,'')}" | |
end | |
end | |
@params_add = "svn add " + @params_add unless @params_add.empty? | |
@params_del = "svn delete " + @params_del unless @params_del.empty? | |
@is_modify = !@array_add.empty? || !@array_del.empty? || !@array_mod.empty? | |
# puts "is_modify :#{@is_modify}" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Mee Project Image SVN Commit System</h1> | |
<div id="result"> | |
<% if @result %> | |
<h2><%= @result %></h2> | |
<% else %> | |
<ul> | |
<% for item in @array_add %> | |
<li> | |
新建 <%= item %> | |
</li> | |
<% end %> | |
<% for item in @array_mod %> | |
<li> | |
修改 <%= item %> | |
</li> | |
<% end %> | |
<% for item in @array_del %> | |
<li> | |
删除 <%= item %> | |
</li> | |
<% end %> | |
<% end %> | |
</ul> | |
</div> | |
<% unless @result %> | |
<div id = "commit_form"> | |
<h3>Input Comments Here</h3> | |
<% form_remote_tag :url => {:action => :commit} do %> | |
<%= text_area_tag 'comment' , nil , :row => 5 , :cols => 30 %> | |
<%= submit_tag 'Update SVN' %> | |
<% end %> | |
<% end %> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment