Mercurial > hg > soundsoftware-site
comparison app/helpers/.svn/text-base/repositories_helper.rb.svn-base @ 523:0b6c82dead28 luisf
Merge from branch "cannam"
author | luisf <luis.figueira@eecs.qmul.ac.uk> |
---|---|
date | Mon, 25 Jul 2011 14:23:37 +0100 |
parents | 753f1380d6bc |
children |
comparison
equal
deleted
inserted
replaced
318:f7c525dc7585 | 523:0b6c82dead28 |
---|---|
1 # redMine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006 Jean-Philippe Lang | 2 # Copyright (C) 2006-2011 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
8 # | 8 # |
9 # This program is distributed in the hope that it will be useful, | 9 # This program is distributed in the hope that it will be useful, |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 # GNU General Public License for more details. | 12 # GNU General Public License for more details. |
13 # | 13 # |
14 # You should have received a copy of the GNU General Public License | 14 # You should have received a copy of the GNU General Public License |
15 # along with this program; if not, write to the Free Software | 15 # along with this program; if not, write to the Free Software |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 17 |
18 require 'iconv' | 18 require 'iconv' |
19 require 'redmine/codeset_util' | |
19 | 20 |
20 module RepositoriesHelper | 21 module RepositoriesHelper |
21 def format_revision(txt) | 22 def format_revision(revision) |
22 txt.to_s[0,8] | 23 if revision.respond_to? :format_identifier |
23 end | 24 revision.format_identifier |
24 | 25 else |
26 revision.to_s | |
27 end | |
28 end | |
29 | |
25 def truncate_at_line_break(text, length = 255) | 30 def truncate_at_line_break(text, length = 255) |
26 if text | 31 if text |
27 text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...') | 32 text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...') |
28 end | 33 end |
29 end | 34 end |
30 | 35 |
31 def render_properties(properties) | 36 def render_properties(properties) |
32 unless properties.nil? || properties.empty? | 37 unless properties.nil? || properties.empty? |
33 content = '' | 38 content = '' |
34 properties.keys.sort.each do |property| | 39 properties.keys.sort.each do |property| |
35 content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>") | 40 content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>") |
36 end | 41 end |
37 content_tag('ul', content, :class => 'properties') | 42 content_tag('ul', content, :class => 'properties') |
38 end | 43 end |
39 end | 44 end |
40 | 45 |
41 def render_changeset_changes | 46 def render_changeset_changes |
42 changes = @changeset.changes.find(:all, :limit => 1000, :order => 'path').collect do |change| | 47 changes = @changeset.changes.find(:all, :limit => 1000, :order => 'path').collect do |change| |
43 case change.action | 48 case change.action |
44 when 'A' | 49 when 'A' |
45 # Detects moved/copied files | 50 # Detects moved/copied files |
46 if !change.from_path.blank? | 51 if !change.from_path.blank? |
47 change.action = @changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C' | 52 change.action = |
53 @changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C' | |
48 end | 54 end |
49 change | 55 change |
50 when 'D' | 56 when 'D' |
51 @changeset.changes.detect {|c| c.from_path == change.path} ? nil : change | 57 @changeset.changes.detect {|c| c.from_path == change.path} ? nil : change |
52 else | 58 else |
53 change | 59 change |
54 end | 60 end |
55 end.compact | 61 end.compact |
56 | 62 |
57 tree = { } | 63 tree = { } |
58 changes.each do |change| | 64 changes.each do |change| |
59 p = tree | 65 p = tree |
60 dirs = change.path.to_s.split('/').select {|d| !d.blank?} | 66 dirs = change.path.to_s.split('/').select {|d| !d.blank?} |
61 path = '' | 67 path = '' |
66 p[path] ||= {} | 72 p[path] ||= {} |
67 p = p[path] | 73 p = p[path] |
68 end | 74 end |
69 p[:c] = change | 75 p[:c] = change |
70 end | 76 end |
71 | |
72 render_changes_tree(tree[:s]) | 77 render_changes_tree(tree[:s]) |
73 end | 78 end |
74 | 79 |
75 def render_changes_tree(tree) | 80 def render_changes_tree(tree) |
76 return '' if tree.nil? | 81 return '' if tree.nil? |
77 | |
78 output = '' | 82 output = '' |
79 output << '<ul>' | 83 output << '<ul>' |
80 tree.keys.sort.each do |file| | 84 tree.keys.sort.each do |file| |
81 style = 'change' | 85 style = 'change' |
82 text = File.basename(h(file)) | 86 text = File.basename(h(file)) |
85 path_param = to_path_param(@repository.relative_path(file)) | 89 path_param = to_path_param(@repository.relative_path(file)) |
86 text = link_to(text, :controller => 'repositories', | 90 text = link_to(text, :controller => 'repositories', |
87 :action => 'show', | 91 :action => 'show', |
88 :id => @project, | 92 :id => @project, |
89 :path => path_param, | 93 :path => path_param, |
90 :rev => @changeset.revision) | 94 :rev => @changeset.identifier) |
91 output << "<li class='#{style}'>#{text}</li>" | 95 output << "<li class='#{style}'>#{text}</li>" |
92 output << render_changes_tree(s) | 96 output << render_changes_tree(s) |
93 elsif c = tree[file][:c] | 97 elsif c = tree[file][:c] |
94 style << " change-#{c.action}" | 98 style << " change-#{c.action}" |
95 path_param = to_path_param(@repository.relative_path(c.path)) | 99 path_param = to_path_param(@repository.relative_path(c.path)) |
96 text = link_to(text, :controller => 'repositories', | 100 text = link_to(text, :controller => 'repositories', |
97 :action => 'entry', | 101 :action => 'entry', |
98 :id => @project, | 102 :id => @project, |
99 :path => path_param, | 103 :path => path_param, |
100 :rev => @changeset.revision) unless c.action == 'D' | 104 :rev => @changeset.identifier) unless c.action == 'D' |
101 text << " - #{c.revision}" unless c.revision.blank? | 105 text << " - #{c.revision}" unless c.revision.blank? |
102 text << ' (' + link_to('diff', :controller => 'repositories', | 106 text << ' (' + link_to('diff', :controller => 'repositories', |
103 :action => 'diff', | 107 :action => 'diff', |
104 :id => @project, | 108 :id => @project, |
105 :path => path_param, | 109 :path => path_param, |
106 :rev => @changeset.revision) + ') ' if c.action == 'M' | 110 :rev => @changeset.identifier) + ') ' if c.action == 'M' |
107 text << ' ' + content_tag('span', c.from_path, :class => 'copied-from') unless c.from_path.blank? | 111 text << ' ' + content_tag('span', c.from_path, :class => 'copied-from') unless c.from_path.blank? |
108 output << "<li class='#{style}'>#{text}</li>" | 112 output << "<li class='#{style}'>#{text}</li>" |
109 end | 113 end |
110 end | 114 end |
111 output << '</ul>' | 115 output << '</ul>' |
112 output | 116 output |
113 end | 117 end |
114 | 118 |
115 def to_utf8(str) | 119 def to_utf8(str) |
120 return str if str.nil? | |
121 str = to_utf8_internal(str) | |
122 if str.respond_to?(:force_encoding) | |
123 str.force_encoding('UTF-8') | |
124 end | |
125 str | |
126 end | |
127 | |
128 def to_utf8_internal(str) | |
129 return str if str.nil? | |
130 if str.respond_to?(:force_encoding) | |
131 str.force_encoding('ASCII-8BIT') | |
132 end | |
133 return str if str.empty? | |
116 return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii | 134 return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii |
135 if str.respond_to?(:force_encoding) | |
136 str.force_encoding('UTF-8') | |
137 end | |
117 @encodings ||= Setting.repositories_encodings.split(',').collect(&:strip) | 138 @encodings ||= Setting.repositories_encodings.split(',').collect(&:strip) |
118 @encodings.each do |encoding| | 139 @encodings.each do |encoding| |
119 begin | 140 begin |
120 return Iconv.conv('UTF-8', encoding, str) | 141 return Iconv.conv('UTF-8', encoding, str) |
121 rescue Iconv::Failure | 142 rescue Iconv::Failure |
122 # do nothing here and try the next encoding | 143 # do nothing here and try the next encoding |
123 end | 144 end |
124 end | 145 end |
125 str | 146 str = Redmine::CodesetUtil.replace_invalid_utf8(str) |
126 end | 147 end |
127 | 148 private :to_utf8_internal |
128 def repository_field_tags(form, repository) | 149 |
150 def repository_field_tags(form, repository) | |
129 method = repository.class.name.demodulize.underscore + "_field_tags" | 151 method = repository.class.name.demodulize.underscore + "_field_tags" |
130 send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method) && method != 'repository_field_tags' | 152 if repository.is_a?(Repository) && |
131 end | 153 respond_to?(method) && method != 'repository_field_tags' |
132 | 154 send(method, form, repository) |
155 end | |
156 end | |
157 | |
133 def scm_select_tag(repository) | 158 def scm_select_tag(repository) |
134 scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']] | 159 scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']] |
135 Redmine::Scm::Base.all.each do |scm| | 160 Redmine::Scm::Base.all.each do |scm| |
136 scm_options << ["Repository::#{scm}".constantize.scm_name, scm] if Setting.enabled_scm.include?(scm) || (repository && repository.class.name.demodulize == scm) | 161 if Setting.enabled_scm.include?(scm) || |
137 end | 162 (repository && repository.class.name.demodulize == scm) |
138 | 163 scm_options << ["Repository::#{scm}".constantize.scm_name, scm] |
139 select_tag('repository_scm', | 164 end |
165 end | |
166 select_tag('repository_scm', | |
140 options_for_select(scm_options, repository.class.name.demodulize), | 167 options_for_select(scm_options, repository.class.name.demodulize), |
141 :disabled => (repository && !repository.new_record?), | 168 :disabled => (repository && !repository.new_record?), |
142 :onchange => remote_function(:url => { :controller => 'repositories', :action => 'edit', :id => @project }, :method => :get, :with => "Form.serialize(this.form)") | 169 :onchange => remote_function( |
143 ) | 170 :url => { |
144 end | 171 :controller => 'repositories', |
145 | 172 :action => 'edit', |
173 :id => @project | |
174 }, | |
175 :method => :get, | |
176 :with => "Form.serialize(this.form)") | |
177 ) | |
178 end | |
179 | |
146 def with_leading_slash(path) | 180 def with_leading_slash(path) |
147 path.to_s.starts_with?('/') ? path : "/#{path}" | 181 path.to_s.starts_with?('/') ? path : "/#{path}" |
148 end | 182 end |
149 | 183 |
150 def without_leading_slash(path) | 184 def without_leading_slash(path) |
151 path.gsub(%r{^/+}, '') | 185 path.gsub(%r{^/+}, '') |
152 end | 186 end |
153 | 187 |
154 def subversion_field_tags(form, repository) | 188 def subversion_field_tags(form, repository) |
155 content_tag('p', form.text_field(:url, :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)) + | 189 content_tag('p', form.text_field(:url, :size => 60, :required => true, |
190 :disabled => (repository && !repository.root_url.blank?)) + | |
156 '<br />(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') + | 191 '<br />(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') + |
157 content_tag('p', form.text_field(:login, :size => 30)) + | 192 content_tag('p', form.text_field(:login, :size => 30)) + |
158 content_tag('p', form.password_field(:password, :size => 30, :name => 'ignore', | 193 content_tag('p', form.password_field( |
159 :value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)), | 194 :password, :size => 30, :name => 'ignore', |
160 :onfocus => "this.value=''; this.name='repository[password]';", | 195 :value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)), |
161 :onchange => "this.name='repository[password]';")) | 196 :onfocus => "this.value=''; this.name='repository[password]';", |
197 :onchange => "this.name='repository[password]';")) | |
162 end | 198 end |
163 | 199 |
164 def darcs_field_tags(form, repository) | 200 def darcs_field_tags(form, repository) |
165 content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?))) | 201 content_tag('p', form.text_field( |
166 end | 202 :url, :label => l(:field_path_to_repository), |
167 | 203 :size => 60, :required => true, |
204 :disabled => (repository && !repository.new_record?))) + | |
205 content_tag('p', form.select( | |
206 :log_encoding, [nil] + Setting::ENCODINGS, | |
207 :label => l(:field_commit_logs_encoding), :required => true)) | |
208 end | |
209 | |
168 def mercurial_field_tags(form, repository) | 210 def mercurial_field_tags(form, repository) |
169 content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?))) | 211 content_tag('p', form.text_field( |
212 :url, :label => l(:field_path_to_repository), | |
213 :size => 60, :required => true, | |
214 :disabled => (repository && !repository.root_url.blank?) | |
215 ) + | |
216 '<br />' + l(:text_mercurial_repository_note)) + | |
217 content_tag('p', form.select( | |
218 :path_encoding, [nil] + Setting::ENCODINGS, | |
219 :label => l(:field_scm_path_encoding) | |
220 ) + | |
221 '<br />' + l(:text_scm_path_encoding_note)) | |
170 end | 222 end |
171 | 223 |
172 def git_field_tags(form, repository) | 224 def git_field_tags(form, repository) |
173 content_tag('p', form.text_field(:url, :label => 'Path to .git directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?))) | 225 content_tag('p', form.text_field( |
226 :url, :label => l(:field_path_to_repository), | |
227 :size => 60, :required => true, | |
228 :disabled => (repository && !repository.root_url.blank?) | |
229 ) + | |
230 '<br />' + l(:text_git_repository_note)) + | |
231 content_tag('p', form.select( | |
232 :path_encoding, [nil] + Setting::ENCODINGS, | |
233 :label => l(:field_scm_path_encoding) | |
234 ) + | |
235 '<br />' + l(:text_scm_path_encoding_note)) + | |
236 content_tag('p', form.check_box( | |
237 :extra_report_last_commit, | |
238 :label => l(:label_git_report_last_commit) | |
239 )) | |
174 end | 240 end |
175 | 241 |
176 def cvs_field_tags(form, repository) | 242 def cvs_field_tags(form, repository) |
177 content_tag('p', form.text_field(:root_url, :label => 'CVSROOT', :size => 60, :required => true, :disabled => !repository.new_record?)) + | 243 content_tag('p', form.text_field( |
178 content_tag('p', form.text_field(:url, :label => 'Module', :size => 30, :required => true, :disabled => !repository.new_record?)) | 244 :root_url, |
245 :label => l(:field_cvsroot), | |
246 :size => 60, :required => true, | |
247 :disabled => !repository.new_record?)) + | |
248 content_tag('p', form.text_field( | |
249 :url, | |
250 :label => l(:field_cvs_module), | |
251 :size => 30, :required => true, | |
252 :disabled => !repository.new_record?)) + | |
253 content_tag('p', form.select( | |
254 :log_encoding, [nil] + Setting::ENCODINGS, | |
255 :label => l(:field_commit_logs_encoding), :required => true)) + | |
256 content_tag('p', form.select( | |
257 :path_encoding, [nil] + Setting::ENCODINGS, | |
258 :label => l(:field_scm_path_encoding) | |
259 ) + | |
260 '<br />' + l(:text_scm_path_encoding_note)) | |
179 end | 261 end |
180 | 262 |
181 def bazaar_field_tags(form, repository) | 263 def bazaar_field_tags(form, repository) |
182 content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?))) | 264 content_tag('p', form.text_field( |
183 end | 265 :url, :label => l(:field_path_to_repository), |
184 | 266 :size => 60, :required => true, |
267 :disabled => (repository && !repository.new_record?))) + | |
268 content_tag('p', form.select( | |
269 :log_encoding, [nil] + Setting::ENCODINGS, | |
270 :label => l(:field_commit_logs_encoding), :required => true)) | |
271 end | |
272 | |
185 def filesystem_field_tags(form, repository) | 273 def filesystem_field_tags(form, repository) |
186 content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?))) | 274 content_tag('p', form.text_field( |
275 :url, :label => l(:field_root_directory), | |
276 :size => 60, :required => true, | |
277 :disabled => (repository && !repository.root_url.blank?))) + | |
278 content_tag('p', form.select( | |
279 :path_encoding, [nil] + Setting::ENCODINGS, | |
280 :label => l(:field_scm_path_encoding) | |
281 ) + | |
282 '<br />' + l(:text_scm_path_encoding_note)) | |
187 end | 283 end |
188 end | 284 end |