annotate .svn/pristine/92/92b54f75307a6f6fb76293a614977222fd8cf9eb.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents e248c7af89ec
children
rev   line source
Chris@1494 1 # encoding: utf-8
Chris@1494 2 #
Chris@1494 3 # Redmine - project management software
Chris@1494 4 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1494 5 #
Chris@1494 6 # This program is free software; you can redistribute it and/or
Chris@1494 7 # modify it under the terms of the GNU General Public License
Chris@1494 8 # as published by the Free Software Foundation; either version 2
Chris@1494 9 # of the License, or (at your option) any later version.
Chris@1494 10 #
Chris@1494 11 # This program is distributed in the hope that it will be useful,
Chris@1494 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1494 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1494 14 # GNU General Public License for more details.
Chris@1494 15 #
Chris@1494 16 # You should have received a copy of the GNU General Public License
Chris@1494 17 # along with this program; if not, write to the Free Software
Chris@1494 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1494 19
Chris@1494 20 module RepositoriesHelper
Chris@1494 21 def format_revision(revision)
Chris@1494 22 if revision.respond_to? :format_identifier
Chris@1494 23 revision.format_identifier
Chris@1494 24 else
Chris@1494 25 revision.to_s
Chris@1494 26 end
Chris@1494 27 end
Chris@1494 28
Chris@1494 29 def truncate_at_line_break(text, length = 255)
Chris@1494 30 if text
Chris@1494 31 text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...')
Chris@1494 32 end
Chris@1494 33 end
Chris@1494 34
Chris@1494 35 def render_properties(properties)
Chris@1494 36 unless properties.nil? || properties.empty?
Chris@1494 37 content = ''
Chris@1494 38 properties.keys.sort.each do |property|
Chris@1494 39 content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>".html_safe)
Chris@1494 40 end
Chris@1494 41 content_tag('ul', content.html_safe, :class => 'properties')
Chris@1494 42 end
Chris@1494 43 end
Chris@1494 44
Chris@1494 45 def render_changeset_changes
Chris@1494 46 changes = @changeset.filechanges.limit(1000).reorder('path').all.collect do |change|
Chris@1494 47 case change.action
Chris@1494 48 when 'A'
Chris@1494 49 # Detects moved/copied files
Chris@1494 50 if !change.from_path.blank?
Chris@1494 51 change.action =
Chris@1494 52 @changeset.filechanges.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C'
Chris@1494 53 end
Chris@1494 54 change
Chris@1494 55 when 'D'
Chris@1494 56 @changeset.filechanges.detect {|c| c.from_path == change.path} ? nil : change
Chris@1494 57 else
Chris@1494 58 change
Chris@1494 59 end
Chris@1494 60 end.compact
Chris@1494 61
Chris@1494 62 tree = { }
Chris@1494 63 changes.each do |change|
Chris@1494 64 p = tree
Chris@1494 65 dirs = change.path.to_s.split('/').select {|d| !d.blank?}
Chris@1494 66 path = ''
Chris@1494 67 dirs.each do |dir|
Chris@1494 68 path += '/' + dir
Chris@1494 69 p[:s] ||= {}
Chris@1494 70 p = p[:s]
Chris@1494 71 p[path] ||= {}
Chris@1494 72 p = p[path]
Chris@1494 73 end
Chris@1494 74 p[:c] = change
Chris@1494 75 end
Chris@1494 76 render_changes_tree(tree[:s])
Chris@1494 77 end
Chris@1494 78
Chris@1494 79 def render_changes_tree(tree)
Chris@1494 80 return '' if tree.nil?
Chris@1494 81 output = ''
Chris@1494 82 output << '<ul>'
Chris@1494 83 tree.keys.sort.each do |file|
Chris@1494 84 style = 'change'
Chris@1494 85 text = File.basename(h(file))
Chris@1494 86 if s = tree[file][:s]
Chris@1494 87 style << ' folder'
Chris@1494 88 path_param = to_path_param(@repository.relative_path(file))
Chris@1494 89 text = link_to(h(text), :controller => 'repositories',
Chris@1494 90 :action => 'show',
Chris@1494 91 :id => @project,
Chris@1494 92 :repository_id => @repository.identifier_param,
Chris@1494 93 :path => path_param,
Chris@1494 94 :rev => @changeset.identifier)
Chris@1494 95 output << "<li class='#{style}'>#{text}"
Chris@1494 96 output << render_changes_tree(s)
Chris@1494 97 output << "</li>"
Chris@1494 98 elsif c = tree[file][:c]
Chris@1494 99 style << " change-#{c.action}"
Chris@1494 100 path_param = to_path_param(@repository.relative_path(c.path))
Chris@1494 101 text = link_to(h(text), :controller => 'repositories',
Chris@1494 102 :action => 'entry',
Chris@1494 103 :id => @project,
Chris@1494 104 :repository_id => @repository.identifier_param,
Chris@1494 105 :path => path_param,
Chris@1494 106 :rev => @changeset.identifier) unless c.action == 'D'
Chris@1494 107 text << " - #{h(c.revision)}" unless c.revision.blank?
Chris@1494 108 text << ' ('.html_safe + link_to(l(:label_diff), :controller => 'repositories',
Chris@1494 109 :action => 'diff',
Chris@1494 110 :id => @project,
Chris@1494 111 :repository_id => @repository.identifier_param,
Chris@1494 112 :path => path_param,
Chris@1494 113 :rev => @changeset.identifier) + ') '.html_safe if c.action == 'M'
Chris@1494 114 text << ' '.html_safe + content_tag('span', h(c.from_path), :class => 'copied-from') unless c.from_path.blank?
Chris@1494 115 output << "<li class='#{style}'>#{text}</li>"
Chris@1494 116 end
Chris@1494 117 end
Chris@1494 118 output << '</ul>'
Chris@1494 119 output.html_safe
Chris@1494 120 end
Chris@1494 121
Chris@1494 122 def repository_field_tags(form, repository)
Chris@1494 123 method = repository.class.name.demodulize.underscore + "_field_tags"
Chris@1494 124 if repository.is_a?(Repository) &&
Chris@1494 125 respond_to?(method) && method != 'repository_field_tags'
Chris@1494 126 send(method, form, repository)
Chris@1494 127 end
Chris@1494 128 end
Chris@1494 129
Chris@1494 130 def scm_select_tag(repository)
Chris@1494 131 scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']]
Chris@1494 132 Redmine::Scm::Base.all.each do |scm|
Chris@1494 133 if Setting.enabled_scm.include?(scm) ||
Chris@1494 134 (repository && repository.class.name.demodulize == scm)
Chris@1494 135 scm_options << ["Repository::#{scm}".constantize.scm_name, scm]
Chris@1494 136 end
Chris@1494 137 end
Chris@1494 138 select_tag('repository_scm',
Chris@1494 139 options_for_select(scm_options, repository.class.name.demodulize),
Chris@1494 140 :disabled => (repository && !repository.new_record?),
Chris@1494 141 :data => {:remote => true, :method => 'get'})
Chris@1494 142 end
Chris@1494 143
Chris@1494 144 def with_leading_slash(path)
Chris@1494 145 path.to_s.starts_with?('/') ? path : "/#{path}"
Chris@1494 146 end
Chris@1494 147
Chris@1494 148 def without_leading_slash(path)
Chris@1494 149 path.gsub(%r{^/+}, '')
Chris@1494 150 end
Chris@1494 151
Chris@1494 152 def subversion_field_tags(form, repository)
Chris@1494 153 content_tag('p', form.text_field(:url, :size => 60, :required => true,
Chris@1494 154 :disabled => !repository.safe_attribute?('url')) +
Chris@1494 155 '<br />'.html_safe +
Chris@1494 156 '(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') +
Chris@1494 157 content_tag('p', form.text_field(:login, :size => 30)) +
Chris@1494 158 content_tag('p', form.password_field(
Chris@1494 159 :password, :size => 30, :name => 'ignore',
Chris@1494 160 :value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)),
Chris@1494 161 :onfocus => "this.value=''; this.name='repository[password]';",
Chris@1494 162 :onchange => "this.name='repository[password]';"))
Chris@1494 163 end
Chris@1494 164
Chris@1494 165 def darcs_field_tags(form, repository)
Chris@1494 166 content_tag('p', form.text_field(
Chris@1494 167 :url, :label => l(:field_path_to_repository),
Chris@1494 168 :size => 60, :required => true,
Chris@1494 169 :disabled => !repository.safe_attribute?('url'))) +
Chris@1494 170 content_tag('p', form.select(
Chris@1494 171 :log_encoding, [nil] + Setting::ENCODINGS,
Chris@1494 172 :label => l(:field_commit_logs_encoding), :required => true))
Chris@1494 173 end
Chris@1494 174
Chris@1494 175 def mercurial_field_tags(form, repository)
Chris@1494 176 content_tag('p', form.text_field(
Chris@1494 177 :url, :label => l(:field_path_to_repository),
Chris@1494 178 :size => 60, :required => true,
Chris@1494 179 :disabled => !repository.safe_attribute?('url')
Chris@1494 180 ) +
Chris@1494 181 '<br />'.html_safe + l(:text_mercurial_repository_note)) +
Chris@1494 182 content_tag('p', form.select(
Chris@1494 183 :path_encoding, [nil] + Setting::ENCODINGS,
Chris@1494 184 :label => l(:field_scm_path_encoding)
Chris@1494 185 ) +
Chris@1494 186 '<br />'.html_safe + l(:text_scm_path_encoding_note))
Chris@1494 187 end
Chris@1494 188
Chris@1494 189 def git_field_tags(form, repository)
Chris@1494 190 content_tag('p', form.text_field(
Chris@1494 191 :url, :label => l(:field_path_to_repository),
Chris@1494 192 :size => 60, :required => true,
Chris@1494 193 :disabled => !repository.safe_attribute?('url')
Chris@1494 194 ) +
Chris@1494 195 '<br />'.html_safe +
Chris@1494 196 l(:text_git_repository_note)) +
Chris@1494 197 content_tag('p', form.select(
Chris@1494 198 :path_encoding, [nil] + Setting::ENCODINGS,
Chris@1494 199 :label => l(:field_scm_path_encoding)
Chris@1494 200 ) +
Chris@1494 201 '<br />'.html_safe + l(:text_scm_path_encoding_note)) +
Chris@1494 202 content_tag('p', form.check_box(
Chris@1494 203 :extra_report_last_commit,
Chris@1494 204 :label => l(:label_git_report_last_commit)
Chris@1494 205 ))
Chris@1494 206 end
Chris@1494 207
Chris@1494 208 def cvs_field_tags(form, repository)
Chris@1494 209 content_tag('p', form.text_field(
Chris@1494 210 :root_url,
Chris@1494 211 :label => l(:field_cvsroot),
Chris@1494 212 :size => 60, :required => true,
Chris@1494 213 :disabled => !repository.safe_attribute?('root_url'))) +
Chris@1494 214 content_tag('p', form.text_field(
Chris@1494 215 :url,
Chris@1494 216 :label => l(:field_cvs_module),
Chris@1494 217 :size => 30, :required => true,
Chris@1494 218 :disabled => !repository.safe_attribute?('url'))) +
Chris@1494 219 content_tag('p', form.select(
Chris@1494 220 :log_encoding, [nil] + Setting::ENCODINGS,
Chris@1494 221 :label => l(:field_commit_logs_encoding), :required => true)) +
Chris@1494 222 content_tag('p', form.select(
Chris@1494 223 :path_encoding, [nil] + Setting::ENCODINGS,
Chris@1494 224 :label => l(:field_scm_path_encoding)
Chris@1494 225 ) +
Chris@1494 226 '<br />'.html_safe + l(:text_scm_path_encoding_note))
Chris@1494 227 end
Chris@1494 228
Chris@1494 229 def bazaar_field_tags(form, repository)
Chris@1494 230 content_tag('p', form.text_field(
Chris@1494 231 :url, :label => l(:field_path_to_repository),
Chris@1494 232 :size => 60, :required => true,
Chris@1494 233 :disabled => !repository.safe_attribute?('url'))) +
Chris@1494 234 content_tag('p', form.select(
Chris@1494 235 :log_encoding, [nil] + Setting::ENCODINGS,
Chris@1494 236 :label => l(:field_commit_logs_encoding), :required => true))
Chris@1494 237 end
Chris@1494 238
Chris@1494 239 def filesystem_field_tags(form, repository)
Chris@1494 240 content_tag('p', form.text_field(
Chris@1494 241 :url, :label => l(:field_root_directory),
Chris@1494 242 :size => 60, :required => true,
Chris@1494 243 :disabled => !repository.safe_attribute?('url'))) +
Chris@1494 244 content_tag('p', form.select(
Chris@1494 245 :path_encoding, [nil] + Setting::ENCODINGS,
Chris@1494 246 :label => l(:field_scm_path_encoding)
Chris@1494 247 ) +
Chris@1494 248 '<br />'.html_safe + l(:text_scm_path_encoding_note))
Chris@1494 249 end
Chris@1494 250
Chris@1494 251 def index_commits(commits, heads)
Chris@1494 252 return nil if commits.nil? or commits.first.parents.nil?
Chris@1494 253 refs_map = {}
Chris@1494 254 heads.each do |head|
Chris@1494 255 refs_map[head.scmid] ||= []
Chris@1494 256 refs_map[head.scmid] << head
Chris@1494 257 end
Chris@1494 258 commits_by_scmid = {}
Chris@1494 259 commits.reverse.each_with_index do |commit, commit_index|
Chris@1494 260 commits_by_scmid[commit.scmid] = {
Chris@1494 261 :parent_scmids => commit.parents.collect { |parent| parent.scmid },
Chris@1494 262 :rdmid => commit_index,
Chris@1494 263 :refs => refs_map.include?(commit.scmid) ? refs_map[commit.scmid].join(" ") : nil,
Chris@1494 264 :scmid => commit.scmid,
Chris@1494 265 :href => block_given? ? yield(commit.scmid) : commit.scmid
Chris@1494 266 }
Chris@1494 267 end
Chris@1494 268 heads.sort! { |head1, head2| head1.to_s <=> head2.to_s }
Chris@1494 269 space = nil
Chris@1494 270 heads.each do |head|
Chris@1494 271 if commits_by_scmid.include? head.scmid
Chris@1494 272 space = index_head((space || -1) + 1, head, commits_by_scmid)
Chris@1494 273 end
Chris@1494 274 end
Chris@1494 275 # when no head matched anything use first commit
Chris@1494 276 space ||= index_head(0, commits.first, commits_by_scmid)
Chris@1494 277 return commits_by_scmid, space
Chris@1494 278 end
Chris@1494 279
Chris@1494 280 def index_head(space, commit, commits_by_scmid)
Chris@1494 281 stack = [[space, commits_by_scmid[commit.scmid]]]
Chris@1494 282 max_space = space
Chris@1494 283 until stack.empty?
Chris@1494 284 space, commit = stack.pop
Chris@1494 285 commit[:space] = space if commit[:space].nil?
Chris@1494 286 space -= 1
Chris@1494 287 commit[:parent_scmids].each_with_index do |parent_scmid, parent_index|
Chris@1494 288 parent_commit = commits_by_scmid[parent_scmid]
Chris@1494 289 if parent_commit and parent_commit[:space].nil?
Chris@1494 290 stack.unshift [space += 1, parent_commit]
Chris@1494 291 end
Chris@1494 292 end
Chris@1494 293 max_space = space if max_space < space
Chris@1494 294 end
Chris@1494 295 max_space
Chris@1494 296 end
Chris@1494 297 end