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,21 +8,15 @@ class GraphController < ProjectResourceController | ||
| 8 | before_filter :require_non_empty_project | 8 | before_filter :require_non_empty_project |
| 9 | 9 | ||
| 10 | def show | 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 | end | 13 | end |
| 20 | 14 | ||
| 21 | respond_to do |format| | 15 | respond_to do |format| |
| 22 | format.html | 16 | format.html |
| 23 | 17 | ||
| 24 | format.json do | 18 | format.json do |
| 25 | - @graph = Network::Graph.new(project, @ref, @commit) | 19 | + @graph = Network::Graph.new(project, @ref, @commit, @options[:filter_ref]) |
| 26 | end | 20 | end |
| 27 | end | 21 | end |
| 28 | end | 22 | end |
app/controllers/refs_controller.rb
| 1 | class RefsController < ProjectResourceController | 1 | class RefsController < ProjectResourceController |
| 2 | + include ExtractsPath | ||
| 2 | 3 | ||
| 3 | # Authorize | 4 | # Authorize |
| 4 | before_filter :authorize_read_project! | 5 | before_filter :authorize_read_project! |
| 5 | before_filter :authorize_code_access! | 6 | before_filter :authorize_code_access! |
| 6 | before_filter :require_non_empty_project | 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 | def switch | 9 | def switch |
| 12 | respond_to do |format| | 10 | respond_to do |format| |
| 13 | format.html do | 11 | format.html do |
| 14 | new_path = if params[:destination] == "tree" | 12 | new_path = if params[:destination] == "tree" |
| 15 | - project_tree_path(@project, (@ref + "/" + params[:path])) | 13 | + project_tree_path(@project, (@id)) |
| 16 | elsif params[:destination] == "blob" | 14 | elsif params[:destination] == "blob" |
| 17 | - project_blob_path(@project, (@ref + "/" + params[:path])) | 15 | + project_blob_path(@project, (@id)) |
| 18 | elsif params[:destination] == "graph" | 16 | elsif params[:destination] == "graph" |
| 19 | - project_graph_path(@project, @ref) | 17 | + project_graph_path(@project, @id, @options) |
| 20 | else | 18 | else |
| 21 | - project_commits_path(@project, @ref) | 19 | + project_commits_path(@project, @id) |
| 22 | end | 20 | end |
| 23 | 21 | ||
| 24 | redirect_to new_path | 22 | redirect_to new_path |
| @@ -42,27 +40,4 @@ class RefsController < ProjectResourceController | @@ -42,27 +40,4 @@ class RefsController < ProjectResourceController | ||
| 42 | } | 40 | } |
| 43 | end | 41 | end |
| 44 | end | 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 | end | 43 | end |
app/controllers/tree_controller.rb
| @@ -8,9 +8,6 @@ class TreeController < ProjectResourceController | @@ -8,9 +8,6 @@ class TreeController < ProjectResourceController | ||
| 8 | before_filter :require_non_empty_project | 8 | before_filter :require_non_empty_project |
| 9 | 9 | ||
| 10 | def show | 10 | def show |
| 11 | - @hex_path = Digest::SHA1.hexdigest(@path) | ||
| 12 | - @logs_path = logs_file_project_ref_path(@project, @ref, @path) | ||
| 13 | - | ||
| 14 | respond_to do |format| | 11 | respond_to do |format| |
| 15 | format.html | 12 | format.html |
| 16 | # Disable cache so browser history works | 13 | # Disable cache so browser history works |
app/models/network/graph.rb
| @@ -8,10 +8,11 @@ module Network | @@ -8,10 +8,11 @@ module Network | ||
| 8 | @max_count ||= 650 | 8 | @max_count ||= 650 |
| 9 | end | 9 | end |
| 10 | 10 | ||
| 11 | - def initialize project, ref, commit | 11 | + def initialize project, ref, commit, filter_ref |
| 12 | @project = project | 12 | @project = project |
| 13 | @ref = ref | 13 | @ref = ref |
| 14 | @commit = commit | 14 | @commit = commit |
| 15 | + @filter_ref = filter_ref | ||
| 15 | @repo = project.repo | 16 | @repo = project.repo |
| 16 | 17 | ||
| 17 | @commits = collect_commits | 18 | @commits = collect_commits |
| @@ -107,7 +108,9 @@ module Network | @@ -107,7 +108,9 @@ module Network | ||
| 107 | skip: skip | 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 | end | 114 | end |
| 112 | 115 | ||
| 113 | def commits_sort_by_ref | 116 | def commits_sort_by_ref |
app/views/graph/_head.html.haml
| @@ -3,14 +3,24 @@ | @@ -3,14 +3,24 @@ | ||
| 3 | 3 | ||
| 4 | .clearfix | 4 | .clearfix |
| 5 | .pull-left | 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 | .search.pull-right | 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 | .control-group | 18 | .control-group |
| 11 | = label_tag :search , "Looking for commit:", class: 'control-label light' | 19 | = label_tag :search , "Looking for commit:", class: 'control-label light' |
| 12 | .controls | 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 | = button_tag type: 'submit', class: 'btn vtop' do | 22 | = button_tag type: 'submit', class: 'btn vtop' do |
| 15 | %i.icon-search | 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,9 +7,11 @@ | ||
| 7 | 7 | ||
| 8 | :javascript | 8 | :javascript |
| 9 | var branch_graph; | 9 | var branch_graph; |
| 10 | - | 10 | + $("#filter_ref").click(function() { |
| 11 | + $(this).closest('form').submit(); | ||
| 12 | + }); | ||
| 11 | branch_graph = new BranchGraph($("#holder"), { | 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 | commit_url: '#{project_commit_path(@project, 'ae45ca32').gsub("ae45ca32", "%s")}', | 15 | commit_url: '#{project_commit_path(@project, 'ae45ca32').gsub("ae45ca32", "%s")}', |
| 14 | ref: '#{@ref}', | 16 | ref: '#{@ref}', |
| 15 | commit_id: '#{@commit.id}' | 17 | commit_id: '#{@commit.id}' |
app/views/shared/_ref_switcher.html.haml
| @@ -3,3 +3,5 @@ | @@ -3,3 +3,5 @@ | ||
| 3 | = hidden_field_tag :destination, destination | 3 | = hidden_field_tag :destination, destination |
| 4 | - if defined?(path) | 4 | - if defined?(path) |
| 5 | = hidden_field_tag :path, path | 5 | = hidden_field_tag :path, path |
| 6 | + - @options && @options.each do |key, value| | ||
| 7 | + = hidden_field_tag key, value, id: nil |
features/project/network.feature
| @@ -25,3 +25,12 @@ Feature: Project Network Graph | @@ -25,3 +25,12 @@ Feature: Project Network Graph | ||
| 25 | Then page should have network graph | 25 | Then page should have network graph |
| 26 | And page should select "master" in select box | 26 | And page should select "master" in select box |
| 27 | And page should have "v2.1.0" on graph | 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,6 +19,10 @@ class ProjectNetworkGraph < Spinach::FeatureSteps | ||
| 19 | page.should have_selector '#ref_chzn span', text: "master" | 19 | page.should have_selector '#ref_chzn span', text: "master" |
| 20 | end | 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 | And 'page should have "master" on graph' do | 26 | And 'page should have "master" on graph' do |
| 23 | within '.graph' do | 27 | within '.graph' do |
| 24 | page.should have_content 'master' | 28 | page.should have_content 'master' |
| @@ -35,6 +39,28 @@ class ProjectNetworkGraph < Spinach::FeatureSteps | @@ -35,6 +39,28 @@ class ProjectNetworkGraph < Spinach::FeatureSteps | ||
| 35 | sleep 2 | 39 | sleep 2 |
| 36 | end | 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 | And 'page should select "stable" in select box' do | 64 | And 'page should select "stable" in select box' do |
| 39 | page.should have_selector '#ref_chzn span', text: "stable" | 65 | page.should have_selector '#ref_chzn span', text: "stable" |
| 40 | end | 66 | end |
lib/extracts_path.rb
| @@ -94,16 +94,33 @@ module ExtractsPath | @@ -94,16 +94,33 @@ module ExtractsPath | ||
| 94 | # Automatically renders `not_found!` if a valid tree path could not be | 94 | # Automatically renders `not_found!` if a valid tree path could not be |
| 95 | # resolved (e.g., when a user inserts an invalid path or ref). | 95 | # resolved (e.g., when a user inserts an invalid path or ref). |
| 96 | def assign_ref_vars | 96 | def assign_ref_vars |
| 97 | - @id = params[:id] | 97 | + @id = get_id |
| 98 | 98 | ||
| 99 | @ref, @path = extract_ref(@id) | 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 | raise InvalidPathError unless @tree.exists? | 114 | raise InvalidPathError unless @tree.exists? |
| 106 | rescue RuntimeError, NoMethodError, InvalidPathError | 115 | rescue RuntimeError, NoMethodError, InvalidPathError |
| 107 | not_found! | 116 | not_found! |
| 108 | end | 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 | end | 126 | end |