summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-05-13 04:31:27 -0700
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-05-13 04:31:27 -0700
commit9ea27db155b1aac503c3a1cfabca422475378064 (patch)
tree7eb6569bb1a04e3d1a2e2be8276ce11be5718285
parent58d6176bc35fb45427df75b9762df6bb0d3b3a98 (diff)
parent1738055dabb902b45d07839bec053bfc59fd05ee (diff)
downloadgitlab-ce-9ea27db155b1aac503c3a1cfabca422475378064.tar.gz
Merge pull request #3591 from hiroponz/show-only-selected-branch
Show only selected branch
-rw-r--r--app/controllers/graph_controller.rb12
-rw-r--r--app/controllers/refs_controller.rb35
-rw-r--r--app/controllers/tree_controller.rb3
-rw-r--r--app/models/network/graph.rb7
-rw-r--r--app/views/graph/_head.html.haml16
-rw-r--r--app/views/graph/show.html.haml6
-rw-r--r--app/views/shared/_ref_switcher.html.haml2
-rw-r--r--features/project/network.feature9
-rw-r--r--features/steps/project/project_network_graph.rb26
-rw-r--r--lib/extracts_path.rb23
10 files changed, 87 insertions, 52 deletions
diff --git a/app/controllers/graph_controller.rb b/app/controllers/graph_controller.rb
index b4bf9565112..c79ed5ca3cc 100644
--- a/app/controllers/graph_controller.rb
+++ b/app/controllers/graph_controller.rb
@@ -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
diff --git a/app/controllers/refs_controller.rb b/app/controllers/refs_controller.rb
index 188feb73ec1..e7def3984f8 100644
--- a/app/controllers/refs_controller.rb
+++ b/app/controllers/refs_controller.rb
@@ -1,24 +1,22 @@
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
diff --git a/app/controllers/tree_controller.rb b/app/controllers/tree_controller.rb
index a03ea3ff30d..24e1329f926 100644
--- a/app/controllers/tree_controller.rb
+++ b/app/controllers/tree_controller.rb
@@ -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
diff --git a/app/models/network/graph.rb b/app/models/network/graph.rb
index 27072836cbb..ffec4712e45 100644
--- a/app/models/network/graph.rb
+++ b/app/models/network/graph.rb
@@ -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
diff --git a/app/views/graph/_head.html.haml b/app/views/graph/_head.html.haml
index fba9a958a19..7a5b3c6f43d 100644
--- a/app/views/graph/_head.html.haml
+++ b/app/views/graph/_head.html.haml
@@ -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"
diff --git a/app/views/graph/show.html.haml b/app/views/graph/show.html.haml
index 682d2798906..0ee6648317c 100644
--- a/app/views/graph/show.html.haml
+++ b/app/views/graph/show.html.haml
@@ -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}'
diff --git a/app/views/shared/_ref_switcher.html.haml b/app/views/shared/_ref_switcher.html.haml
index 8b44cf1944e..dc8c656e12e 100644
--- a/app/views/shared/_ref_switcher.html.haml
+++ b/app/views/shared/_ref_switcher.html.haml
@@ -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
diff --git a/features/project/network.feature b/features/project/network.feature
index 538124a4c5f..f98e19b60d3 100644
--- a/features/project/network.feature
+++ b/features/project/network.feature
@@ -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"
diff --git a/features/steps/project/project_network_graph.rb b/features/steps/project/project_network_graph.rb
index 8db6a39e99f..48a73f09fac 100644
--- a/features/steps/project/project_network_graph.rb
+++ b/features/steps/project/project_network_graph.rb
@@ -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
diff --git a/lib/extracts_path.rb b/lib/extracts_path.rb
index 1b7c698d0a8..a81c80cfc6f 100644
--- a/lib/extracts_path.rb
+++ b/lib/extracts_path.rb
@@ -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