To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / app / helpers / repositories_helper.rb @ 441:cbce1fd3b1b7
History | View | Annotate | Download (10.7 KB)
| 1 | 441:cbce1fd3b1b7 | Chris | # Redmine - project management software
|
|---|---|---|---|
| 2 | # Copyright (C) 2006-2011 Jean-Philippe Lang
|
||
| 3 | 0:513646585e45 | Chris | #
|
| 4 | # This program is free software; you can redistribute it and/or
|
||
| 5 | # modify it under the terms of the GNU General Public License
|
||
| 6 | # as published by the Free Software Foundation; either version 2
|
||
| 7 | # of the License, or (at your option) any later version.
|
||
| 8 | 441:cbce1fd3b1b7 | Chris | #
|
| 9 | 0:513646585e45 | Chris | # This program is distributed in the hope that it will be useful,
|
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
| 12 | # GNU General Public License for more details.
|
||
| 13 | 441:cbce1fd3b1b7 | Chris | #
|
| 14 | 0:513646585e45 | Chris | # You should have received a copy of the GNU General Public License
|
| 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.
|
||
| 17 | |||
| 18 | require 'iconv'
|
||
| 19 | 441:cbce1fd3b1b7 | Chris | require 'redmine/codeset_util'
|
| 20 | 0:513646585e45 | Chris | |
| 21 | module RepositoriesHelper |
||
| 22 | 119:8661b858af72 | Chris | def format_revision(revision) |
| 23 | if revision.respond_to? :format_identifier |
||
| 24 | revision.format_identifier |
||
| 25 | else
|
||
| 26 | revision.to_s |
||
| 27 | end
|
||
| 28 | 0:513646585e45 | Chris | end
|
| 29 | 245:051f544170fe | Chris | |
| 30 | 0:513646585e45 | Chris | def truncate_at_line_break(text, length = 255) |
| 31 | if text
|
||
| 32 | text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...') |
||
| 33 | end
|
||
| 34 | end
|
||
| 35 | 245:051f544170fe | Chris | |
| 36 | 0:513646585e45 | Chris | def render_properties(properties) |
| 37 | unless properties.nil? || properties.empty?
|
||
| 38 | content = ''
|
||
| 39 | properties.keys.sort.each do |property|
|
||
| 40 | content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>") |
||
| 41 | end
|
||
| 42 | content_tag('ul', content, :class => 'properties') |
||
| 43 | end
|
||
| 44 | end
|
||
| 45 | 245:051f544170fe | Chris | |
| 46 | 0:513646585e45 | Chris | def render_changeset_changes |
| 47 | changes = @changeset.changes.find(:all, :limit => 1000, :order => 'path').collect do |change| |
||
| 48 | case change.action
|
||
| 49 | when 'A' |
||
| 50 | # Detects moved/copied files
|
||
| 51 | if !change.from_path.blank?
|
||
| 52 | 441:cbce1fd3b1b7 | Chris | change.action = |
| 53 | @changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C' |
||
| 54 | 0:513646585e45 | Chris | end
|
| 55 | change |
||
| 56 | when 'D' |
||
| 57 | @changeset.changes.detect {|c| c.from_path == change.path} ? nil : change |
||
| 58 | else
|
||
| 59 | change |
||
| 60 | end
|
||
| 61 | 441:cbce1fd3b1b7 | Chris | end.compact
|
| 62 | |||
| 63 | 0:513646585e45 | Chris | tree = { }
|
| 64 | changes.each do |change|
|
||
| 65 | p = tree |
||
| 66 | dirs = change.path.to_s.split('/').select {|d| !d.blank?}
|
||
| 67 | path = ''
|
||
| 68 | dirs.each do |dir|
|
||
| 69 | path += '/' + dir
|
||
| 70 | p[:s] ||= {}
|
||
| 71 | p = p[:s]
|
||
| 72 | p[path] ||= {}
|
||
| 73 | p = p[path] |
||
| 74 | end
|
||
| 75 | p[:c] = change
|
||
| 76 | end
|
||
| 77 | render_changes_tree(tree[:s])
|
||
| 78 | end
|
||
| 79 | 245:051f544170fe | Chris | |
| 80 | 0:513646585e45 | Chris | def render_changes_tree(tree) |
| 81 | return '' if tree.nil? |
||
| 82 | output = ''
|
||
| 83 | output << '<ul>'
|
||
| 84 | tree.keys.sort.each do |file|
|
||
| 85 | style = 'change'
|
||
| 86 | text = File.basename(h(file))
|
||
| 87 | if s = tree[file][:s] |
||
| 88 | style << ' folder'
|
||
| 89 | path_param = to_path_param(@repository.relative_path(file))
|
||
| 90 | text = link_to(text, :controller => 'repositories', |
||
| 91 | :action => 'show', |
||
| 92 | :id => @project, |
||
| 93 | :path => path_param,
|
||
| 94 | 119:8661b858af72 | Chris | :rev => @changeset.identifier) |
| 95 | 0:513646585e45 | Chris | output << "<li class='#{style}'>#{text}</li>"
|
| 96 | output << render_changes_tree(s) |
||
| 97 | elsif c = tree[file][:c] |
||
| 98 | style << " change-#{c.action}"
|
||
| 99 | path_param = to_path_param(@repository.relative_path(c.path))
|
||
| 100 | text = link_to(text, :controller => 'repositories', |
||
| 101 | :action => 'entry', |
||
| 102 | :id => @project, |
||
| 103 | :path => path_param,
|
||
| 104 | 119:8661b858af72 | Chris | :rev => @changeset.identifier) unless c.action == 'D' |
| 105 | 0:513646585e45 | Chris | text << " - #{c.revision}" unless c.revision.blank? |
| 106 | text << ' (' + link_to('diff', :controller => 'repositories', |
||
| 107 | :action => 'diff', |
||
| 108 | :id => @project, |
||
| 109 | :path => path_param,
|
||
| 110 | 119:8661b858af72 | Chris | :rev => @changeset.identifier) + ') ' if c.action == 'M' |
| 111 | 0:513646585e45 | Chris | text << ' ' + content_tag('span', c.from_path, :class => 'copied-from') unless c.from_path.blank? |
| 112 | output << "<li class='#{style}'>#{text}</li>"
|
||
| 113 | end
|
||
| 114 | end
|
||
| 115 | output << '</ul>'
|
||
| 116 | output |
||
| 117 | end
|
||
| 118 | 245:051f544170fe | Chris | |
| 119 | 0:513646585e45 | Chris | def to_utf8(str) |
| 120 | 441:cbce1fd3b1b7 | Chris | return str if str.nil? |
| 121 | str = to_utf8_internal(str) |
||
| 122 | 119:8661b858af72 | Chris | if str.respond_to?(:force_encoding) |
| 123 | str.force_encoding('UTF-8')
|
||
| 124 | end
|
||
| 125 | 441:cbce1fd3b1b7 | Chris | str |
| 126 | end
|
||
| 127 | 245:051f544170fe | Chris | |
| 128 | 441:cbce1fd3b1b7 | Chris | 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? |
||
| 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
|
||
| 138 | 0:513646585e45 | Chris | @encodings ||= Setting.repositories_encodings.split(',').collect(&:strip) |
| 139 | @encodings.each do |encoding| |
||
| 140 | begin
|
||
| 141 | return Iconv.conv('UTF-8', encoding, str) |
||
| 142 | rescue Iconv::Failure |
||
| 143 | # do nothing here and try the next encoding
|
||
| 144 | end
|
||
| 145 | end
|
||
| 146 | 441:cbce1fd3b1b7 | Chris | str = Redmine::CodesetUtil.replace_invalid_utf8(str) |
| 147 | 245:051f544170fe | Chris | end
|
| 148 | 441:cbce1fd3b1b7 | Chris | private :to_utf8_internal
|
| 149 | 245:051f544170fe | Chris | |
| 150 | def repository_field_tags(form, repository) |
||
| 151 | 0:513646585e45 | Chris | method = repository.class.name.demodulize.underscore + "_field_tags"
|
| 152 | 245:051f544170fe | Chris | if repository.is_a?(Repository) && |
| 153 | respond_to?(method) && method != 'repository_field_tags'
|
||
| 154 | send(method, form, repository) |
||
| 155 | end
|
||
| 156 | 0:513646585e45 | Chris | end
|
| 157 | 245:051f544170fe | Chris | |
| 158 | 0:513646585e45 | Chris | def scm_select_tag(repository) |
| 159 | scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']] |
||
| 160 | Redmine::Scm::Base.all.each do |scm| |
||
| 161 | 245:051f544170fe | Chris | if Setting.enabled_scm.include?(scm) || |
| 162 | (repository && repository.class.name.demodulize == scm) |
||
| 163 | scm_options << ["Repository::#{scm}".constantize.scm_name, scm]
|
||
| 164 | end
|
||
| 165 | 0:513646585e45 | Chris | end
|
| 166 | 441:cbce1fd3b1b7 | Chris | select_tag('repository_scm',
|
| 167 | 0:513646585e45 | Chris | options_for_select(scm_options, repository.class.name.demodulize), |
| 168 | :disabled => (repository && !repository.new_record?),
|
||
| 169 | 245:051f544170fe | Chris | :onchange => remote_function(
|
| 170 | :url => {
|
||
| 171 | :controller => 'repositories', |
||
| 172 | 441:cbce1fd3b1b7 | Chris | :action => 'edit', |
| 173 | :id => @project |
||
| 174 | }, |
||
| 175 | 245:051f544170fe | Chris | :method => :get, |
| 176 | 441:cbce1fd3b1b7 | Chris | :with => "Form.serialize(this.form)") |
| 177 | ) |
||
| 178 | 0:513646585e45 | Chris | end
|
| 179 | 245:051f544170fe | Chris | |
| 180 | 0:513646585e45 | Chris | def with_leading_slash(path) |
| 181 | path.to_s.starts_with?('/') ? path : "/#{path}" |
||
| 182 | end
|
||
| 183 | 245:051f544170fe | Chris | |
| 184 | 0:513646585e45 | Chris | def without_leading_slash(path) |
| 185 | path.gsub(%r{^/+}, '') |
||
| 186 | end
|
||
| 187 | |||
| 188 | def subversion_field_tags(form, repository) |
||
| 189 | 245:051f544170fe | Chris | content_tag('p', form.text_field(:url, :size => 60, :required => true, |
| 190 | :disabled => (repository && !repository.root_url.blank?)) +
|
||
| 191 | 0:513646585e45 | Chris | '<br />(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') +
|
| 192 | content_tag('p', form.text_field(:login, :size => 30)) + |
||
| 193 | 245:051f544170fe | Chris | content_tag('p', form.password_field(
|
| 194 | :password, :size => 30, :name => 'ignore', |
||
| 195 | :value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)), |
||
| 196 | :onfocus => "this.value=''; this.name='repository[password]';", |
||
| 197 | :onchange => "this.name='repository[password]';")) |
||
| 198 | 0:513646585e45 | Chris | end
|
| 199 | |||
| 200 | def darcs_field_tags(form, repository) |
||
| 201 | 441:cbce1fd3b1b7 | Chris | content_tag('p', form.text_field(
|
| 202 | :url, :label => l(:field_path_to_repository), |
||
| 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 | 0:513646585e45 | Chris | end
|
| 209 | 245:051f544170fe | Chris | |
| 210 | 0:513646585e45 | Chris | def mercurial_field_tags(form, repository) |
| 211 | 441:cbce1fd3b1b7 | Chris | content_tag('p', form.text_field(
|
| 212 | :url, :label => l(:field_path_to_repository), |
||
| 213 | 245:051f544170fe | Chris | :size => 60, :required => true, |
| 214 | 441:cbce1fd3b1b7 | Chris | :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)) |
||
| 222 | 0:513646585e45 | Chris | end
|
| 223 | |||
| 224 | def git_field_tags(form, repository) |
||
| 225 | 441:cbce1fd3b1b7 | Chris | content_tag('p', form.text_field(
|
| 226 | :url, :label => l(:field_path_to_repository), |
||
| 227 | 245:051f544170fe | Chris | :size => 60, :required => true, |
| 228 | 441:cbce1fd3b1b7 | Chris | :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 | )) |
||
| 240 | 0:513646585e45 | Chris | end
|
| 241 | |||
| 242 | def cvs_field_tags(form, repository) |
||
| 243 | 441:cbce1fd3b1b7 | Chris | content_tag('p', form.text_field(
|
| 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)) |
||
| 261 | 0:513646585e45 | Chris | end
|
| 262 | |||
| 263 | def bazaar_field_tags(form, repository) |
||
| 264 | 441:cbce1fd3b1b7 | Chris | content_tag('p', form.text_field(
|
| 265 | :url, :label => l(:field_path_to_repository), |
||
| 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 | 0:513646585e45 | Chris | end
|
| 272 | 245:051f544170fe | Chris | |
| 273 | 0:513646585e45 | Chris | def filesystem_field_tags(form, repository) |
| 274 | 441:cbce1fd3b1b7 | Chris | content_tag('p', form.text_field(
|
| 275 | :url, :label => l(:field_root_directory), |
||
| 276 | 245:051f544170fe | Chris | :size => 60, :required => true, |
| 277 | :disabled => (repository && !repository.root_url.blank?))) +
|
||
| 278 | content_tag('p', form.select(
|
||
| 279 | :path_encoding, [nil] + Setting::ENCODINGS, |
||
| 280 | 441:cbce1fd3b1b7 | Chris | :label => l(:field_scm_path_encoding) |
| 281 | ) + |
||
| 282 | '<br />' + l(:text_scm_path_encoding_note)) |
||
| 283 | 0:513646585e45 | Chris | end
|
| 284 | end |