Commit 9ea27db1 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge pull request #3591 from hiroponz/show-only-selected-branch

Show only selected branch
parents 58d6176b 1738055d
......@@ -8,21 +8,15 @@ class GraphController < ProjectResourceController
before_filter :require_non_empty_project
def show
if params.has_key?(:q)
if params[:q].blank?
redirect_to project_graph_path(@project, params[:id])
return
end
@q = params[:q]
@commit = @project.repository.commit(@q) || @commit
if @options[:q]
@commit = @project.repository.commit(@options[:q]) || @commit
end
respond_to do |format|
format.html
format.json do
@graph = Network::Graph.new(project, @ref, @commit)
@graph = Network::Graph.new(project, @ref, @commit, @options[:filter_ref])
end
end
end
......
class RefsController < ProjectResourceController
include ExtractsPath
# Authorize
before_filter :authorize_read_project!
before_filter :authorize_code_access!
before_filter :require_non_empty_project
before_filter :ref
before_filter :define_tree_vars, only: [:blob, :logs_tree]
def switch
respond_to do |format|
format.html do
new_path = if params[:destination] == "tree"
project_tree_path(@project, (@ref + "/" + params[:path]))
project_tree_path(@project, (@id))
elsif params[:destination] == "blob"
project_blob_path(@project, (@ref + "/" + params[:path]))
project_blob_path(@project, (@id))
elsif params[:destination] == "graph"
project_graph_path(@project, @ref)
project_graph_path(@project, @id, @options)
else
project_commits_path(@project, @ref)
project_commits_path(@project, @id)
end
redirect_to new_path
......@@ -42,27 +40,4 @@ class RefsController < ProjectResourceController
}
end
end
protected
def define_tree_vars
params[:path] = nil if params[:path].blank?
@repo = project.repository
@commit = @repo.commit(@ref)
@tree = Tree.new(@repo, @commit.id, @ref, params[:path])
@hex_path = Digest::SHA1.hexdigest(params[:path] || "")
if params[:path]
@logs_path = logs_file_project_ref_path(@project, @ref, params[:path])
else
@logs_path = logs_tree_project_ref_path(@project, @ref)
end
rescue
return render_404
end
def ref
@ref = params[:id] || params[:ref]
end
end
......@@ -8,9 +8,6 @@ class TreeController < ProjectResourceController
before_filter :require_non_empty_project
def show
@hex_path = Digest::SHA1.hexdigest(@path)
@logs_path = logs_file_project_ref_path(@project, @ref, @path)
respond_to do |format|
format.html
# Disable cache so browser history works
......
......@@ -8,10 +8,11 @@ module Network
@max_count ||= 650
end
def initialize project, ref, commit
def initialize project, ref, commit, filter_ref
@project = project
@ref = ref
@commit = commit
@filter_ref = filter_ref
@repo = project.repo
@commits = collect_commits
......@@ -107,7 +108,9 @@ module Network
skip: skip
}
Grit::Commit.find_all(@repo, nil, opts)
ref = @ref if @filter_ref
Grit::Commit.find_all(@repo, ref, opts)
end
def commits_sort_by_ref
......
......@@ -3,14 +3,24 @@
.clearfix
.pull-left
= render partial: 'shared/ref_switcher', locals: {destination: 'graph', path: @path}
= render partial: 'shared/ref_switcher', locals: {destination: 'graph'}
.pull-left
= form_tag project_graph_path(@project, @id), method: :get do |f|
.control-group
= label_tag :filter_ref, "Show only selected ref", class: 'control-label light'
.controls
= check_box_tag :filter_ref, 1, @options[:filter_ref]
- @options.each do |key, value|
= hidden_field_tag(key, value, id: nil) unless key == "filter_ref"
.search.pull-right
= form_tag project_graph_path(@project, params[:id]), method: :get do |f|
= form_tag project_graph_path(@project, @id), method: :get do |f|
.control-group
= label_tag :search , "Looking for commit:", class: 'control-label light'
.controls
= text_field_tag :q, @q, placeholder: "Input SHA", class: "search-input xlarge"
= text_field_tag :q, @options[:q], placeholder: "Input SHA", class: "search-input xlarge"
= button_tag type: 'submit', class: 'btn vtop' do
%i.icon-search
- @options.each do |key, value|
= hidden_field_tag(key, value, id: nil) unless key == "q"
......@@ -7,9 +7,11 @@
:javascript
var branch_graph;
$("#filter_ref").click(function() {
$(this).closest('form').submit();
});
branch_graph = new BranchGraph($("#holder"), {
url: '#{project_graph_path(@project, @ref, q: @q, format: :json)}',
url: '#{project_graph_path(@project, @ref, @options.merge(format: :json))}',
commit_url: '#{project_commit_path(@project, 'ae45ca32').gsub("ae45ca32", "%s")}',
ref: '#{@ref}',
commit_id: '#{@commit.id}'
......
......@@ -3,3 +3,5 @@
= hidden_field_tag :destination, destination
- if defined?(path)
= hidden_field_tag :path, path
- @options && @options.each do |key, value|
= hidden_field_tag key, value, id: nil
......@@ -25,3 +25,12 @@ Feature: Project Network Graph
Then page should have network graph
And page should select "master" in select box
And page should have "v2.1.0" on graph
@javascript
Scenario: I should filter selected tag
When I switch ref to "v2.1.0"
Then page should have content not cotaining "v2.1.0"
When click "Show only selected branch" checkbox
Then page should not have content not cotaining "v2.1.0"
When click "Show only selected branch" checkbox
Then page should have content not cotaining "v2.1.0"
......@@ -19,6 +19,10 @@ class ProjectNetworkGraph < Spinach::FeatureSteps
page.should have_selector '#ref_chzn span', text: "master"
end
And 'page should select "v2.1.0" in select box' do
page.should have_selector '#ref_chzn span', text: "v2.1.0"
end
And 'page should have "master" on graph' do
within '.graph' do
page.should have_content 'master'
......@@ -35,6 +39,28 @@ class ProjectNetworkGraph < Spinach::FeatureSteps
sleep 2
end
When 'I switch ref to "v2.1.0"' do
page.select 'v2.1.0', from: 'ref'
sleep 2
end
When 'click "Show only selected branch" checkbox' do
find('#filter_ref').click
sleep 2
end
Then 'page should have content not cotaining "v2.1.0"' do
within '.graph' do
page.should have_content 'cleaning'
end
end
Then 'page should not have content not cotaining "v2.1.0"' do
within '.graph' do
page.should_not have_content 'cleaning'
end
end
And 'page should select "stable" in select box' do
page.should have_selector '#ref_chzn span', text: "stable"
end
......
......@@ -94,16 +94,33 @@ module ExtractsPath
# Automatically renders `not_found!` if a valid tree path could not be
# resolved (e.g., when a user inserts an invalid path or ref).
def assign_ref_vars
@id = params[:id]
@id = get_id
@ref, @path = extract_ref(@id)
@commit = @project.repository.commit(@ref)
@repo = @project.repository
@tree = Tree.new(@project.repository, @commit.id, @ref, @path)
@commit = @repo.commit(@ref)
@tree = Tree.new(@repo, @commit.id, @ref, @path)
@hex_path = Digest::SHA1.hexdigest(@path)
@logs_path = logs_file_project_ref_path(@project, @ref, @path)
# assign allowed options
allowed_options = ["filter_ref", "q"]
@options = params.select {|key, value| allowed_options.include?(key) && !value.blank? }
@options = HashWithIndifferentAccess.new(@options)
raise InvalidPathError unless @tree.exists?
rescue RuntimeError, NoMethodError, InvalidPathError
not_found!
end
private
def get_id
id = params[:id] || params[:ref]
id += "/" + params[:path] unless params[:path].blank?
id
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment