Commit 9ea27db155b1aac503c3a1cfabca422475378064
Exists in
master
and in
4 other branches
Merge pull request #3591 from hiroponz/show-only-selected-branch
Show only selected branch
Showing
10 changed files
with
87 additions
and
52 deletions
Show diff stats
app/controllers/graph_controller.rb
... | ... | @@ -8,21 +8,15 @@ class GraphController < ProjectResourceController |
8 | 8 | before_filter :require_non_empty_project |
9 | 9 | |
10 | 10 | def show |
11 | - if params.has_key?(:q) | |
12 | - if params[:q].blank? | |
13 | - redirect_to project_graph_path(@project, params[:id]) | |
14 | - return | |
15 | - end | |
16 | - | |
17 | - @q = params[:q] | |
18 | - @commit = @project.repository.commit(@q) || @commit | |
11 | + if @options[:q] | |
12 | + @commit = @project.repository.commit(@options[:q]) || @commit | |
19 | 13 | end |
20 | 14 | |
21 | 15 | respond_to do |format| |
22 | 16 | format.html |
23 | 17 | |
24 | 18 | format.json do |
25 | - @graph = Network::Graph.new(project, @ref, @commit) | |
19 | + @graph = Network::Graph.new(project, @ref, @commit, @options[:filter_ref]) | |
26 | 20 | end |
27 | 21 | end |
28 | 22 | end | ... | ... |
app/controllers/refs_controller.rb
1 | 1 | class RefsController < ProjectResourceController |
2 | + include ExtractsPath | |
2 | 3 | |
3 | 4 | # Authorize |
4 | 5 | before_filter :authorize_read_project! |
5 | 6 | before_filter :authorize_code_access! |
6 | 7 | before_filter :require_non_empty_project |
7 | 8 | |
8 | - before_filter :ref | |
9 | - before_filter :define_tree_vars, only: [:blob, :logs_tree] | |
10 | - | |
11 | 9 | def switch |
12 | 10 | respond_to do |format| |
13 | 11 | format.html do |
14 | 12 | new_path = if params[:destination] == "tree" |
15 | - project_tree_path(@project, (@ref + "/" + params[:path])) | |
13 | + project_tree_path(@project, (@id)) | |
16 | 14 | elsif params[:destination] == "blob" |
17 | - project_blob_path(@project, (@ref + "/" + params[:path])) | |
15 | + project_blob_path(@project, (@id)) | |
18 | 16 | elsif params[:destination] == "graph" |
19 | - project_graph_path(@project, @ref) | |
17 | + project_graph_path(@project, @id, @options) | |
20 | 18 | else |
21 | - project_commits_path(@project, @ref) | |
19 | + project_commits_path(@project, @id) | |
22 | 20 | end |
23 | 21 | |
24 | 22 | redirect_to new_path |
... | ... | @@ -42,27 +40,4 @@ class RefsController < ProjectResourceController |
42 | 40 | } |
43 | 41 | end |
44 | 42 | end |
45 | - | |
46 | - protected | |
47 | - | |
48 | - def define_tree_vars | |
49 | - params[:path] = nil if params[:path].blank? | |
50 | - | |
51 | - @repo = project.repository | |
52 | - @commit = @repo.commit(@ref) | |
53 | - @tree = Tree.new(@repo, @commit.id, @ref, params[:path]) | |
54 | - @hex_path = Digest::SHA1.hexdigest(params[:path] || "") | |
55 | - | |
56 | - if params[:path] | |
57 | - @logs_path = logs_file_project_ref_path(@project, @ref, params[:path]) | |
58 | - else | |
59 | - @logs_path = logs_tree_project_ref_path(@project, @ref) | |
60 | - end | |
61 | - rescue | |
62 | - return render_404 | |
63 | - end | |
64 | - | |
65 | - def ref | |
66 | - @ref = params[:id] || params[:ref] | |
67 | - end | |
68 | 43 | end | ... | ... |
app/controllers/tree_controller.rb
... | ... | @@ -8,9 +8,6 @@ class TreeController < ProjectResourceController |
8 | 8 | before_filter :require_non_empty_project |
9 | 9 | |
10 | 10 | def show |
11 | - @hex_path = Digest::SHA1.hexdigest(@path) | |
12 | - @logs_path = logs_file_project_ref_path(@project, @ref, @path) | |
13 | - | |
14 | 11 | respond_to do |format| |
15 | 12 | format.html |
16 | 13 | # Disable cache so browser history works | ... | ... |
app/models/network/graph.rb
... | ... | @@ -8,10 +8,11 @@ module Network |
8 | 8 | @max_count ||= 650 |
9 | 9 | end |
10 | 10 | |
11 | - def initialize project, ref, commit | |
11 | + def initialize project, ref, commit, filter_ref | |
12 | 12 | @project = project |
13 | 13 | @ref = ref |
14 | 14 | @commit = commit |
15 | + @filter_ref = filter_ref | |
15 | 16 | @repo = project.repo |
16 | 17 | |
17 | 18 | @commits = collect_commits |
... | ... | @@ -107,7 +108,9 @@ module Network |
107 | 108 | skip: skip |
108 | 109 | } |
109 | 110 | |
110 | - Grit::Commit.find_all(@repo, nil, opts) | |
111 | + ref = @ref if @filter_ref | |
112 | + | |
113 | + Grit::Commit.find_all(@repo, ref, opts) | |
111 | 114 | end |
112 | 115 | |
113 | 116 | def commits_sort_by_ref | ... | ... |
app/views/graph/_head.html.haml
... | ... | @@ -3,14 +3,24 @@ |
3 | 3 | |
4 | 4 | .clearfix |
5 | 5 | .pull-left |
6 | - = render partial: 'shared/ref_switcher', locals: {destination: 'graph', path: @path} | |
6 | + = render partial: 'shared/ref_switcher', locals: {destination: 'graph'} | |
7 | + .pull-left | |
8 | + = form_tag project_graph_path(@project, @id), method: :get do |f| | |
9 | + .control-group | |
10 | + = label_tag :filter_ref, "Show only selected ref", class: 'control-label light' | |
11 | + .controls | |
12 | + = check_box_tag :filter_ref, 1, @options[:filter_ref] | |
13 | + - @options.each do |key, value| | |
14 | + = hidden_field_tag(key, value, id: nil) unless key == "filter_ref" | |
7 | 15 | |
8 | 16 | .search.pull-right |
9 | - = form_tag project_graph_path(@project, params[:id]), method: :get do |f| | |
17 | + = form_tag project_graph_path(@project, @id), method: :get do |f| | |
10 | 18 | .control-group |
11 | 19 | = label_tag :search , "Looking for commit:", class: 'control-label light' |
12 | 20 | .controls |
13 | - = text_field_tag :q, @q, placeholder: "Input SHA", class: "search-input xlarge" | |
21 | + = text_field_tag :q, @options[:q], placeholder: "Input SHA", class: "search-input xlarge" | |
14 | 22 | = button_tag type: 'submit', class: 'btn vtop' do |
15 | 23 | %i.icon-search |
24 | + - @options.each do |key, value| | |
25 | + = hidden_field_tag(key, value, id: nil) unless key == "q" | |
16 | 26 | ... | ... |
app/views/graph/show.html.haml
... | ... | @@ -7,9 +7,11 @@ |
7 | 7 | |
8 | 8 | :javascript |
9 | 9 | var branch_graph; |
10 | - | |
10 | + $("#filter_ref").click(function() { | |
11 | + $(this).closest('form').submit(); | |
12 | + }); | |
11 | 13 | branch_graph = new BranchGraph($("#holder"), { |
12 | - url: '#{project_graph_path(@project, @ref, q: @q, format: :json)}', | |
14 | + url: '#{project_graph_path(@project, @ref, @options.merge(format: :json))}', | |
13 | 15 | commit_url: '#{project_commit_path(@project, 'ae45ca32').gsub("ae45ca32", "%s")}', |
14 | 16 | ref: '#{@ref}', |
15 | 17 | commit_id: '#{@commit.id}' | ... | ... |
app/views/shared/_ref_switcher.html.haml
features/project/network.feature
... | ... | @@ -25,3 +25,12 @@ Feature: Project Network Graph |
25 | 25 | Then page should have network graph |
26 | 26 | And page should select "master" in select box |
27 | 27 | And page should have "v2.1.0" on graph |
28 | + | |
29 | + @javascript | |
30 | + Scenario: I should filter selected tag | |
31 | + When I switch ref to "v2.1.0" | |
32 | + Then page should have content not cotaining "v2.1.0" | |
33 | + When click "Show only selected branch" checkbox | |
34 | + Then page should not have content not cotaining "v2.1.0" | |
35 | + When click "Show only selected branch" checkbox | |
36 | + Then page should have content not cotaining "v2.1.0" | ... | ... |
features/steps/project/project_network_graph.rb
... | ... | @@ -19,6 +19,10 @@ class ProjectNetworkGraph < Spinach::FeatureSteps |
19 | 19 | page.should have_selector '#ref_chzn span', text: "master" |
20 | 20 | end |
21 | 21 | |
22 | + And 'page should select "v2.1.0" in select box' do | |
23 | + page.should have_selector '#ref_chzn span', text: "v2.1.0" | |
24 | + end | |
25 | + | |
22 | 26 | And 'page should have "master" on graph' do |
23 | 27 | within '.graph' do |
24 | 28 | page.should have_content 'master' |
... | ... | @@ -35,6 +39,28 @@ class ProjectNetworkGraph < Spinach::FeatureSteps |
35 | 39 | sleep 2 |
36 | 40 | end |
37 | 41 | |
42 | + When 'I switch ref to "v2.1.0"' do | |
43 | + page.select 'v2.1.0', from: 'ref' | |
44 | + sleep 2 | |
45 | + end | |
46 | + | |
47 | + When 'click "Show only selected branch" checkbox' do | |
48 | + find('#filter_ref').click | |
49 | + sleep 2 | |
50 | + end | |
51 | + | |
52 | + Then 'page should have content not cotaining "v2.1.0"' do | |
53 | + within '.graph' do | |
54 | + page.should have_content 'cleaning' | |
55 | + end | |
56 | + end | |
57 | + | |
58 | + Then 'page should not have content not cotaining "v2.1.0"' do | |
59 | + within '.graph' do | |
60 | + page.should_not have_content 'cleaning' | |
61 | + end | |
62 | + end | |
63 | + | |
38 | 64 | And 'page should select "stable" in select box' do |
39 | 65 | page.should have_selector '#ref_chzn span', text: "stable" |
40 | 66 | end | ... | ... |
lib/extracts_path.rb
... | ... | @@ -94,16 +94,33 @@ module ExtractsPath |
94 | 94 | # Automatically renders `not_found!` if a valid tree path could not be |
95 | 95 | # resolved (e.g., when a user inserts an invalid path or ref). |
96 | 96 | def assign_ref_vars |
97 | - @id = params[:id] | |
97 | + @id = get_id | |
98 | 98 | |
99 | 99 | @ref, @path = extract_ref(@id) |
100 | 100 | |
101 | - @commit = @project.repository.commit(@ref) | |
101 | + @repo = @project.repository | |
102 | 102 | |
103 | - @tree = Tree.new(@project.repository, @commit.id, @ref, @path) | |
103 | + @commit = @repo.commit(@ref) | |
104 | + | |
105 | + @tree = Tree.new(@repo, @commit.id, @ref, @path) | |
106 | + @hex_path = Digest::SHA1.hexdigest(@path) | |
107 | + @logs_path = logs_file_project_ref_path(@project, @ref, @path) | |
108 | + | |
109 | + # assign allowed options | |
110 | + allowed_options = ["filter_ref", "q"] | |
111 | + @options = params.select {|key, value| allowed_options.include?(key) && !value.blank? } | |
112 | + @options = HashWithIndifferentAccess.new(@options) | |
104 | 113 | |
105 | 114 | raise InvalidPathError unless @tree.exists? |
106 | 115 | rescue RuntimeError, NoMethodError, InvalidPathError |
107 | 116 | not_found! |
108 | 117 | end |
118 | + | |
119 | + private | |
120 | + | |
121 | + def get_id | |
122 | + id = params[:id] || params[:ref] | |
123 | + id += "/" + params[:path] unless params[:path].blank? | |
124 | + id | |
125 | + end | |
109 | 126 | end | ... | ... |