From 038d40f0f5b202fe9ed133fdf9de1774bdbc8ede Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 11 Jun 2013 09:54:01 +0300 Subject: [PATCH] Solve inconsistency between network graph & stat graphs --- app/controllers/graph_controller.rb | 23 ----------------------- app/controllers/graphs_controller.rb | 17 +++++++++++++++++ app/controllers/network_controller.rb | 23 +++++++++++++++++++++++ app/controllers/refs_controller.rb | 2 +- app/controllers/stat_graph_controller.rb | 17 ----------------- app/views/graph/_head.html.haml | 26 -------------------------- app/views/graph/show.html.haml | 18 ------------------ app/views/graph/show.json.erb | 23 ----------------------- app/views/graphs/show.html.haml | 31 +++++++++++++++++++++++++++++++ app/views/graphs/show.js.haml | 16 ++++++++++++++++ app/views/layouts/nav/_project.html.haml | 8 ++++---- app/views/network/_head.html.haml | 26 ++++++++++++++++++++++++++ app/views/network/show.html.haml | 18 ++++++++++++++++++ app/views/network/show.json.erb | 23 +++++++++++++++++++++++ app/views/stat_graph/show.html.haml | 31 ------------------------------- app/views/stat_graph/show.js.haml | 16 ---------------- config/routes.rb | 4 ++-- features/steps/project/project_graph.rb | 2 +- features/steps/project/project_network_graph.rb | 2 +- features/steps/shared/paths.rb | 2 +- spec/routing/project_routing_spec.rb | 12 +++++++++--- 21 files changed, 173 insertions(+), 167 deletions(-) delete mode 100644 app/controllers/graph_controller.rb create mode 100644 app/controllers/graphs_controller.rb create mode 100644 app/controllers/network_controller.rb delete mode 100644 app/controllers/stat_graph_controller.rb delete mode 100644 app/views/graph/_head.html.haml delete mode 100644 app/views/graph/show.html.haml delete mode 100644 app/views/graph/show.json.erb create mode 100644 app/views/graphs/show.html.haml create mode 100644 app/views/graphs/show.js.haml create mode 100644 app/views/network/_head.html.haml create mode 100644 app/views/network/show.html.haml create mode 100644 app/views/network/show.json.erb delete mode 100644 app/views/stat_graph/show.html.haml delete mode 100644 app/views/stat_graph/show.js.haml diff --git a/app/controllers/graph_controller.rb b/app/controllers/graph_controller.rb deleted file mode 100644 index c79ed5c..0000000 --- a/app/controllers/graph_controller.rb +++ /dev/null @@ -1,23 +0,0 @@ -class GraphController < ProjectResourceController - include ExtractsPath - include ApplicationHelper - - # Authorize - before_filter :authorize_read_project! - before_filter :authorize_code_access! - before_filter :require_non_empty_project - - def show - 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, @options[:filter_ref]) - end - end - end -end diff --git a/app/controllers/graphs_controller.rb b/app/controllers/graphs_controller.rb new file mode 100644 index 0000000..5ae9c15 --- /dev/null +++ b/app/controllers/graphs_controller.rb @@ -0,0 +1,17 @@ +class GraphsController < ProjectResourceController + # Authorize + before_filter :authorize_read_project! + before_filter :authorize_code_access! + before_filter :require_non_empty_project + + def show + respond_to do |format| + format.html + format.js do + @repo = @project.repository + @stats = Gitlab::Git::GitStats.new(@repo.raw, @repo.root_ref) + @log = @stats.parsed_log.to_json + end + end + end +end diff --git a/app/controllers/network_controller.rb b/app/controllers/network_controller.rb new file mode 100644 index 0000000..3c8e747 --- /dev/null +++ b/app/controllers/network_controller.rb @@ -0,0 +1,23 @@ +class NetworkController < ProjectResourceController + include ExtractsPath + include ApplicationHelper + + # Authorize + before_filter :authorize_read_project! + before_filter :authorize_code_access! + before_filter :require_non_empty_project + + def show + 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, @options[:filter_ref]) + end + end + end +end diff --git a/app/controllers/refs_controller.rb b/app/controllers/refs_controller.rb index e7def39..cae9193 100644 --- a/app/controllers/refs_controller.rb +++ b/app/controllers/refs_controller.rb @@ -14,7 +14,7 @@ class RefsController < ProjectResourceController elsif params[:destination] == "blob" project_blob_path(@project, (@id)) elsif params[:destination] == "graph" - project_graph_path(@project, @id, @options) + project_network_path(@project, @id, @options) else project_commits_path(@project, @id) end diff --git a/app/controllers/stat_graph_controller.rb b/app/controllers/stat_graph_controller.rb deleted file mode 100644 index f076f47..0000000 --- a/app/controllers/stat_graph_controller.rb +++ /dev/null @@ -1,17 +0,0 @@ -class StatGraphController < ProjectResourceController - # Authorize - before_filter :authorize_read_project! - before_filter :authorize_code_access! - before_filter :require_non_empty_project - - def show - respond_to do |format| - format.html - format.js do - @repo = @project.repository - @stats = Gitlab::Git::GitStats.new(@repo.raw, @repo.root_ref) - @log = @stats.parsed_log.to_json - end - end - end -end diff --git a/app/views/graph/_head.html.haml b/app/views/graph/_head.html.haml deleted file mode 100644 index 7a5b3c6..0000000 --- a/app/views/graph/_head.html.haml +++ /dev/null @@ -1,26 +0,0 @@ -%h3.page_title Project Network Graph -%hr - -.clearfix - .pull-left - = 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, @id), method: :get do |f| - .control-group - = label_tag :search , "Looking for commit:", class: 'control-label light' - .controls - = 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 deleted file mode 100644 index 0ee6648..0000000 --- a/app/views/graph/show.html.haml +++ /dev/null @@ -1,18 +0,0 @@ -= render "head" -.graph_holder - %h4 - %small You can move around the graph by using the arrow keys. - #holder.graph - .loading.loading-gray - -:javascript - var branch_graph; - $("#filter_ref").click(function() { - $(this).closest('form').submit(); - }); - branch_graph = new BranchGraph($("#holder"), { - 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/graph/show.json.erb b/app/views/graph/show.json.erb deleted file mode 100644 index 9a62cdb..0000000 --- a/app/views/graph/show.json.erb +++ /dev/null @@ -1,23 +0,0 @@ -<% self.formats = ["html"] %> - -<%= raw( - { - days: @graph.days.compact.map { |d| [d.day, d.strftime("%b")] }, - commits: @graph.commits.map do |c| - { - parents: parents_zip_spaces(c.parents(@graph.map), c.parent_spaces), - author: { - name: c.author_name, - email: c.author_email, - icon: gravatar_icon(c.author_email, 20) - }, - time: c.time, - space: c.spaces.first, - refs: get_refs(c), - id: c.sha, - date: c.date, - message: c.message, - } - end - }.to_json -) %> diff --git a/app/views/graphs/show.html.haml b/app/views/graphs/show.html.haml new file mode 100644 index 0000000..05bc143 --- /dev/null +++ b/app/views/graphs/show.html.haml @@ -0,0 +1,31 @@ +.loading-graph + %center + .loading + %h3.page_title Building repository graph. Please wait a moment. + +.stat-graph + .header.clearfix + .pull-right + %select + %option{:value => "commits"} Commits + %option{:value => "additions"} Additions + %option{:value => "deletions"} Deletions + %h3#date_header.page_title + %input#brush_change{:type => "hidden"} + .graphs + #contributors-master + #contributors.clearfix + %ol.contributors-list.clearfix + +:javascript + $(".stat-graph").hide(); + + $.ajax({ + type: "GET", + url: location.href, + complete: function() { + $(".loading-graph").hide(); + $(".stat-graph").show(); + }, + dataType: "script" + }); diff --git a/app/views/graphs/show.js.haml b/app/views/graphs/show.js.haml new file mode 100644 index 0000000..b7c9b41 --- /dev/null +++ b/app/views/graphs/show.js.haml @@ -0,0 +1,16 @@ +:plain + controller = new ContributorsStatGraph + controller.init(#{@log}) + + $("select").change( function () { + var field = $(this).val() + controller.set_current_field(field) + controller.redraw_master() + controller.redraw_authors() + }) + + $("#brush_change").change( function () { + controller.change_date_header() + controller.redraw_authors() + }) + diff --git a/app/views/layouts/nav/_project.html.haml b/app/views/layouts/nav/_project.html.haml index 399bcf5..1c5781d 100644 --- a/app/views/layouts/nav/_project.html.haml +++ b/app/views/layouts/nav/_project.html.haml @@ -9,10 +9,10 @@ = link_to 'Files', project_tree_path(@project, @ref || @repository.root_ref) = nav_link(controller: %w(commit commits compare repositories protected_branches)) do = link_to "Commits", project_commits_path(@project, @ref || @repository.root_ref) - = nav_link(controller: %w(graph)) do - = link_to "Network", project_graph_path(@project, @ref || @repository.root_ref) - = nav_link(controller: %w(stat_graph)) do - = link_to "Graphs", project_stat_graph_path(@project, @ref || @repository.root_ref) + = nav_link(controller: %w(network)) do + = link_to "Network", project_network_path(@project, @ref || @repository.root_ref) + = nav_link(controller: %w(graphs)) do + = link_to "Graphs", project_graph_path(@project, @ref || @repository.root_ref) - if @project.issues_enabled = nav_link(controller: %w(issues milestones labels)) do diff --git a/app/views/network/_head.html.haml b/app/views/network/_head.html.haml new file mode 100644 index 0000000..62ab8b0 --- /dev/null +++ b/app/views/network/_head.html.haml @@ -0,0 +1,26 @@ +%h3.page_title Project Network Graph +%hr + +.clearfix + .pull-left + = render partial: 'shared/ref_switcher', locals: {destination: 'graph'} + .pull-left + = form_tag project_network_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_network_path(@project, @id), method: :get do |f| + .control-group + = label_tag :search , "Looking for commit:", class: 'control-label light' + .controls + = 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/network/show.html.haml b/app/views/network/show.html.haml new file mode 100644 index 0000000..a480cea --- /dev/null +++ b/app/views/network/show.html.haml @@ -0,0 +1,18 @@ += render "head" +.graph_holder + %h4 + %small You can move around the graph by using the arrow keys. + #holder.graph + .loading.loading-gray + +:javascript + var branch_graph; + $("#filter_ref").click(function() { + $(this).closest('form').submit(); + }); + branch_graph = new BranchGraph($("#holder"), { + url: '#{project_network_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/network/show.json.erb b/app/views/network/show.json.erb new file mode 100644 index 0000000..9a62cdb --- /dev/null +++ b/app/views/network/show.json.erb @@ -0,0 +1,23 @@ +<% self.formats = ["html"] %> + +<%= raw( + { + days: @graph.days.compact.map { |d| [d.day, d.strftime("%b")] }, + commits: @graph.commits.map do |c| + { + parents: parents_zip_spaces(c.parents(@graph.map), c.parent_spaces), + author: { + name: c.author_name, + email: c.author_email, + icon: gravatar_icon(c.author_email, 20) + }, + time: c.time, + space: c.spaces.first, + refs: get_refs(c), + id: c.sha, + date: c.date, + message: c.message, + } + end + }.to_json +) %> diff --git a/app/views/stat_graph/show.html.haml b/app/views/stat_graph/show.html.haml deleted file mode 100644 index 05bc143..0000000 --- a/app/views/stat_graph/show.html.haml +++ /dev/null @@ -1,31 +0,0 @@ -.loading-graph - %center - .loading - %h3.page_title Building repository graph. Please wait a moment. - -.stat-graph - .header.clearfix - .pull-right - %select - %option{:value => "commits"} Commits - %option{:value => "additions"} Additions - %option{:value => "deletions"} Deletions - %h3#date_header.page_title - %input#brush_change{:type => "hidden"} - .graphs - #contributors-master - #contributors.clearfix - %ol.contributors-list.clearfix - -:javascript - $(".stat-graph").hide(); - - $.ajax({ - type: "GET", - url: location.href, - complete: function() { - $(".loading-graph").hide(); - $(".stat-graph").show(); - }, - dataType: "script" - }); diff --git a/app/views/stat_graph/show.js.haml b/app/views/stat_graph/show.js.haml deleted file mode 100644 index b7c9b41..0000000 --- a/app/views/stat_graph/show.js.haml +++ /dev/null @@ -1,16 +0,0 @@ -:plain - controller = new ContributorsStatGraph - controller.init(#{@log}) - - $("select").change( function () { - var field = $(this).val() - controller.set_current_field(field) - controller.redraw_master() - controller.redraw_authors() - }) - - $("#brush_change").change( function () { - controller.change_date_header() - controller.redraw_authors() - }) - diff --git a/config/routes.rb b/config/routes.rb index c555cd0..a50f78c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -190,8 +190,8 @@ Gitlab::Application.routes.draw do resources :commits, only: [:show], constraints: {id: /(?:[^.]|\.(?!atom$))+/, format: /atom/} resources :compare, only: [:index, :create] resources :blame, only: [:show], constraints: {id: /.+/} - resources :graph, only: [:show], constraints: {id: /(?:[^.]|\.(?!json$))+/, format: /json/} - resources :stat_graph, only: [:show], constraints: {id: /(?:[^.]|\.(?!json$))+/, format: /json/} + resources :network, only: [:show], constraints: {id: /(?:[^.]|\.(?!json$))+/, format: /json/} + resources :graphs, only: [:show], constraints: {id: /(?:[^.]|\.(?!json$))+/, format: /json/} match "/compare/:from...:to" => "compare#show", as: "compare", via: [:get, :post], constraints: {from: /.+/, to: /.+/} scope module: :projects do diff --git a/features/steps/project/project_graph.rb b/features/steps/project/project_graph.rb index 489485b..50942b3 100644 --- a/features/steps/project/project_graph.rb +++ b/features/steps/project/project_graph.rb @@ -8,6 +8,6 @@ class ProjectGraph < Spinach::FeatureSteps When 'I visit project "Shop" graph page' do project = Project.find_by_name("Shop") - visit project_stat_graph_path(project, "master") + visit project_graph_path(project, "master") end end diff --git a/features/steps/project/project_network_graph.rb b/features/steps/project/project_network_graph.rb index 48a73f0..f001c0b 100644 --- a/features/steps/project/project_network_graph.rb +++ b/features/steps/project/project_network_graph.rb @@ -12,7 +12,7 @@ class ProjectNetworkGraph < Spinach::FeatureSteps Network::Graph.stub(max_count: 10) project = Project.find_by_name("Shop") - visit project_graph_path(project, "master") + visit project_network_path(project, "master") end And 'page should select "master" in select box' do diff --git a/features/steps/shared/paths.rb b/features/steps/shared/paths.rb index 3641e78..21b6159 100644 --- a/features/steps/shared/paths.rb +++ b/features/steps/shared/paths.rb @@ -149,7 +149,7 @@ module SharedPaths # Stub Graph max_size to speed up test (10 commits vs. 650) Network::Graph.stub(max_count: 10) - visit project_graph_path(@project, root_ref) + visit project_network_path(@project, root_ref) end step "I visit my project's issues page" do diff --git a/spec/routing/project_routing_spec.rb b/spec/routing/project_routing_spec.rb index 94f9480..a1d4bd6 100644 --- a/spec/routing/project_routing_spec.rb +++ b/spec/routing/project_routing_spec.rb @@ -446,9 +446,15 @@ describe CompareController, "routing" do end end -describe GraphController, "routing" do +describe NetworkController, "routing" do it "to #show" do - get("/gitlabhq/graph/master").should route_to('graph#show', project_id: 'gitlabhq', id: 'master') - get("/gitlabhq/graph/master.json").should route_to('graph#show', project_id: 'gitlabhq', id: 'master', format: "json") + get("/gitlabhq/network/master").should route_to('network#show', project_id: 'gitlabhq', id: 'master') + get("/gitlabhq/network/master.json").should route_to('network#show', project_id: 'gitlabhq', id: 'master', format: "json") + end +end + +describe GraphsController, "routing" do + it "to #show" do + get("/gitlabhq/graphs/master").should route_to('graphs#show', project_id: 'gitlabhq', id: 'master') end end -- libgit2 0.21.2