@@ -1,182 +1,188 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require 'iconv' |
|
19 | 19 | |
|
20 | 20 | module RepositoriesHelper |
|
21 | 21 | def format_revision(txt) |
|
22 | 22 | txt.to_s[0,8] |
|
23 | 23 | end |
|
24 | 24 | |
|
25 | 25 | def truncate_at_line_break(text, length = 255) |
|
26 | 26 | if text |
|
27 | 27 | text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...') |
|
28 | 28 | end |
|
29 | 29 | end |
|
30 | 30 | |
|
31 | 31 | def render_properties(properties) |
|
32 | 32 | unless properties.nil? || properties.empty? |
|
33 | 33 | content = '' |
|
34 | 34 | properties.keys.sort.each do |property| |
|
35 | 35 | content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>") |
|
36 | 36 | end |
|
37 | 37 | content_tag('ul', content, :class => 'properties') |
|
38 | 38 | end |
|
39 | 39 | end |
|
40 | 40 | |
|
41 | 41 | def render_changeset_changes |
|
42 | 42 | changes = @changeset.changes.find(:all, :limit => 1000, :order => 'path').collect do |change| |
|
43 | 43 | case change.action |
|
44 | 44 | when 'A' |
|
45 | 45 | # Detects moved/copied files |
|
46 | 46 | if !change.from_path.blank? |
|
47 | 47 | change.action = @changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C' |
|
48 | 48 | end |
|
49 | 49 | change |
|
50 | 50 | when 'D' |
|
51 | 51 | @changeset.changes.detect {|c| c.from_path == change.path} ? nil : change |
|
52 | 52 | else |
|
53 | 53 | change |
|
54 | 54 | end |
|
55 |
|
|
|
55 | end.compact | |
|
56 | 56 | |
|
57 | 57 | tree = { } |
|
58 | 58 | changes.each do |change| |
|
59 | 59 | p = tree |
|
60 | 60 | dirs = change.path.to_s.split('/').select {|d| !d.blank?} |
|
61 | path = '' | |
|
61 | 62 | dirs.each do |dir| |
|
63 | path += '/' + dir | |
|
62 | 64 | p[:s] ||= {} |
|
63 | 65 | p = p[:s] |
|
64 |
p[ |
|
|
65 |
p = p[ |
|
|
66 | p[path] ||= {} | |
|
67 | p = p[path] | |
|
66 | 68 | end |
|
67 | 69 | p[:c] = change |
|
68 | 70 | end |
|
69 | 71 | |
|
70 | 72 | render_changes_tree(tree[:s]) |
|
71 | 73 | end |
|
72 | 74 | |
|
73 | 75 | def render_changes_tree(tree) |
|
74 | 76 | return '' if tree.nil? |
|
75 | 77 | |
|
76 | 78 | output = '' |
|
77 | 79 | output << '<ul>' |
|
78 | 80 | tree.keys.sort.each do |file| |
|
79 | s = !tree[file][:s].nil? | |
|
80 | c = tree[file][:c] | |
|
81 | ||
|
82 | 81 | style = 'change' |
|
83 | style << ' folder' if s | |
|
84 | style << " change-#{c.action}" if c | |
|
85 | ||
|
86 | text = h(file) | |
|
87 | unless c.nil? | |
|
82 | text = File.basename(h(file)) | |
|
83 | if s = tree[file][:s] | |
|
84 | style << ' folder' | |
|
85 | path_param = to_path_param(@repository.relative_path(file)) | |
|
86 | text = link_to(text, :controller => 'repositories', | |
|
87 | :action => 'show', | |
|
88 | :id => @project, | |
|
89 | :path => path_param, | |
|
90 | :rev => @changeset.revision) | |
|
91 | output << "<li class='#{style}'>#{text}</li>" | |
|
92 | output << render_changes_tree(s) | |
|
93 | elsif c = tree[file][:c] | |
|
94 | style << " change-#{c.action}" | |
|
88 | 95 | path_param = to_path_param(@repository.relative_path(c.path)) |
|
89 | 96 | text = link_to(text, :controller => 'repositories', |
|
90 | 97 | :action => 'entry', |
|
91 | 98 | :id => @project, |
|
92 | 99 | :path => path_param, |
|
93 |
:rev => @changeset.revision) unless |
|
|
100 | :rev => @changeset.revision) unless c.action == 'D' | |
|
94 | 101 | text << " - #{c.revision}" unless c.revision.blank? |
|
95 | 102 | text << ' (' + link_to('diff', :controller => 'repositories', |
|
96 | 103 | :action => 'diff', |
|
97 | 104 | :id => @project, |
|
98 | 105 | :path => path_param, |
|
99 | 106 | :rev => @changeset.revision) + ') ' if c.action == 'M' |
|
100 | 107 | text << ' ' + content_tag('span', c.from_path, :class => 'copied-from') unless c.from_path.blank? |
|
108 | output << "<li class='#{style}'>#{text}</li>" | |
|
101 | 109 | end |
|
102 | output << "<li class='#{style}'>#{text}</li>" | |
|
103 | output << render_changes_tree(tree[file][:s]) if s | |
|
104 | 110 | end |
|
105 | 111 | output << '</ul>' |
|
106 | 112 | output |
|
107 | 113 | end |
|
108 | 114 | |
|
109 | 115 | def to_utf8(str) |
|
110 | 116 | return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii |
|
111 | 117 | @encodings ||= Setting.repositories_encodings.split(',').collect(&:strip) |
|
112 | 118 | @encodings.each do |encoding| |
|
113 | 119 | begin |
|
114 | 120 | return Iconv.conv('UTF-8', encoding, str) |
|
115 | 121 | rescue Iconv::Failure |
|
116 | 122 | # do nothing here and try the next encoding |
|
117 | 123 | end |
|
118 | 124 | end |
|
119 | 125 | str |
|
120 | 126 | end |
|
121 | 127 | |
|
122 | 128 | def repository_field_tags(form, repository) |
|
123 | 129 | method = repository.class.name.demodulize.underscore + "_field_tags" |
|
124 | 130 | send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method) && method != 'repository_field_tags' |
|
125 | 131 | end |
|
126 | 132 | |
|
127 | 133 | def scm_select_tag(repository) |
|
128 | 134 | scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']] |
|
129 | 135 | Redmine::Scm::Base.all.each do |scm| |
|
130 | 136 | scm_options << ["Repository::#{scm}".constantize.scm_name, scm] if Setting.enabled_scm.include?(scm) || (repository && repository.class.name.demodulize == scm) |
|
131 | 137 | end |
|
132 | 138 | |
|
133 | 139 | select_tag('repository_scm', |
|
134 | 140 | options_for_select(scm_options, repository.class.name.demodulize), |
|
135 | 141 | :disabled => (repository && !repository.new_record?), |
|
136 | 142 | :onchange => remote_function(:url => { :controller => 'repositories', :action => 'edit', :id => @project }, :method => :get, :with => "Form.serialize(this.form)") |
|
137 | 143 | ) |
|
138 | 144 | end |
|
139 | 145 | |
|
140 | 146 | def with_leading_slash(path) |
|
141 | 147 | path.to_s.starts_with?('/') ? path : "/#{path}" |
|
142 | 148 | end |
|
143 | 149 | |
|
144 | 150 | def without_leading_slash(path) |
|
145 | 151 | path.gsub(%r{^/+}, '') |
|
146 | 152 | end |
|
147 | 153 | |
|
148 | 154 | def subversion_field_tags(form, repository) |
|
149 | 155 | content_tag('p', form.text_field(:url, :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)) + |
|
150 | 156 | '<br />(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') + |
|
151 | 157 | content_tag('p', form.text_field(:login, :size => 30)) + |
|
152 | 158 | content_tag('p', form.password_field(:password, :size => 30, :name => 'ignore', |
|
153 | 159 | :value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)), |
|
154 | 160 | :onfocus => "this.value=''; this.name='repository[password]';", |
|
155 | 161 | :onchange => "this.name='repository[password]';")) |
|
156 | 162 | end |
|
157 | 163 | |
|
158 | 164 | def darcs_field_tags(form, repository) |
|
159 | 165 | content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?))) |
|
160 | 166 | end |
|
161 | 167 | |
|
162 | 168 | def mercurial_field_tags(form, repository) |
|
163 | 169 | content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?))) |
|
164 | 170 | end |
|
165 | 171 | |
|
166 | 172 | def git_field_tags(form, repository) |
|
167 | 173 | content_tag('p', form.text_field(:url, :label => 'Path to .git directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?))) |
|
168 | 174 | end |
|
169 | 175 | |
|
170 | 176 | def cvs_field_tags(form, repository) |
|
171 | 177 | content_tag('p', form.text_field(:root_url, :label => 'CVSROOT', :size => 60, :required => true, :disabled => !repository.new_record?)) + |
|
172 | 178 | content_tag('p', form.text_field(:url, :label => 'Module', :size => 30, :required => true, :disabled => !repository.new_record?)) |
|
173 | 179 | end |
|
174 | 180 | |
|
175 | 181 | def bazaar_field_tags(form, repository) |
|
176 | 182 | content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?))) |
|
177 | 183 | end |
|
178 | 184 | |
|
179 | 185 | def filesystem_field_tags(form, repository) |
|
180 | 186 | content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?))) |
|
181 | 187 | end |
|
182 | 188 | end |
General Comments 0
You need to be logged in to leave comments.
Login now