##// END OF EJS Templates
Truncate comments on changeset list....
Jean-Philippe Lang -
r1898:9131cdf6b91b
parent child
Show More
@@ -1,176 +1,182
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
2 # Copyright (C) 2006 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
19
20 module RepositoriesHelper
20 module RepositoriesHelper
21 def format_revision(txt)
21 def format_revision(txt)
22 txt.to_s[0,8]
22 txt.to_s[0,8]
23 end
23 end
24
24
25 def truncate_at_line_break(text, length = 255)
26 if text
27 text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...')
28 end
29 end
30
25 def render_properties(properties)
31 def render_properties(properties)
26 unless properties.nil? || properties.empty?
32 unless properties.nil? || properties.empty?
27 content = ''
33 content = ''
28 properties.keys.sort.each do |property|
34 properties.keys.sort.each do |property|
29 content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>")
35 content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>")
30 end
36 end
31 content_tag('ul', content, :class => 'properties')
37 content_tag('ul', content, :class => 'properties')
32 end
38 end
33 end
39 end
34
40
35 def render_changeset_changes
41 def render_changeset_changes
36 changes = @changeset.changes.find(:all, :limit => 1000, :order => 'path').collect do |change|
42 changes = @changeset.changes.find(:all, :limit => 1000, :order => 'path').collect do |change|
37 case change.action
43 case change.action
38 when 'A'
44 when 'A'
39 # Detects moved/copied files
45 # Detects moved/copied files
40 if !change.from_path.blank?
46 if !change.from_path.blank?
41 change.action = @changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C'
47 change.action = @changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C'
42 end
48 end
43 change
49 change
44 when 'D'
50 when 'D'
45 @changeset.changes.detect {|c| c.from_path == change.path} ? nil : change
51 @changeset.changes.detect {|c| c.from_path == change.path} ? nil : change
46 else
52 else
47 change
53 change
48 end
54 end
49 end.compact
55 end.compact
50
56
51 tree = { }
57 tree = { }
52 changes.each do |change|
58 changes.each do |change|
53 p = tree
59 p = tree
54 dirs = change.path.to_s.split('/').select {|d| !d.blank?}
60 dirs = change.path.to_s.split('/').select {|d| !d.blank?}
55 dirs.each do |dir|
61 dirs.each do |dir|
56 p[:s] ||= {}
62 p[:s] ||= {}
57 p = p[:s]
63 p = p[:s]
58 p[dir] ||= {}
64 p[dir] ||= {}
59 p = p[dir]
65 p = p[dir]
60 end
66 end
61 p[:c] = change
67 p[:c] = change
62 end
68 end
63
69
64 render_changes_tree(tree[:s])
70 render_changes_tree(tree[:s])
65 end
71 end
66
72
67 def render_changes_tree(tree)
73 def render_changes_tree(tree)
68 return '' if tree.nil?
74 return '' if tree.nil?
69
75
70 output = ''
76 output = ''
71 output << '<ul>'
77 output << '<ul>'
72 tree.keys.sort.each do |file|
78 tree.keys.sort.each do |file|
73 s = !tree[file][:s].nil?
79 s = !tree[file][:s].nil?
74 c = tree[file][:c]
80 c = tree[file][:c]
75
81
76 style = 'change'
82 style = 'change'
77 style << ' folder' if s
83 style << ' folder' if s
78 style << " change-#{c.action}" if c
84 style << " change-#{c.action}" if c
79
85
80 text = h(file)
86 text = h(file)
81 unless c.nil?
87 unless c.nil?
82 path_param = to_path_param(@repository.relative_path(c.path))
88 path_param = to_path_param(@repository.relative_path(c.path))
83 text = link_to(text, :controller => 'repositories',
89 text = link_to(text, :controller => 'repositories',
84 :action => 'entry',
90 :action => 'entry',
85 :id => @project,
91 :id => @project,
86 :path => path_param,
92 :path => path_param,
87 :rev => @changeset.revision) unless s || c.action == 'D'
93 :rev => @changeset.revision) unless s || c.action == 'D'
88 text << " - #{c.revision}" unless c.revision.blank?
94 text << " - #{c.revision}" unless c.revision.blank?
89 text << ' (' + link_to('diff', :controller => 'repositories',
95 text << ' (' + link_to('diff', :controller => 'repositories',
90 :action => 'diff',
96 :action => 'diff',
91 :id => @project,
97 :id => @project,
92 :path => path_param,
98 :path => path_param,
93 :rev => @changeset.revision) + ') ' if c.action == 'M'
99 :rev => @changeset.revision) + ') ' if c.action == 'M'
94 text << ' ' + content_tag('span', c.from_path, :class => 'copied-from') unless c.from_path.blank?
100 text << ' ' + content_tag('span', c.from_path, :class => 'copied-from') unless c.from_path.blank?
95 end
101 end
96 output << "<li class='#{style}'>#{text}</li>"
102 output << "<li class='#{style}'>#{text}</li>"
97 output << render_changes_tree(tree[file][:s]) if s
103 output << render_changes_tree(tree[file][:s]) if s
98 end
104 end
99 output << '</ul>'
105 output << '</ul>'
100 output
106 output
101 end
107 end
102
108
103 def to_utf8(str)
109 def to_utf8(str)
104 return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
110 return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
105 @encodings ||= Setting.repositories_encodings.split(',').collect(&:strip)
111 @encodings ||= Setting.repositories_encodings.split(',').collect(&:strip)
106 @encodings.each do |encoding|
112 @encodings.each do |encoding|
107 begin
113 begin
108 return Iconv.conv('UTF-8', encoding, str)
114 return Iconv.conv('UTF-8', encoding, str)
109 rescue Iconv::Failure
115 rescue Iconv::Failure
110 # do nothing here and try the next encoding
116 # do nothing here and try the next encoding
111 end
117 end
112 end
118 end
113 str
119 str
114 end
120 end
115
121
116 def repository_field_tags(form, repository)
122 def repository_field_tags(form, repository)
117 method = repository.class.name.demodulize.underscore + "_field_tags"
123 method = repository.class.name.demodulize.underscore + "_field_tags"
118 send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method)
124 send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method)
119 end
125 end
120
126
121 def scm_select_tag(repository)
127 def scm_select_tag(repository)
122 scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']]
128 scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']]
123 REDMINE_SUPPORTED_SCM.each do |scm|
129 REDMINE_SUPPORTED_SCM.each do |scm|
124 scm_options << ["Repository::#{scm}".constantize.scm_name, scm] if Setting.enabled_scm.include?(scm) || (repository && repository.class.name.demodulize == scm)
130 scm_options << ["Repository::#{scm}".constantize.scm_name, scm] if Setting.enabled_scm.include?(scm) || (repository && repository.class.name.demodulize == scm)
125 end
131 end
126
132
127 select_tag('repository_scm',
133 select_tag('repository_scm',
128 options_for_select(scm_options, repository.class.name.demodulize),
134 options_for_select(scm_options, repository.class.name.demodulize),
129 :disabled => (repository && !repository.new_record?),
135 :disabled => (repository && !repository.new_record?),
130 :onchange => remote_function(:url => { :controller => 'repositories', :action => 'edit', :id => @project }, :method => :get, :with => "Form.serialize(this.form)")
136 :onchange => remote_function(:url => { :controller => 'repositories', :action => 'edit', :id => @project }, :method => :get, :with => "Form.serialize(this.form)")
131 )
137 )
132 end
138 end
133
139
134 def with_leading_slash(path)
140 def with_leading_slash(path)
135 path.to_s.starts_with?('/') ? path : "/#{path}"
141 path.to_s.starts_with?('/') ? path : "/#{path}"
136 end
142 end
137
143
138 def without_leading_slash(path)
144 def without_leading_slash(path)
139 path.gsub(%r{^/+}, '')
145 path.gsub(%r{^/+}, '')
140 end
146 end
141
147
142 def subversion_field_tags(form, repository)
148 def subversion_field_tags(form, repository)
143 content_tag('p', form.text_field(:url, :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)) +
149 content_tag('p', form.text_field(:url, :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)) +
144 '<br />(http://, https://, svn://, file:///)') +
150 '<br />(http://, https://, svn://, file:///)') +
145 content_tag('p', form.text_field(:login, :size => 30)) +
151 content_tag('p', form.text_field(:login, :size => 30)) +
146 content_tag('p', form.password_field(:password, :size => 30, :name => 'ignore',
152 content_tag('p', form.password_field(:password, :size => 30, :name => 'ignore',
147 :value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)),
153 :value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)),
148 :onfocus => "this.value=''; this.name='repository[password]';",
154 :onfocus => "this.value=''; this.name='repository[password]';",
149 :onchange => "this.name='repository[password]';"))
155 :onchange => "this.name='repository[password]';"))
150 end
156 end
151
157
152 def darcs_field_tags(form, repository)
158 def darcs_field_tags(form, repository)
153 content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?)))
159 content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?)))
154 end
160 end
155
161
156 def mercurial_field_tags(form, repository)
162 def mercurial_field_tags(form, repository)
157 content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
163 content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
158 end
164 end
159
165
160 def git_field_tags(form, repository)
166 def git_field_tags(form, repository)
161 content_tag('p', form.text_field(:url, :label => 'Path to .git directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
167 content_tag('p', form.text_field(:url, :label => 'Path to .git directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
162 end
168 end
163
169
164 def cvs_field_tags(form, repository)
170 def cvs_field_tags(form, repository)
165 content_tag('p', form.text_field(:root_url, :label => 'CVSROOT', :size => 60, :required => true, :disabled => !repository.new_record?)) +
171 content_tag('p', form.text_field(:root_url, :label => 'CVSROOT', :size => 60, :required => true, :disabled => !repository.new_record?)) +
166 content_tag('p', form.text_field(:url, :label => 'Module', :size => 30, :required => true, :disabled => !repository.new_record?))
172 content_tag('p', form.text_field(:url, :label => 'Module', :size => 30, :required => true, :disabled => !repository.new_record?))
167 end
173 end
168
174
169 def bazaar_field_tags(form, repository)
175 def bazaar_field_tags(form, repository)
170 content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?)))
176 content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?)))
171 end
177 end
172
178
173 def filesystem_field_tags(form, repository)
179 def filesystem_field_tags(form, repository)
174 content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
180 content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
175 end
181 end
176 end
182 end
@@ -1,28 +1,28
1 <% form_tag({:controller => 'repositories', :action => 'diff', :id => @project, :path => to_path_param(path)}, :method => :get) do %>
1 <% form_tag({:controller => 'repositories', :action => 'diff', :id => @project, :path => to_path_param(path)}, :method => :get) do %>
2 <table class="list changesets">
2 <table class="list changesets">
3 <thead><tr>
3 <thead><tr>
4 <th>#</th>
4 <th>#</th>
5 <th></th>
5 <th></th>
6 <th></th>
6 <th></th>
7 <th><%= l(:label_date) %></th>
7 <th><%= l(:label_date) %></th>
8 <th><%= l(:field_author) %></th>
8 <th><%= l(:field_author) %></th>
9 <th><%= l(:field_comments) %></th>
9 <th><%= l(:field_comments) %></th>
10 </tr></thead>
10 </tr></thead>
11 <tbody>
11 <tbody>
12 <% show_diff = entry && entry.is_file? && revisions.size > 1 %>
12 <% show_diff = entry && entry.is_file? && revisions.size > 1 %>
13 <% line_num = 1 %>
13 <% line_num = 1 %>
14 <% revisions.each do |changeset| %>
14 <% revisions.each do |changeset| %>
15 <tr class="changeset <%= cycle 'odd', 'even' %>">
15 <tr class="changeset <%= cycle 'odd', 'even' %>">
16 <td class="id"><%= link_to format_revision(changeset.revision), :action => 'revision', :id => project, :rev => changeset.revision %></td>
16 <td class="id"><%= link_to format_revision(changeset.revision), :action => 'revision', :id => project, :rev => changeset.revision %></td>
17 <td class="checkbox"><%= radio_button_tag('rev', changeset.revision, (line_num==1), :id => "cb-#{line_num}", :onclick => "$('cbto-#{line_num+1}').checked=true;") if show_diff && (line_num < revisions.size) %></td>
17 <td class="checkbox"><%= radio_button_tag('rev', changeset.revision, (line_num==1), :id => "cb-#{line_num}", :onclick => "$('cbto-#{line_num+1}').checked=true;") if show_diff && (line_num < revisions.size) %></td>
18 <td class="checkbox"><%= radio_button_tag('rev_to', changeset.revision, (line_num==2), :id => "cbto-#{line_num}", :onclick => "if ($('cb-#{line_num}').checked==true) {$('cb-#{line_num-1}').checked=true;}") if show_diff && (line_num > 1) %></td>
18 <td class="checkbox"><%= radio_button_tag('rev_to', changeset.revision, (line_num==2), :id => "cbto-#{line_num}", :onclick => "if ($('cb-#{line_num}').checked==true) {$('cb-#{line_num-1}').checked=true;}") if show_diff && (line_num > 1) %></td>
19 <td class="committed_on"><%= format_time(changeset.committed_on) %></td>
19 <td class="committed_on"><%= format_time(changeset.committed_on) %></td>
20 <td class="author"><%=h changeset.committer.to_s.split('<').first %></td>
20 <td class="author"><%=h changeset.committer.to_s.split('<').first %></td>
21 <td class="comments"><%= textilizable(changeset.comments) %></td>
21 <td class="comments"><%= textilizable(truncate_at_line_break(changeset.comments)) %></td>
22 </tr>
22 </tr>
23 <% line_num += 1 %>
23 <% line_num += 1 %>
24 <% end %>
24 <% end %>
25 </tbody>
25 </tbody>
26 </table>
26 </table>
27 <%= submit_tag(l(:label_view_diff), :name => nil) if show_diff %>
27 <%= submit_tag(l(:label_view_diff), :name => nil) if show_diff %>
28 <% end %>
28 <% end %>
General Comments 0
You need to be logged in to leave comments. Login now