Merge pull request #1902 from tsigo/breadcrumbs
Fix breadcrumb links on Commits page
This commit is contained in:
commit
f8e27b92bf
|
@ -17,23 +17,21 @@ $ ->
|
||||||
"ajax:beforeSend": -> $('.tree_progress').addClass("loading")
|
"ajax:beforeSend": -> $('.tree_progress').addClass("loading")
|
||||||
"ajax:complete": -> $('.tree_progress').removeClass("loading")
|
"ajax:complete": -> $('.tree_progress').removeClass("loading")
|
||||||
|
|
||||||
# Maintain forward/back history while browsing the file tree
|
# Maintain forward/back history while browsing the file tree
|
||||||
|
((window) ->
|
||||||
|
History = window.History
|
||||||
|
$ = window.jQuery
|
||||||
|
document = window.document
|
||||||
|
|
||||||
((window) ->
|
# Check to see if History.js is enabled for our Browser
|
||||||
History = window.History
|
unless History.enabled
|
||||||
$ = window.jQuery
|
return false
|
||||||
document = window.document
|
|
||||||
|
|
||||||
# Check to see if History.js is enabled for our Browser
|
$('#tree-slider .tree-item-file-name a, .breadcrumb li > a').live 'click', (e) ->
|
||||||
unless History.enabled
|
History.pushState(null, null, $(@).attr('href'))
|
||||||
return false
|
return false
|
||||||
|
|
||||||
$ ->
|
History.Adapter.bind window, 'statechange', ->
|
||||||
$('#tree-slider .tree-item-file-name a, .breadcrumb li > a').live 'click', (e) ->
|
state = History.getState()
|
||||||
History.pushState(null, null, $(@).attr('href'))
|
window.ajaxGet(state.url)
|
||||||
return false
|
)(window)
|
||||||
|
|
||||||
History.Adapter.bind window, 'statechange', ->
|
|
||||||
state = History.getState()
|
|
||||||
window.ajaxGet(state.url)
|
|
||||||
)(window)
|
|
||||||
|
|
|
@ -8,14 +8,14 @@ class TreeDecorator < ApplicationDecorator
|
||||||
|
|
||||||
#parts = parts[0...-1] if is_blob?
|
#parts = parts[0...-1] if is_blob?
|
||||||
|
|
||||||
yield(h.link_to("..", "#", remote: true)) if parts.count > max_links
|
yield(h.link_to("..", "#")) if parts.count > max_links
|
||||||
|
|
||||||
parts.each do |part|
|
parts.each do |part|
|
||||||
part_path = File.join(part_path, part) unless part_path.empty?
|
part_path = File.join(part_path, part) unless part_path.empty?
|
||||||
part_path = part if part_path.empty?
|
part_path = part if part_path.empty?
|
||||||
|
|
||||||
next unless parts.last(2).include?(part) if parts.count > max_links
|
next unless parts.last(2).include?(part) if parts.count > max_links
|
||||||
yield(h.link_to(h.truncate(part, length: 40), h.project_tree_path(project, h.tree_join(ref, part_path)), remote: true))
|
yield(h.link_to(h.truncate(part, length: 40), h.project_tree_path(project, h.tree_join(ref, part_path))))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -67,4 +67,29 @@ module TreeHelper
|
||||||
can?(current_user, :push_code, @project)
|
can?(current_user, :push_code, @project)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Breadcrumb links for a Project and, if applicable, a tree path
|
||||||
|
def breadcrumbs
|
||||||
|
return unless @project && @ref
|
||||||
|
|
||||||
|
# Add the root project link and the arrow icon
|
||||||
|
crumbs = content_tag(:li) do
|
||||||
|
content_tag(:span, nil, class: 'arrow') +
|
||||||
|
link_to(@project.name, project_commits_path(@project, @ref))
|
||||||
|
end
|
||||||
|
|
||||||
|
if @path
|
||||||
|
parts = @path.split('/')
|
||||||
|
|
||||||
|
parts.each_with_index do |part, i|
|
||||||
|
crumbs += content_tag(:span, '/', class: 'divider')
|
||||||
|
crumbs += content_tag(:li) do
|
||||||
|
# The text is just the individual part, but the link needs all the parts before it
|
||||||
|
link_to part, project_commits_path(@project, tree_join(@ref, parts[0..i].join('/')))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
crumbs.html_safe
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,14 +2,7 @@
|
||||||
|
|
||||||
- if @path.present?
|
- if @path.present?
|
||||||
%ul.breadcrumb
|
%ul.breadcrumb
|
||||||
%li
|
= breadcrumbs
|
||||||
%span.arrow
|
|
||||||
= link_to project_commits_path(@project) do
|
|
||||||
= @project.name
|
|
||||||
%span.divider
|
|
||||||
\/
|
|
||||||
%li
|
|
||||||
%a{href: "#"}= @path.split("/").join(" / ")
|
|
||||||
|
|
||||||
%div{id: dom_id(@project)}
|
%div{id: dom_id(@project)}
|
||||||
#commits_list= render "commits"
|
#commits_list= render "commits"
|
||||||
|
|
|
@ -19,3 +19,7 @@ Feature: Project Browse commits
|
||||||
Given I visit compare refs page
|
Given I visit compare refs page
|
||||||
And I fill compare fields with refs
|
And I fill compare fields with refs
|
||||||
Then I see compared refs
|
Then I see compared refs
|
||||||
|
|
||||||
|
Scenario: I browse commits for a specific path
|
||||||
|
Given I visit my project's commits page for a specific path
|
||||||
|
Then I see breadcrumb links
|
||||||
|
|
|
@ -42,4 +42,13 @@ class ProjectBrowseCommits < Spinach::FeatureSteps
|
||||||
page.should have_content "Commits (1)"
|
page.should have_content "Commits (1)"
|
||||||
page.should have_content "Showing 2 changed files"
|
page.should have_content "Showing 2 changed files"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Then 'I see breadcrumb links' do
|
||||||
|
page.should have_selector('ul.breadcrumb')
|
||||||
|
page.should have_selector('ul.breadcrumb span.divider', count: 3)
|
||||||
|
page.should have_selector('ul.breadcrumb a', count: 4)
|
||||||
|
|
||||||
|
find('ul.breadcrumb li:first a')['href'].should match(/#{@project.path}\/commits\/master\z/)
|
||||||
|
find('ul.breadcrumb li:last a')['href'].should match(%r{master/app/models/project\.rb\z})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -121,6 +121,10 @@ module SharedPaths
|
||||||
visit project_commits_path(@project, @project.root_ref, {limit: 5})
|
visit project_commits_path(@project, @project.root_ref, {limit: 5})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Given "I visit my project's commits page for a specific path" do
|
||||||
|
visit project_commits_path(@project, @project.root_ref + "/app/models/project.rb", {limit: 5})
|
||||||
|
end
|
||||||
|
|
||||||
Given "I visit my project's network page" do
|
Given "I visit my project's network page" do
|
||||||
# Stub GraphCommit max_size to speed up test (10 commits vs. 650)
|
# Stub GraphCommit max_size to speed up test (10 commits vs. 650)
|
||||||
Gitlab::GraphCommit.stub(max_count: 10)
|
Gitlab::GraphCommit.stub(max_count: 10)
|
||||||
|
|
Loading…
Reference in New Issue