Module: RepositoriesHelper
- Defined in:
- app/helpers/repositories_helper.rb
Overview
Redmine - project management software Copyright (C) 2006-2016 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.
Instance Method Summary collapse
- #bazaar_field_tags(form, repository) ⇒ Object
- #cvs_field_tags(form, repository) ⇒ Object
- #darcs_field_tags(form, repository) ⇒ Object
- #filesystem_field_tags(form, repository) ⇒ Object
- #format_revision(revision) ⇒ Object
- #git_field_tags(form, repository) ⇒ Object
- #index_commits(commits, heads) ⇒ Object
- #index_head(space, commit, commits_by_scmid) ⇒ Object
- #mercurial_field_tags(form, repository) ⇒ Object
- #render_changes_tree(tree) ⇒ Object
- #render_changeset_changes ⇒ Object
- #render_properties(properties) ⇒ Object
- #repository_field_tags(form, repository) ⇒ Object
- #scm_log_encoding_tag(form, repository) ⇒ Object
- #scm_path_encoding_tag(form, repository) ⇒ Object
- #scm_path_info(repository) ⇒ Object
- #scm_path_info_tag(repository) ⇒ Object
- #scm_select_tag(repository) ⇒ Object
- #subversion_field_tags(form, repository) ⇒ Object
- #truncate_at_line_break(text, length = 255) ⇒ Object
- #with_leading_slash(path) ⇒ Object
Instance Method Details
#bazaar_field_tags(form, repository) ⇒ Object
209 210 211 212 213 214 215 216 |
# File 'app/helpers/repositories_helper.rb', line 209 def (form, repository) content_tag('p', form.text_field( :url, :label => l(:field_path_to_repository), :size => 60, :required => true, :disabled => !repository.safe_attribute?('url')) + scm_path_info_tag(repository)) + scm_log_encoding_tag(form, repository) end |
#cvs_field_tags(form, repository) ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'app/helpers/repositories_helper.rb', line 193 def (form, repository) content_tag('p', form.text_field( :root_url, :label => l(:field_cvsroot), :size => 60, :required => true, :disabled => !repository.safe_attribute?('root_url')) + scm_path_info_tag(repository)) + content_tag('p', form.text_field( :url, :label => l(:field_cvs_module), :size => 30, :required => true, :disabled => !repository.safe_attribute?('url'))) + scm_log_encoding_tag(form, repository) + scm_path_encoding_tag(form, repository) end |
#darcs_field_tags(form, repository) ⇒ Object
160 161 162 163 164 165 166 167 |
# File 'app/helpers/repositories_helper.rb', line 160 def (form, repository) content_tag('p', form.text_field( :url, :label => l(:field_path_to_repository), :size => 60, :required => true, :disabled => !repository.safe_attribute?('url')) + scm_path_info_tag(repository)) + scm_log_encoding_tag(form, repository) end |
#filesystem_field_tags(form, repository) ⇒ Object
218 219 220 221 222 223 224 225 |
# File 'app/helpers/repositories_helper.rb', line 218 def (form, repository) content_tag('p', form.text_field( :url, :label => l(:field_root_directory), :size => 60, :required => true, :disabled => !repository.safe_attribute?('url')) + scm_path_info_tag(repository)) + scm_path_encoding_tag(form, repository) end |
#format_revision(revision) ⇒ Object
21 22 23 24 25 26 27 |
# File 'app/helpers/repositories_helper.rb', line 21 def format_revision(revision) if revision.respond_to? :format_identifier revision.format_identifier else revision.to_s end end |
#git_field_tags(form, repository) ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'app/helpers/repositories_helper.rb', line 179 def (form, repository) content_tag('p', form.text_field( :url, :label => l(:field_path_to_repository), :size => 60, :required => true, :disabled => !repository.safe_attribute?('url') ) + scm_path_info_tag(repository)) + scm_path_encoding_tag(form, repository) + content_tag('p', form.check_box( :report_last_commit, :label => l(:label_git_report_last_commit) )) end |
#index_commits(commits, heads) ⇒ Object
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'app/helpers/repositories_helper.rb', line 264 def index_commits(commits, heads) return nil if commits.nil? or commits.first.parents.nil? refs_map = {} heads.each do |head| refs_map[head.scmid] ||= [] refs_map[head.scmid] << head end commits_by_scmid = {} commits.reverse.each_with_index do |commit, commit_index| commits_by_scmid[commit.scmid] = { :parent_scmids => commit.parents.collect { |parent| parent.scmid }, :rdmid => commit_index, :refs => refs_map.include?(commit.scmid) ? refs_map[commit.scmid].join(" ") : nil, :scmid => commit.scmid, :href => block_given? ? yield(commit.scmid) : commit.scmid } end heads.sort! { |head1, head2| head1.to_s <=> head2.to_s } space = nil heads.each do |head| if commits_by_scmid.include? head.scmid space = index_head((space || -1) + 1, head, commits_by_scmid) end end # when no head matched anything use first commit space ||= index_head(0, commits.first, commits_by_scmid) return commits_by_scmid, space end |
#index_head(space, commit, commits_by_scmid) ⇒ Object
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'app/helpers/repositories_helper.rb', line 293 def index_head(space, commit, commits_by_scmid) stack = [[space, commits_by_scmid[commit.scmid]]] max_space = space until stack.empty? space, commit = stack.pop commit[:space] = space if commit[:space].nil? space -= 1 commit[:parent_scmids].each_with_index do |parent_scmid, parent_index| parent_commit = commits_by_scmid[parent_scmid] if parent_commit and parent_commit[:space].nil? stack.unshift [space += 1, parent_commit] end end max_space = space if max_space < space end max_space end |
#mercurial_field_tags(form, repository) ⇒ Object
169 170 171 172 173 174 175 176 177 |
# File 'app/helpers/repositories_helper.rb', line 169 def (form, repository) content_tag('p', form.text_field( :url, :label => l(:field_path_to_repository), :size => 60, :required => true, :disabled => !repository.safe_attribute?('url') ) + scm_path_info_tag(repository)) + scm_path_encoding_tag(form, repository) end |
#render_changes_tree(tree) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'app/helpers/repositories_helper.rb', line 79 def render_changes_tree(tree) return '' if tree.nil? output = '' output << '<ul>' tree.keys.sort.each do |file| style = 'change' text = File.basename(h(file)) if s = tree[file][:s] style << ' folder' path_param = to_path_param(@repository.relative_path(file)) text = link_to(h(text), :controller => 'repositories', :action => 'show', :id => @project, :repository_id => @repository.identifier_param, :path => path_param, :rev => @changeset.identifier) output << "<li class='#{style}'>#{text}" output << render_changes_tree(s) output << "</li>" elsif c = tree[file][:c] style << " change-#{c.action}" path_param = to_path_param(@repository.relative_path(c.path)) text = link_to(h(text), :controller => 'repositories', :action => 'entry', :id => @project, :repository_id => @repository.identifier_param, :path => path_param, :rev => @changeset.identifier) unless c.action == 'D' text << " - #{h(c.revision)}" unless c.revision.blank? text << ' ('.html_safe + link_to(l(:label_diff), :controller => 'repositories', :action => 'diff', :id => @project, :repository_id => @repository.identifier_param, :path => path_param, :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? output << "<li class='#{style}'>#{text}</li>" end end output << '</ul>' output.html_safe end |
#render_changeset_changes ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/helpers/repositories_helper.rb', line 45 def render_changeset_changes changes = @changeset.filechanges.limit(1000).reorder('path').collect do |change| case change.action when 'A' # Detects moved/copied files if !change.from_path.blank? change.action = @changeset.filechanges.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C' end change when 'D' @changeset.filechanges.detect {|c| c.from_path == change.path} ? nil : change else change end end.compact tree = { } changes.each do |change| p = tree dirs = change.path.to_s.split('/').select {|d| !d.blank?} path = '' dirs.each do |dir| path += '/' + dir p[:s] ||= {} p = p[:s] p[path] ||= {} p = p[path] end p[:c] = change end render_changes_tree(tree[:s]) end |
#render_properties(properties) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'app/helpers/repositories_helper.rb', line 35 def render_properties(properties) unless properties.nil? || properties.empty? content = '' properties.keys.sort.each do |property| content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>".html_safe) end content_tag('ul', content.html_safe, :class => 'properties') end end |
#repository_field_tags(form, repository) ⇒ Object
122 123 124 125 126 127 128 |
# File 'app/helpers/repositories_helper.rb', line 122 def (form, repository) method = repository.class.name.demodulize.underscore + "_field_tags" if repository.is_a?(Repository) && respond_to?(method) && method != 'repository_field_tags' send(method, form, repository) end end |
#scm_log_encoding_tag(form, repository) ⇒ Object
245 246 247 248 249 250 251 252 253 |
# File 'app/helpers/repositories_helper.rb', line 245 def scm_log_encoding_tag(form, repository) select = form.select( :log_encoding, [nil] + Setting::ENCODINGS, :label => l(:field_commit_logs_encoding), :required => true ) content_tag('p', select) end |
#scm_path_encoding_tag(form, repository) ⇒ Object
255 256 257 258 259 260 261 262 |
# File 'app/helpers/repositories_helper.rb', line 255 def scm_path_encoding_tag(form, repository) select = form.select( :path_encoding, [nil] + Setting::ENCODINGS, :label => l(:field_scm_path_encoding) ) content_tag('p', select + content_tag('em', l(:text_scm_path_encoding_note), :class => 'info')) end |
#scm_path_info(repository) ⇒ Object
236 237 238 239 240 241 242 243 |
# File 'app/helpers/repositories_helper.rb', line 236 def scm_path_info(repository) scm_name = repository.scm_name.to_s.downcase info_from_config = Redmine::Configuration["scm_#{scm_name}_path_info"].presence return info_from_config.html_safe if info_from_config l("text_#{scm_name}_repository_note", :default => '') end |
#scm_path_info_tag(repository) ⇒ Object
227 228 229 230 231 232 233 234 |
# File 'app/helpers/repositories_helper.rb', line 227 def scm_path_info_tag(repository) text = scm_path_info(repository) if text.present? content_tag('em', text, :class => 'info') else '' end end |
#scm_select_tag(repository) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'app/helpers/repositories_helper.rb', line 130 def scm_select_tag(repository) = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']] Redmine::Scm::Base.all.each do |scm| if Setting.enabled_scm.include?(scm) || (repository && repository.class.name.demodulize == scm) << ["Repository::#{scm}".constantize.scm_name, scm] end end select_tag('repository_scm', (, repository.class.name.demodulize), :disabled => (repository && !repository.new_record?), :data => {:remote => true, :method => 'get'}) end |
#subversion_field_tags(form, repository) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 |
# File 'app/helpers/repositories_helper.rb', line 148 def (form, repository) content_tag('p', form.text_field(:url, :size => 60, :required => true, :disabled => !repository.safe_attribute?('url')) + scm_path_info_tag(repository)) + 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]';")) end |
#truncate_at_line_break(text, length = 255) ⇒ Object
29 30 31 32 33 |
# File 'app/helpers/repositories_helper.rb', line 29 def truncate_at_line_break(text, length = 255) if text text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...') end end |
#with_leading_slash(path) ⇒ Object
144 145 146 |
# File 'app/helpers/repositories_helper.rb', line 144 def with_leading_slash(path) path.to_s.starts_with?('/') ? path : "/#{path}" end |