Mercurial > hg > soundsoftware-site
diff app/helpers/.svn/text-base/repositories_helper.rb.svn-base @ 523:0b6c82dead28 luisf
Merge from branch "cannam"
author | luisf <luis.figueira@eecs.qmul.ac.uk> |
---|---|
date | Mon, 25 Jul 2011 14:23:37 +0100 |
parents | 753f1380d6bc |
children |
line wrap: on
line diff
--- a/app/helpers/.svn/text-base/repositories_helper.rb.svn-base Mon Mar 28 18:17:06 2011 +0100 +++ b/app/helpers/.svn/text-base/repositories_helper.rb.svn-base Mon Jul 25 14:23:37 2011 +0100 @@ -1,33 +1,38 @@ -# redMine - project management software -# Copyright (C) 2006 Jean-Philippe Lang +# Redmine - project management software +# Copyright (C) 2006-2011 Jean-Philippe Lang # # 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. -# +# # 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. -# +# # 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. require 'iconv' +require 'redmine/codeset_util' module RepositoriesHelper - def format_revision(txt) - txt.to_s[0,8] + def format_revision(revision) + if revision.respond_to? :format_identifier + revision.format_identifier + else + revision.to_s + end end - + def truncate_at_line_break(text, length = 255) if text text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...') end end - + def render_properties(properties) unless properties.nil? || properties.empty? content = '' @@ -37,14 +42,15 @@ content_tag('ul', content, :class => 'properties') end end - + 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? - change.action = @changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C' + change.action = + @changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C' end change when 'D' @@ -52,8 +58,8 @@ else change end - end.compact - + end.compact + tree = { } changes.each do |change| p = tree @@ -68,13 +74,11 @@ end p[:c] = change end - render_changes_tree(tree[:s]) end - + def render_changes_tree(tree) return '' if tree.nil? - output = '' output << '<ul>' tree.keys.sort.each do |file| @@ -87,7 +91,7 @@ :action => 'show', :id => @project, :path => path_param, - :rev => @changeset.revision) + :rev => @changeset.identifier) output << "<li class='#{style}'>#{text}</li>" output << render_changes_tree(s) elsif c = tree[file][:c] @@ -97,13 +101,13 @@ :action => 'entry', :id => @project, :path => path_param, - :rev => @changeset.revision) unless c.action == 'D' + :rev => @changeset.identifier) unless c.action == 'D' text << " - #{c.revision}" unless c.revision.blank? text << ' (' + link_to('diff', :controller => 'repositories', :action => 'diff', :id => @project, :path => path_param, - :rev => @changeset.revision) + ') ' if c.action == 'M' + :rev => @changeset.identifier) + ') ' if c.action == 'M' text << ' ' + content_tag('span', c.from_path, :class => 'copied-from') unless c.from_path.blank? output << "<li class='#{style}'>#{text}</li>" end @@ -111,9 +115,26 @@ output << '</ul>' output end - + def to_utf8(str) + 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? + 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 + if str.respond_to?(:force_encoding) + str.force_encoding('UTF-8') + end @encodings ||= Setting.repositories_encodings.split(',').collect(&:strip) @encodings.each do |encoding| begin @@ -122,67 +143,142 @@ # do nothing here and try the next encoding end end - str + str = Redmine::CodesetUtil.replace_invalid_utf8(str) end - - def repository_field_tags(form, repository) + private :to_utf8_internal + + def repository_field_tags(form, repository) method = repository.class.name.demodulize.underscore + "_field_tags" - send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method) && method != 'repository_field_tags' + if repository.is_a?(Repository) && + respond_to?(method) && method != 'repository_field_tags' + send(method, form, repository) + end end - + def scm_select_tag(repository) scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']] Redmine::Scm::Base.all.each do |scm| - scm_options << ["Repository::#{scm}".constantize.scm_name, scm] if Setting.enabled_scm.include?(scm) || (repository && repository.class.name.demodulize == scm) + if Setting.enabled_scm.include?(scm) || + (repository && repository.class.name.demodulize == scm) + scm_options << ["Repository::#{scm}".constantize.scm_name, scm] + end end - - select_tag('repository_scm', + select_tag('repository_scm', options_for_select(scm_options, repository.class.name.demodulize), :disabled => (repository && !repository.new_record?), - :onchange => remote_function(:url => { :controller => 'repositories', :action => 'edit', :id => @project }, :method => :get, :with => "Form.serialize(this.form)") - ) + :onchange => remote_function( + :url => { + :controller => 'repositories', + :action => 'edit', + :id => @project + }, + :method => :get, + :with => "Form.serialize(this.form)") + ) end - + def with_leading_slash(path) path.to_s.starts_with?('/') ? path : "/#{path}" end - + def without_leading_slash(path) path.gsub(%r{^/+}, '') end def subversion_field_tags(form, repository) - content_tag('p', form.text_field(:url, :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)) + + content_tag('p', form.text_field(:url, :size => 60, :required => true, + :disabled => (repository && !repository.root_url.blank?)) + '<br />(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') + content_tag('p', form.text_field(:login, :size => 30)) + - 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]';")) + 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]';")) end def darcs_field_tags(form, repository) - content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?))) + content_tag('p', form.text_field( + :url, :label => l(:field_path_to_repository), + :size => 60, :required => true, + :disabled => (repository && !repository.new_record?))) + + content_tag('p', form.select( + :log_encoding, [nil] + Setting::ENCODINGS, + :label => l(:field_commit_logs_encoding), :required => true)) end - + def mercurial_field_tags(form, repository) - content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?))) + content_tag('p', form.text_field( + :url, :label => l(:field_path_to_repository), + :size => 60, :required => true, + :disabled => (repository && !repository.root_url.blank?) + ) + + '<br />' + l(:text_mercurial_repository_note)) + + content_tag('p', form.select( + :path_encoding, [nil] + Setting::ENCODINGS, + :label => l(:field_scm_path_encoding) + ) + + '<br />' + l(:text_scm_path_encoding_note)) end def git_field_tags(form, repository) - content_tag('p', form.text_field(:url, :label => 'Path to .git directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?))) + content_tag('p', form.text_field( + :url, :label => l(:field_path_to_repository), + :size => 60, :required => true, + :disabled => (repository && !repository.root_url.blank?) + ) + + '<br />' + l(:text_git_repository_note)) + + content_tag('p', form.select( + :path_encoding, [nil] + Setting::ENCODINGS, + :label => l(:field_scm_path_encoding) + ) + + '<br />' + l(:text_scm_path_encoding_note)) + + content_tag('p', form.check_box( + :extra_report_last_commit, + :label => l(:label_git_report_last_commit) + )) end def cvs_field_tags(form, repository) - content_tag('p', form.text_field(:root_url, :label => 'CVSROOT', :size => 60, :required => true, :disabled => !repository.new_record?)) + - content_tag('p', form.text_field(:url, :label => 'Module', :size => 30, :required => true, :disabled => !repository.new_record?)) + content_tag('p', form.text_field( + :root_url, + :label => l(:field_cvsroot), + :size => 60, :required => true, + :disabled => !repository.new_record?)) + + content_tag('p', form.text_field( + :url, + :label => l(:field_cvs_module), + :size => 30, :required => true, + :disabled => !repository.new_record?)) + + content_tag('p', form.select( + :log_encoding, [nil] + Setting::ENCODINGS, + :label => l(:field_commit_logs_encoding), :required => true)) + + content_tag('p', form.select( + :path_encoding, [nil] + Setting::ENCODINGS, + :label => l(:field_scm_path_encoding) + ) + + '<br />' + l(:text_scm_path_encoding_note)) end def bazaar_field_tags(form, repository) - content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?))) + content_tag('p', form.text_field( + :url, :label => l(:field_path_to_repository), + :size => 60, :required => true, + :disabled => (repository && !repository.new_record?))) + + content_tag('p', form.select( + :log_encoding, [nil] + Setting::ENCODINGS, + :label => l(:field_commit_logs_encoding), :required => true)) end - + def filesystem_field_tags(form, repository) - content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?))) + content_tag('p', form.text_field( + :url, :label => l(:field_root_directory), + :size => 60, :required => true, + :disabled => (repository && !repository.root_url.blank?))) + + content_tag('p', form.select( + :path_encoding, [nil] + Setting::ENCODINGS, + :label => l(:field_scm_path_encoding) + ) + + '<br />' + l(:text_scm_path_encoding_note)) end end