Skip to content

Commit f8e27b9

Browse files
committed
Merge pull request gitlabhq#1902 from tsigo/breadcrumbs
Fix breadcrumb links on Commits page
2 parents b4be3c7 + e601856 commit f8e27b9

File tree

7 files changed

+63
-30
lines changed

7 files changed

+63
-30
lines changed

app/assets/javascripts/tree.js.coffee

+18-20
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,21 @@ $ ->
1717
"ajax:beforeSend": -> $('.tree_progress').addClass("loading")
1818
"ajax:complete": -> $('.tree_progress').removeClass("loading")
1919

20-
# Maintain forward/back history while browsing the file tree
21-
22-
((window) ->
23-
History = window.History
24-
$ = window.jQuery
25-
document = window.document
26-
27-
# Check to see if History.js is enabled for our Browser
28-
unless History.enabled
29-
return false
30-
31-
$ ->
32-
$('#tree-slider .tree-item-file-name a, .breadcrumb li > a').live 'click', (e) ->
33-
History.pushState(null, null, $(@).attr('href'))
34-
return false
35-
36-
History.Adapter.bind window, 'statechange', ->
37-
state = History.getState()
38-
window.ajaxGet(state.url)
39-
)(window)
20+
# Maintain forward/back history while browsing the file tree
21+
((window) ->
22+
History = window.History
23+
$ = window.jQuery
24+
document = window.document
25+
26+
# Check to see if History.js is enabled for our Browser
27+
unless History.enabled
28+
return false
29+
30+
$('#tree-slider .tree-item-file-name a, .breadcrumb li > a').live 'click', (e) ->
31+
History.pushState(null, null, $(@).attr('href'))
32+
return false
33+
34+
History.Adapter.bind window, 'statechange', ->
35+
state = History.getState()
36+
window.ajaxGet(state.url)
37+
)(window)

app/decorators/tree_decorator.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ def breadcrumbs(max_links = 2)
88

99
#parts = parts[0...-1] if is_blob?
1010

11-
yield(h.link_to("..", "#", remote: true)) if parts.count > max_links
11+
yield(h.link_to("..", "#")) if parts.count > max_links
1212

1313
parts.each do |part|
1414
part_path = File.join(part_path, part) unless part_path.empty?
1515
part_path = part if part_path.empty?
1616

1717
next unless parts.last(2).include?(part) if parts.count > max_links
18-
yield(h.link_to(h.truncate(part, length: 40), h.project_tree_path(project, h.tree_join(ref, part_path)), remote: true))
18+
yield(h.link_to(h.truncate(part, length: 40), h.project_tree_path(project, h.tree_join(ref, part_path))))
1919
end
2020
end
2121
end

app/helpers/tree_helper.rb

+25
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,29 @@ def allowed_tree_edit?
6767
can?(current_user, :push_code, @project)
6868
end
6969
end
70+
71+
# Breadcrumb links for a Project and, if applicable, a tree path
72+
def breadcrumbs
73+
return unless @project && @ref
74+
75+
# Add the root project link and the arrow icon
76+
crumbs = content_tag(:li) do
77+
content_tag(:span, nil, class: 'arrow') +
78+
link_to(@project.name, project_commits_path(@project, @ref))
79+
end
80+
81+
if @path
82+
parts = @path.split('/')
83+
84+
parts.each_with_index do |part, i|
85+
crumbs += content_tag(:span, '/', class: 'divider')
86+
crumbs += content_tag(:li) do
87+
# The text is just the individual part, but the link needs all the parts before it
88+
link_to part, project_commits_path(@project, tree_join(@ref, parts[0..i].join('/')))
89+
end
90+
end
91+
end
92+
93+
crumbs.html_safe
94+
end
7095
end

app/views/commits/show.html.haml

+1-8
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@
22

33
- if @path.present?
44
%ul.breadcrumb
5-
%li
6-
%span.arrow
7-
= link_to project_commits_path(@project) do
8-
= @project.name
9-
%span.divider
10-
\/
11-
%li
12-
%a{href: "#"}= @path.split("/").join(" / ")
5+
= breadcrumbs
136

147
%div{id: dom_id(@project)}
158
#commits_list= render "commits"

features/project/commits/commits.feature

+4
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ Feature: Project Browse commits
1919
Given I visit compare refs page
2020
And I fill compare fields with refs
2121
Then I see compared refs
22+
23+
Scenario: I browse commits for a specific path
24+
Given I visit my project's commits page for a specific path
25+
Then I see breadcrumb links

features/steps/project/project_browse_commits.rb

+9
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,13 @@ class ProjectBrowseCommits < Spinach::FeatureSteps
4242
page.should have_content "Commits (1)"
4343
page.should have_content "Showing 2 changed files"
4444
end
45+
46+
Then 'I see breadcrumb links' do
47+
page.should have_selector('ul.breadcrumb')
48+
page.should have_selector('ul.breadcrumb span.divider', count: 3)
49+
page.should have_selector('ul.breadcrumb a', count: 4)
50+
51+
find('ul.breadcrumb li:first a')['href'].should match(/#{@project.path}\/commits\/master\z/)
52+
find('ul.breadcrumb li:last a')['href'].should match(%r{master/app/models/project\.rb\z})
53+
end
4554
end

features/steps/shared/paths.rb

+4
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ module SharedPaths
121121
visit project_commits_path(@project, @project.root_ref, {limit: 5})
122122
end
123123

124+
Given "I visit my project's commits page for a specific path" do
125+
visit project_commits_path(@project, @project.root_ref + "/app/models/project.rb", {limit: 5})
126+
end
127+
124128
Given "I visit my project's network page" do
125129
# Stub GraphCommit max_size to speed up test (10 commits vs. 650)
126130
Gitlab::GraphCommit.stub(max_count: 10)

0 commit comments

Comments
 (0)