##// END OF EJS Templates
add raphael.js (#5501)...
add raphael.js (#5501) git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7724 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r7432:70a83bd47c43
r7604:c3a4a57291fd
Show More
repositories_helper.rb
286 lines | 10.9 KiB | text/x-ruby | RubyLexer
/ app / helpers / repositories_helper.rb
Toshi MARUYAMA
remove trailing white-spaces from repositories helper source....
r5710 # Redmine - project management software
# Copyright (C) 2006-2011 Jean-Philippe Lang
Jean-Philippe Lang
svn browser merged in trunk...
r103 #
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
Toshi MARUYAMA
remove trailing white-spaces from repositories helper source....
r5710 #
Jean-Philippe Lang
svn browser merged in trunk...
r103 # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
Toshi MARUYAMA
remove trailing white-spaces from repositories helper source....
r5710 #
Jean-Philippe Lang
svn browser merged in trunk...
r103 # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Jean-Philippe Lang
Default encodings for repository files can now be set in application settings (Admin -> Settings -> Repositories encodings)....
r803 require 'iconv'
Toshi MARUYAMA
add Redmine::CodesetUtil and move replacing invalid utf8 logic to it....
r5354 require 'redmine/codeset_util'
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638
Jean-Philippe Lang
svn browser merged in trunk...
r103 module RepositoriesHelper
Toshi MARUYAMA
Changing revision label and identifier at SCM adapter level (#3724, #6092)...
r4493 def format_revision(revision)
if revision.respond_to? :format_identifier
revision.format_identifier
else
revision.to_s
end
Jean-Philippe Lang
Merged Git support branch (r1200 to r1226)....
r1222 end
Toshi MARUYAMA
scm: code clean up repositories_helper.rb....
r4870
Jean-Philippe Lang
Truncate comments on changeset list....
r1898 def truncate_at_line_break(text, length = 255)
if text
text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...')
end
end
Toshi MARUYAMA
scm: code clean up repositories_helper.rb....
r4870
Jean-Philippe Lang
Display svn properties in the browser, svn >= 1.5.0 only (#1581)....
r1613 def render_properties(properties)
unless properties.nil? || properties.empty?
content = ''
properties.keys.sort.each do |property|
Toshi MARUYAMA
Rails3: helper: use html_safe at render_properties(properties) of RepositoriesHelper...
r7427 content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>".html_safe)
Jean-Philippe Lang
Display svn properties in the browser, svn >= 1.5.0 only (#1581)....
r1613 end
Toshi MARUYAMA
Rails3: helper: use html_safe at render_properties(properties) of RepositoriesHelper...
r7427 content_tag('ul', content.html_safe, :class => 'properties')
Jean-Philippe Lang
Display svn properties in the browser, svn >= 1.5.0 only (#1581)....
r1613 end
end
Toshi MARUYAMA
scm: code clean up repositories_helper.rb....
r4870
Jean-Philippe Lang
Render the commit changes list as a tree (#1896)....
r1868 def render_changeset_changes
changes = @changeset.changes.find(:all, :limit => 1000, :order => 'path').collect do |change|
case change.action
when 'A'
# Detects moved/copied files
if !change.from_path.blank?
Toshi MARUYAMA
scm: code clean up RepositoriesHelper....
r5386 change.action =
@changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C'
Jean-Philippe Lang
Render the commit changes list as a tree (#1896)....
r1868 end
change
when 'D'
@changeset.changes.detect {|c| c.from_path == change.path} ? nil : change
else
change
end
Toshi MARUYAMA
scm: code clean up RepositoriesHelper....
r5386 end.compact
Toshi MARUYAMA
remove trailing white-spaces from repositories helper source....
r5710
Jean-Philippe Lang
Render the commit changes list as a tree (#1896)....
r1868 tree = { }
changes.each do |change|
p = tree
dirs = change.path.to_s.split('/').select {|d| !d.blank?}
Jean-Philippe Lang
Linkify folder names on revision view (#5164)....
r3545 path = ''
Jean-Philippe Lang
Render the commit changes list as a tree (#1896)....
r1868 dirs.each do |dir|
Jean-Philippe Lang
Linkify folder names on revision view (#5164)....
r3545 path += '/' + dir
Jean-Philippe Lang
Render the commit changes list as a tree (#1896)....
r1868 p[:s] ||= {}
p = p[:s]
Jean-Philippe Lang
Linkify folder names on revision view (#5164)....
r3545 p[path] ||= {}
p = p[path]
Jean-Philippe Lang
Render the commit changes list as a tree (#1896)....
r1868 end
p[:c] = change
end
render_changes_tree(tree[:s])
end
Toshi MARUYAMA
scm: code clean up repositories_helper.rb....
r4870
Jean-Philippe Lang
Render the commit changes list as a tree (#1896)....
r1868 def render_changes_tree(tree)
return '' if tree.nil?
output = ''
output << '<ul>'
tree.keys.sort.each do |file|
style = 'change'
Jean-Philippe Lang
Linkify folder names on revision view (#5164)....
r3545 text = File.basename(h(file))
if s = tree[file][:s]
style << ' folder'
path_param = to_path_param(@repository.relative_path(file))
Toshi MARUYAMA
HTML escape at app/helpers/repositories_helper.rb....
r6235 text = link_to(h(text), :controller => 'repositories',
Jean-Philippe Lang
Linkify folder names on revision view (#5164)....
r3545 :action => 'show',
:id => @project,
:path => path_param,
Toshi MARUYAMA
Changing revision label and identifier at SCM adapter level (#3724, #6092)...
r4493 :rev => @changeset.identifier)
Jean-Philippe Lang
Linkify folder names on revision view (#5164)....
r3545 output << "<li class='#{style}'>#{text}</li>"
output << render_changes_tree(s)
elsif c = tree[file][:c]
style << " change-#{c.action}"
Jean-Philippe Lang
Render the commit changes list as a tree (#1896)....
r1868 path_param = to_path_param(@repository.relative_path(c.path))
Toshi MARUYAMA
HTML escape at app/helpers/repositories_helper.rb....
r6235 text = link_to(h(text), :controller => 'repositories',
Jean-Philippe Lang
Render the commit changes list as a tree (#1896)....
r1868 :action => 'entry',
:id => @project,
:path => path_param,
Toshi MARUYAMA
Changing revision label and identifier at SCM adapter level (#3724, #6092)...
r4493 :rev => @changeset.identifier) unless c.action == 'D'
Toshi MARUYAMA
HTML escape at app/helpers/repositories_helper.rb....
r6235 text << " - #{h(c.revision)}" unless c.revision.blank?
Toshi MARUYAMA
Rails3: helper: use html_safe at render_changes_tree(tree) of RepositoriesHelper...
r7425 text << ' ('.html_safe + link_to(l(:label_diff), :controller => 'repositories',
Jean-Philippe Lang
Render the commit changes list as a tree (#1896)....
r1868 :action => 'diff',
:id => @project,
:path => path_param,
Toshi MARUYAMA
Rails3: helper: use html_safe at render_changes_tree(tree) of RepositoriesHelper...
r7425 :rev => @changeset.identifier) + ') '.html_safe if c.action == 'M'
text << ' '.html_safe + content_tag('span', h(c.from_path), :class => 'copied-from') unless c.from_path.blank?
Jean-Philippe Lang
Linkify folder names on revision view (#5164)....
r3545 output << "<li class='#{style}'>#{text}</li>"
Jean-Philippe Lang
Render the commit changes list as a tree (#1896)....
r1868 end
end
output << '</ul>'
Toshi MARUYAMA
Rails3: helper: use html_safe at render_changes_tree(tree) of RepositoriesHelper...
r7425 output.html_safe
Jean-Philippe Lang
Render the commit changes list as a tree (#1896)....
r1868 end
Toshi MARUYAMA
scm: code clean up repositories_helper.rb....
r4870
Jean-Philippe Lang
Default encodings for repository files can now be set in application settings (Admin -> Settings -> Repositories encodings)....
r803 def to_utf8(str)
Toshi MARUYAMA
scm: to_utf8() in repositories_helper always returns UTF-8 in Ruby 1.9....
r5045 return str if str.nil?
str = to_utf8_internal(str)
if str.respond_to?(:force_encoding)
str.force_encoding('UTF-8')
end
str
end
def to_utf8_internal(str)
return str if str.nil?
Toshi MARUYAMA
scm: fix repository helper unit test fails in Ruby 1.9 and non UTF-8 locale....
r5038 if str.respond_to?(:force_encoding)
str.force_encoding('ASCII-8BIT')
end
return str if str.empty?
return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
Jean-Philippe Lang
Fixes utf8 conversions with ruby1.9....
r4485 if str.respond_to?(:force_encoding)
str.force_encoding('UTF-8')
end
Jean-Philippe Lang
Default encodings for repository files can now be set in application settings (Admin -> Settings -> Repositories encodings)....
r803 @encodings ||= Setting.repositories_encodings.split(',').collect(&:strip)
@encodings.each do |encoding|
begin
return Iconv.conv('UTF-8', encoding, str)
rescue Iconv::Failure
# do nothing here and try the next encoding
end
end
Toshi MARUYAMA
add Redmine::CodesetUtil and move replacing invalid utf8 logic to it....
r5354 str = Redmine::CodesetUtil.replace_invalid_utf8(str)
Toshi MARUYAMA
scm: Ruby 1.9 compatibility for browsing repository tree (#2664, #2274)....
r4801 end
Toshi MARUYAMA
scm: to_utf8() in repositories_helper always returns UTF-8 in Ruby 1.9....
r5045 private :to_utf8_internal
Toshi MARUYAMA
scm: Ruby 1.9 compatibility for browsing repository tree (#2664, #2274)....
r4801
def repository_field_tags(form, repository)
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 method = repository.class.name.demodulize.underscore + "_field_tags"
Toshi MARUYAMA
scm: code clean up repositories_helper.rb....
r4865 if repository.is_a?(Repository) &&
respond_to?(method) && method != 'repository_field_tags'
send(method, form, repository)
end
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 end
Toshi MARUYAMA
scm: code clean up repositories_helper.rb....
r4865
Jean-Philippe Lang
Added project module concept....
r714 def scm_select_tag(repository)
Jean-Philippe Lang
Ability to disable unused SCM adapters in application settings....
r1493 scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']]
Eric Davis
Converted the REDMINE_SUPPORTED_SCM constant to a class...
r3326 Redmine::Scm::Base.all.each do |scm|
Toshi MARUYAMA
scm: code clean up repositories_helper.rb....
r4865 if Setting.enabled_scm.include?(scm) ||
(repository && repository.class.name.demodulize == scm)
scm_options << ["Repository::#{scm}".constantize.scm_name, scm]
end
Jean-Philippe Lang
Ability to disable unused SCM adapters in application settings....
r1493 end
Toshi MARUYAMA
scm: code clean up RepositoriesHelper....
r5498 select_tag('repository_scm',
Jean-Philippe Lang
Ability to disable unused SCM adapters in application settings....
r1493 options_for_select(scm_options, repository.class.name.demodulize),
Jean-Philippe Lang
Added project module concept....
r714 :disabled => (repository && !repository.new_record?),
Toshi MARUYAMA
scm: code clean up repositories_helper.rb....
r4865 :onchange => remote_function(
:url => {
:controller => 'repositories',
Toshi MARUYAMA
scm: code clean up RepositoriesHelper....
r5498 :action => 'edit',
:id => @project
},
Toshi MARUYAMA
scm: code clean up repositories_helper.rb....
r4865 :method => :get,
Toshi MARUYAMA
scm: code clean up RepositoriesHelper....
r5498 :with => "Form.serialize(this.form)")
)
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 end
Toshi MARUYAMA
scm: code clean up repositories_helper.rb....
r4822
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 def with_leading_slash(path)
Jean-Philippe Lang
Fixed: single file 'View difference' links do not work because of duplicate slashes in url....
r1310 path.to_s.starts_with?('/') ? path : "/#{path}"
end
Toshi MARUYAMA
scm: code clean up repositories_helper.rb....
r4822
Jean-Philippe Lang
Fixed: single file 'View difference' links do not work because of duplicate slashes in url....
r1310 def without_leading_slash(path)
path.gsub(%r{^/+}, '')
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 end
def subversion_field_tags(form, repository)
Toshi MARUYAMA
scm: code clean up repositories_helper.rb....
r4822 content_tag('p', form.text_field(:url, :size => 60, :required => true,
:disabled => (repository && !repository.root_url.blank?)) +
Toshi MARUYAMA
Rails3: helper: use html_safe for Subversion setting...
r7432 '<br />'.html_safe +
'(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') +
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 content_tag('p', form.text_field(:login, :size => 30)) +
Toshi MARUYAMA
scm: code clean up repositories_helper.rb....
r4870 content_tag('p', form.password_field(
:password, :size => 30, :name => 'ignore',
:value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)),
:onfocus => "this.value=''; this.name='repository[password]';",
:onchange => "this.name='repository[password]';"))
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 end
Jean-Philippe Lang
Added Darcs basic support....
r570 def darcs_field_tags(form, repository)
Toshi MARUYAMA
scm: use i18n string at 'Path to repository' setting in Mercurial, Git, Bazaar and Darcs....
r5409 content_tag('p', form.text_field(
Toshi MARUYAMA
scm: darcs: change i18n l() parameter in setting from string to symbol....
r5555 :url, :label => l(:field_path_to_repository),
Toshi MARUYAMA
scm: code clean up RepositoriesHelper....
r5395 :size => 60, :required => true,
:disabled => (repository && !repository.new_record?))) +
Toshi MARUYAMA
scm: use i18n string at commit log encoding setting (#1735)....
r5399 content_tag('p', form.select(
:log_encoding, [nil] + Setting::ENCODINGS,
Toshi MARUYAMA
scm: darcs: change i18n l() parameter in setting from string to symbol....
r5555 :label => l(:field_commit_logs_encoding), :required => true))
Jean-Philippe Lang
Added Darcs basic support....
r570 end
Toshi MARUYAMA
scm: code clean up repositories_helper.rb....
r4822
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 def mercurial_field_tags(form, repository)
Toshi MARUYAMA
scm: mercurial: change "url" human attribute name from "Root directory" to "Path to repository"....
r5408 content_tag('p', form.text_field(
Toshi MARUYAMA
scm: mercurial: change i18n l() parameter in setting from string to symbol....
r5556 :url, :label => l(:field_path_to_repository),
Toshi MARUYAMA
scm: code clean up repositories_helper.rb....
r4822 :size => 60, :required => true,
Toshi MARUYAMA
scm: mercurial: change "url" human attribute name from "Root directory" to "Path to repository"....
r5408 :disabled => (repository && !repository.root_url.blank?)
) +
Toshi MARUYAMA
Rails3: helper: use html_safe for Mercurial setting...
r7428 '<br />'.html_safe + l(:text_mercurial_repository_note)) +
Toshi MARUYAMA
scm: mercurial: add path encoding select box at setting (#2664)....
r4881 content_tag('p', form.select(
:path_encoding, [nil] + Setting::ENCODINGS,
Toshi MARUYAMA
scm: mercurial: change i18n l() parameter in setting from string to symbol....
r5556 :label => l(:field_scm_path_encoding)
Toshi MARUYAMA
scm: use i18n string at path encoding setting note (#2274, #2664, #3462, #5251)....
r5403 ) +
Toshi MARUYAMA
Rails3: helper: use html_safe for Mercurial setting...
r7428 '<br />'.html_safe + l(:text_scm_path_encoding_note))
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 end
Jean-Philippe Lang
Merged Git support branch (r1200 to r1226)....
r1222 def git_field_tags(form, repository)
Toshi MARUYAMA
scm: use i18n string at 'Path to repository' setting in Mercurial, Git, Bazaar and Darcs....
r5409 content_tag('p', form.text_field(
Toshi MARUYAMA
scm: git: change i18n l() parameter in setting from string to symbol....
r5557 :url, :label => l(:field_path_to_repository),
Toshi MARUYAMA
scm: git: change select label to 'Path to repository'....
r4763 :size => 60, :required => true,
Toshi MARUYAMA
scm: use i18n string at 'Path to repository' setting in Mercurial, Git, Bazaar and Darcs....
r5409 :disabled => (repository && !repository.root_url.blank?)
) +
Toshi MARUYAMA
Rails3: helper: use html_safe for git setting...
r7429 '<br />'.html_safe +
Toshi MARUYAMA
improve git repository note at project setting (#9129)....
r6518 l(:text_git_repository_note)) +
Toshi MARUYAMA
scm: git: add path encoding select box at setting (#5251)....
r4944 content_tag('p', form.select(
:path_encoding, [nil] + Setting::ENCODINGS,
Toshi MARUYAMA
scm: git: change i18n l() parameter in setting from string to symbol....
r5557 :label => l(:field_scm_path_encoding)
Toshi MARUYAMA
scm: use i18n string at path encoding setting note (#2274, #2664, #3462, #5251)....
r5403 ) +
Toshi MARUYAMA
Rails3: helper: use html_safe for git setting...
r7429 '<br />'.html_safe + l(:text_scm_path_encoding_note)) +
Toshi MARUYAMA
scm: git: add check box of whether reporting last commit for files and directories in project setting (#8365, #7047)....
r5651 content_tag('p', form.check_box(
:extra_report_last_commit,
Toshi MARUYAMA
scm: git: use symbol instead of string whether reporting last commit in project setting i18n text (#8365)....
r5656 :label => l(:label_git_report_last_commit)
Toshi MARUYAMA
scm: git: add check box of whether reporting last commit for files and directories in project setting (#8365, #7047)....
r5651 ))
Jean-Philippe Lang
Merged Git support branch (r1200 to r1226)....
r1222 end
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 def cvs_field_tags(form, repository)
Toshi MARUYAMA
scm: cvs: use i18n string at 'CVSROOT' and 'Module' setting....
r5415 content_tag('p', form.text_field(
:root_url,
Toshi MARUYAMA
scm: cvs: change i18n l() parameter in setting from string to symbol....
r5558 :label => l(:field_cvsroot),
Toshi MARUYAMA
scm: cvs: use i18n string at 'CVSROOT' and 'Module' setting....
r5415 :size => 60, :required => true,
Toshi MARUYAMA
scm: code clean up RepositoriesHelper....
r5268 :disabled => !repository.new_record?)) +
Toshi MARUYAMA
scm: cvs: use i18n string at 'CVSROOT' and 'Module' setting....
r5415 content_tag('p', form.text_field(
:url,
Toshi MARUYAMA
scm: cvs: change i18n l() parameter in setting from string to symbol....
r5558 :label => l(:field_cvs_module),
Toshi MARUYAMA
scm: code clean up RepositoriesHelper....
r5268 :size => 30, :required => true,
:disabled => !repository.new_record?)) +
Toshi MARUYAMA
scm: use i18n string at commit log encoding setting (#1735)....
r5399 content_tag('p', form.select(
:log_encoding, [nil] + Setting::ENCODINGS,
Toshi MARUYAMA
scm: cvs: change i18n l() parameter in setting from string to symbol....
r5558 :label => l(:field_commit_logs_encoding), :required => true)) +
Toshi MARUYAMA
scm: cvs: add path encoding select box at setting (#3462)....
r5345 content_tag('p', form.select(
Toshi MARUYAMA
scm: use i18n string at path encoding setting note (#2274, #2664, #3462, #5251)....
r5403 :path_encoding, [nil] + Setting::ENCODINGS,
Toshi MARUYAMA
scm: cvs: change i18n l() parameter in setting from string to symbol....
r5558 :label => l(:field_scm_path_encoding)
Toshi MARUYAMA
scm: use i18n string at path encoding setting note (#2274, #2664, #3462, #5251)....
r5403 ) +
Toshi MARUYAMA
Rails3: helper: use html_safe for cvs setting...
r7430 '<br />'.html_safe + l(:text_scm_path_encoding_note))
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 end
Jean-Philippe Lang
Added Bazaar adapter....
r937
def bazaar_field_tags(form, repository)
Toshi MARUYAMA
scm: use i18n string at 'Path to repository' setting in Mercurial, Git, Bazaar and Darcs....
r5409 content_tag('p', form.text_field(
Toshi MARUYAMA
scm: bazaar: change i18n l() parameter in setting from string to symbol....
r5559 :url, :label => l(:field_path_to_repository),
Toshi MARUYAMA
scm: code clean up RepositoriesHelper....
r5268 :size => 60, :required => true,
:disabled => (repository && !repository.new_record?))) +
Toshi MARUYAMA
scm: use i18n string at commit log encoding setting (#1735)....
r5399 content_tag('p', form.select(
:log_encoding, [nil] + Setting::ENCODINGS,
Toshi MARUYAMA
scm: bazaar: change i18n l() parameter in setting from string to symbol....
r5559 :label => l(:field_commit_logs_encoding), :required => true))
Jean-Philippe Lang
Added Bazaar adapter....
r937 end
Toshi MARUYAMA
scm: code clean up repositories_helper.rb....
r4822
Jean-Philippe Lang
Adds Filesystem adapter (patch #1393 by Paul R)....
r1494 def filesystem_field_tags(form, repository)
Toshi MARUYAMA
scm: filesystem: use i18n string at 'Root directory' setting....
r5412 content_tag('p', form.text_field(
Toshi MARUYAMA
scm: filesystem: change i18n l() parameter in setting from string to symbol....
r5560 :url, :label => l(:field_root_directory),
Toshi MARUYAMA
scm: code clean up repositories_helper.rb....
r4822 :size => 60, :required => true,
Toshi MARUYAMA
scm: filesystem: fix mistake of respository select box on r4943 (#2274)....
r4824 :disabled => (repository && !repository.root_url.blank?))) +
Toshi MARUYAMA
scm: filesystem: add note "Default: UTF-8" in path encoding setting (#2274)....
r4868 content_tag('p', form.select(
Toshi MARUYAMA
scm: use i18n string at path encoding setting note (#2274, #2664, #3462, #5251)....
r5403 :path_encoding, [nil] + Setting::ENCODINGS,
Toshi MARUYAMA
scm: filesystem: change i18n l() parameter in setting from string to symbol....
r5560 :label => l(:field_scm_path_encoding)
Toshi MARUYAMA
scm: use i18n string at path encoding setting note (#2274, #2664, #3462, #5251)....
r5403 ) +
Toshi MARUYAMA
Rails3: helper: use html_safe for filesysytem scm setting...
r7431 '<br />'.html_safe + l(:text_scm_path_encoding_note))
Jean-Philippe Lang
Adds Filesystem adapter (patch #1393 by Paul R)....
r1494 end
Jean-Philippe Lang
svn browser merged in trunk...
r103 end