Feature #37996 ยป repository_sidebar_with_config_and_hooks.patch
app/helpers/application_helper.rb | ||
---|---|---|
141 | 141 |
link_to text, url, html_options |
142 | 142 |
end |
143 | 143 | |
144 |
def link_to_repository_buttons(repo, project) |
|
145 |
if User.current.allowed_to? :manage_repository, project |
|
146 |
link_to "(#{l :label_settings})", |
|
147 |
edit_repository_path(repo), |
|
148 |
title: l(:label_settings), |
|
149 |
class: 'icon-only icon-settings' |
|
150 |
end |
|
151 |
end |
|
152 | ||
153 |
def link_to_repository(repo, **options) |
|
154 |
name = options.delete(:name).presence || repo.name |
|
155 |
current_repo = options.delete :current_repo |
|
156 | ||
157 |
css_class = ['repository', repo.scm_name.downcase] |
|
158 |
css_class << 'selected' if current_repo && repo == current_repo |
|
159 | ||
160 |
link_to name, |
|
161 |
{ controller: 'repositories', |
|
162 |
action: 'show', |
|
163 |
id: repo.project, |
|
164 |
repository_id: repo.identifier_param, |
|
165 |
rev: nil, |
|
166 |
path: nil }.merge(options), |
|
167 |
class: css_class.join(' ') |
|
168 |
end |
|
169 | ||
144 | 170 |
# Generates a link to a SCM revision |
145 | 171 |
# Options: |
146 | 172 |
# * :text - Link text (default to the formatted revision) |
app/views/projects/settings/_repositories.html.erb | ||
---|---|---|
18 | 18 |
<% @project.repositories.sort.each do |repository| %> |
19 | 19 |
<tr> |
20 | 20 |
<td class="name"> |
21 |
<%= link_to repository.identifier, |
|
22 |
{:controller => 'repositories', :action => 'show',:id => @project, :repository_id => repository.identifier_param} if repository.identifier.present? %> |
|
21 |
<%= link_to_repository(repository) if repository.identifier.present? %> |
|
23 | 22 |
</td> |
24 | 23 |
<td><%= checked_image repository.is_default? %></td> |
25 | 24 |
<td><%= repository.scm_name %></td> |
app/views/repositories/_sidebar.html.erb | ||
---|---|---|
1 |
<%= call_hook :view_repositories_sidebar_top, project: @project, repository: @repository %> |
|
2 | ||
3 |
<% if @repositories.size > 1 %> |
|
4 |
<h3><%= l(:label_repository_plural) %></h3> |
|
5 |
<ul class="repositories"> |
|
6 |
<% @repositories.sort.map do |repo| %> |
|
7 |
<li> |
|
8 |
<%= link_to_repository repo, current_repo: @repository %> |
|
9 |
<%= link_to_repository_buttons repo, @project %> |
|
10 |
</li> |
|
11 |
<% end %> |
|
12 |
</ul> |
|
13 |
<% end %> |
|
14 | ||
15 |
<%= call_hook :view_repositories_sidebar_bottom, project: @project, repository: @repository %> |
app/views/repositories/show.html.erb | ||
---|---|---|
57 | 57 |
<% end %> |
58 | 58 |
<% end %> |
59 | 59 | |
60 |
<% if @repositories.size > 1 %> |
|
61 |
<% content_for :sidebar do %> |
|
62 |
<h3><%= l(:label_repository_plural) %></h3> |
|
63 |
<p> |
|
64 |
<%= @repositories.sort.collect {|repo| |
|
65 |
link_to repo.name, |
|
66 |
{:controller => 'repositories', :action => 'show', |
|
67 |
:id => @project, :repository_id => repo.identifier_param, :rev => nil, :path => nil}, |
|
68 |
:class => 'repository' + (repo == @repository ? ' selected' : '') |
|
69 |
}.join('<br />').html_safe %> |
|
70 |
</p> |
|
71 |
<% end %> |
|
60 |
<% content_for :sidebar do %> |
|
61 |
<%= render :partial => 'repositories/sidebar' %> |
|
72 | 62 |
<% end %> |
73 | 63 | |
74 | 64 |
<% content_for :header_tags do %> |
test/helpers/application_helper_test.rb | ||
---|---|---|
2211 | 2211 |
end |
2212 | 2212 |
end |
2213 | 2213 | |
2214 |
def test_link_to_repository |
|
2215 |
repo = Repository.find(11) |
|
2216 |
assert_equal '<a class="repository subversion" href="/projects/onlinestore/repository/11">Main repository</a>', |
|
2217 |
link_to_repository(repo) |
|
2218 |
end |
|
2219 | ||
2220 |
def test_link_to_repository_with_identifier |
|
2221 |
repo = Repository.new identifier: 'foo', project: Project.find(2) |
|
2222 |
assert_equal '<a class="repository abstract" href="/projects/onlinestore/repository/foo">foo</a>', |
|
2223 |
link_to_repository(repo) |
|
2224 |
end |
|
2225 | ||
2226 |
def test_link_to_repository_with_custom_name |
|
2227 |
repo = Repository.find(11) |
|
2228 |
assert_equal '<a class="repository subversion" href="/projects/onlinestore/repository/11">showme</a>', |
|
2229 |
link_to_repository(repo, name: 'showme') |
|
2230 |
end |
|
2231 | ||
2232 |
def test_link_to_repository_with_select |
|
2233 |
repo = Repository.find(11) |
|
2234 |
assert_equal '<a class="repository subversion selected" href="/projects/onlinestore/repository/11">Main repository</a>', |
|
2235 |
link_to_repository(repo, current_repo: repo) |
|
2236 |
end |
|
2237 | ||
2214 | 2238 |
private |
2215 | 2239 | |
2216 | 2240 |
def wiki_links_with_special_characters |